summaryrefslogtreecommitdiff
path: root/vdr-smarttvweb/web/Server.js
diff options
context:
space:
mode:
authorthlo <t.lohmar@gmx.de>2013-01-05 16:37:48 +0100
committerthlo <t.lohmar@gmx.de>2013-01-05 16:37:48 +0100
commita84fb47821356729f6bbcf5813aec5f7c6faafed (patch)
treeca3b209b5179ce9e87a9b4371a50e7747a54fba6 /vdr-smarttvweb/web/Server.js
parenta857c8fd7546029ddc666f835a0930f19a33be94 (diff)
downloadvdr-plugin-smarttvweb-a84fb47821356729f6bbcf5813aec5f7c6faafed.tar.gz
vdr-plugin-smarttvweb-a84fb47821356729f6bbcf5813aec5f7c6faafed.tar.bz2
New Web Front End. Various bug fixes.
Diffstat (limited to 'vdr-smarttvweb/web/Server.js')
-rwxr-xr-xvdr-smarttvweb/web/Server.js120
1 files changed, 120 insertions, 0 deletions
diff --git a/vdr-smarttvweb/web/Server.js b/vdr-smarttvweb/web/Server.js
new file mode 100755
index 0000000..9fb39c5
--- /dev/null
+++ b/vdr-smarttvweb/web/Server.js
@@ -0,0 +1,120 @@
+var Server =
+{
+ dataReceivedCallback : null,
+ errorCallback : null,
+ doSort : false,
+ retries : 0,
+
+ XHRObj : null
+};
+
+Server.init = function()
+{
+ var success = true;
+
+ if (this.XHRObj) {
+ this.XHRObj.destroy();
+ this.XHRObj = null;
+ }
+
+ return success;
+};
+
+Server.setSort = function (val) {
+ this.doSort = val;
+};
+
+Server.fetchVideoList = function(url) {
+ if (this.XHRObj == null) {
+ this.XHRObj = new XMLHttpRequest();
+ }
+
+ if (this.XHRObj) {
+ this.XHRObj.onreadystatechange = function()
+ {
+ var splashElement = document.getElementById("splashStatus");
+
+ if (Server.XHRObj.readyState == 4) {
+ Server.createVideoList();
+ }
+ };
+
+ this.XHRObj.open("GET", url, true);
+ this.XHRObj.send(null);
+ }
+ else {
+ console.log("Failed to create XHR");
+
+ if (this.errorCallback != null) {
+ this.errorCallback("ServerError");
+ }
+ }
+};
+
+Server.createVideoList = function() {
+ console.log ("creating Video list now");
+
+ if (this.XHRObj.status != 200) {
+ if (this.errorCallback != null) {
+ this.errorCallback("ServerError");
+ }
+ }
+ else
+ {
+ var xmlResponse = this.XHRObj.responseXML;
+ if (xmlResponse == null) {
+ if (this.errorCallback != null) {
+ this.errorCallback("XmlError");
+ }
+ return;
+ }
+ var xmlElement = xmlResponse.documentElement;
+
+ if (!xmlElement) {
+ console.log("Failed to get valid XML");
+ return;
+ }
+ else
+ {
+ var items = xmlElement.getElementsByTagName("item");
+ if (items.length == 0) {
+ console.log("Something wrong. Response does not contain any item");
+ };
+
+ for (var index = 0; index < items.length; index++) {
+
+ var titleElement = items[index].getElementsByTagName("title")[0];
+ var progElement = items[index].getElementsByTagName("programme")[0];
+ var descriptionElement = items[index].getElementsByTagName("description")[0];
+ var linkElement = items[index].getElementsByTagName("link")[0];
+ var startVal =0;
+ var durVal =0;
+ try {
+ startVal = parseInt(items[index].getElementsByTagName("start")[0].firstChild.data);
+ durVal = parseInt(items[index].getElementsByTagName("duration")[0].firstChild.data);
+ }
+ catch (e) {
+ console.log("ERROR: "+e);
+ }
+
+ var desc = descriptionElement.firstChild.data;
+
+ if (titleElement && linkElement) {
+ var title_list = titleElement.firstChild.data.split("~");
+ Data.addItem( title_list, {link : linkElement.firstChild.data,
+ prog: progElement.firstChild.data,
+ desc: desc,
+ start: startVal,
+ dur: durVal});
+ }
+
+ }
+ Data.completed(this.doSort);
+
+ if (this.dataReceivedCallback)
+ {
+ this.dataReceivedCallback(); /* Notify all data is received and stored */
+ }
+ }
+ }
+};