diff options
Diffstat (limited to 'smarttv-client/Javascript/Epg.js')
-rw-r--r-- | smarttv-client/Javascript/Epg.js | 186 |
1 files changed, 167 insertions, 19 deletions
diff --git a/smarttv-client/Javascript/Epg.js b/smarttv-client/Javascript/Epg.js index c400e0e..89bd05c 100644 --- a/smarttv-client/Javascript/Epg.js +++ b/smarttv-client/Javascript/Epg.js @@ -9,33 +9,181 @@ */
var Epg = {
- restfulUrl : ""
-
+ timeoutObj : null,
+ isActive : false,
+ guidErrors : {},
+ guidTitle : {},
+ curGuid : "",
+ lastGuid :"",
+ sameGuidCount : 0,
+ globalCount :0
};
-// Should be called after initial config
-Epg.init = function () {
- if (Config.serverUrl == "")
+Epg.stopUpdates = function () {
+ if (this.isActive == false )
+ return;
+
+ window.clearTimeout(this.timeoutObj);
+ this.isActive = false;
+ this.curGui = "";
+};
+
+Epg.startEpgUpdating = function() {
+ Main.log("");
+ Main.log("**** Epg.startEpgUpdating ****");
+
+ if (this.isActive == true)
+ return;
+
+/* if (this.globalCount == 30) {
+ Main.log ("stopping");
return;
- if (Config.serverUrl.indexOf(':') != -1) {
- Main.log ("Epg: Serverurl= " + Config.serverUrl);
- this.restfulUrl = Config.serverUrl.splice(0, Config.serverUrl.indexOf(':')) + ":8002";
}
+ */
+ this.globalCount ++;
+ if (Main.state != Main.eLIVE) {
+ Main.logToServer("ERROR in Epg.startEpgUpdating: I am NOT in state Main.eLive...!!");
+ return;
+ }
+ this.isActive = true;
+ var res = Data.findEpgUpdateTime();
+
+ var now = Display.GetEpochTime();
+ var delay = Math.round(res.min - now) *1000;
+ this.curGuid = res.guid;
+
+ Main.log("Epg.startEpgUpdating: Next update for GUID= " + res.guid + " with Min= " + res.min + " delay= " + (delay/1000.0) + "sec");
+
+ if (this.lastGuid == res.guid) {
+ // lastGuid is only changed, when the last response was successful
+ // number of repetitive errors are checked in the error response procedure
+ this.sameGuidCount ++;
+ Main.logToServer("WARNING in Epg.startEpgUpdating: again same Guid guid= " + res.guid + "(" +Epg.guidTitle[res.guid] +") (sameGuidCount= " +this.sameGuidCount+"). OrgDelay= " + (delay/1000.0) + "sec. Delaying...");
+ delay = 1000;
+ if (this.sameGuidCount > 60) {
+ Epg.insertFakeEntry(res.guid);
+ Main.logToServer("ERROR in EPG.updateEPG: insertFakeEntry for guid= " + res.guid + " (" + Epg.guidTitle[res.guid] +")");
+ Epg.isActive = false;
+ Epg.startEpgUpdating();
+// Main.logToServer("ERROR in EPG.updateEPG: 10x same guid !!! - Please file a bug report! - Bitte eine Fehlermeldung posten");
+// Display.showPopup("EPG.updateEPG: 10x same guid !!!<br>Please file a bug report!<br>Bitte eine Fehlermeldung posten");
+ return;
+ }
+ }
+ else {
+ this.sameGuidCount = 0;
+ }
+
+ if (delay <0) {
+ delay = 300; //bit delay in msec
+ }
+// var guid = res.guid;
+ if (!(res.guid in this.guidErrors)) {
+ this.guidErrors[res.guid] = 0;
+ };
+
+ Main.log("Iter over this.guidErrors");
+ for (var prop in this.guidErrors) {
+ Main.log(" " +prop + " == " + this.guidErrors[prop]);
+ }
+ Main.log("Iter Done");
+
+ Main.log("Epg.startEpgUpdating: next Update for guid= " + res.guid + " (" +Epg.guidTitle[res.guid] +") guidErrors= "+this.guidErrors[res.guid]+ " in " + (delay/1000.0) +"sec");
+ Main.logToServer("Epg.startEpgUpdating: next Update for guid= " + res.guid + " (" +Epg.guidTitle[res.guid]+ ") guidErrors= "+this.guidErrors[res.guid]+ " in " + (delay/1000.0) +"sec");
+// Main.logToServer("Epg.startEpgUpdating: next Update for guid= " + res.guid + " in " + (delay/1000.0) +"sec");
- Main.log ("Restful API Url= "+ this.restfulUrl);
+ this.timeoutObj = window.setTimeout(function() { Epg.updateEpg(res.guid); }, delay);
+};
+
+Epg.updateEpg = function (guid) {
+ var url = Config.serverUrl + "/epg.xml?id=" + guid;
+ if (Epg.guidErrors[guid] >2) {
+ Main.logToServer("WARNING in Epg.updateEpg: guid= " + guid + " uses mode=nodesc" );
+ url = url +"&mode=nodesc";
+ }
+ Main.log("Epg.updateEpg: Prep for guid= " + guid + " with ErrorCount= " + Epg.guidErrors[guid] +" and url= " + url);
$.ajax({
- type: "HEAD",
+ type: "GET",
async: true,
- url: this.restfulUrl + "channels.xml",
- success: function(message,text,response){
- Main.log("AJAX Response: MSG= " + message + " txt= " + text + " resp= " + response);
- }
- });
+ url: url,
+ success: Epg.parseResponse,
+ error: Epg.handleError
+ });
+};
+
+Epg.handleError = function (XHR, textStatus, errorThrown) {
+
+ Epg.guidErrors[Epg.curGuid] += 1;
+ Main.log("EPG.updateEPG Error ("+XHR.status +": " +XHR.responseText+")EPG.curGuid= "+Epg.curGuid +" Epg.guidErrors[Epg.curGuid]= " +Epg.guidErrors[Epg.curGuid]);
+ Main.logToServer("EPG.updateEPG Error Response("+ XHR.status + ") EPG.curGuid= "+Epg.curGuid +" Epg.guidErrors[Epg.curGuid]= " +Epg.guidErrors[Epg.curGuid]);
+
+ Epg.isActive = false;
+ Main.log("--------------------------------------------");
+ if (Epg.guidErrors[Epg.curGuid] < 10) {
+ Epg.startEpgUpdating();
+ }
+ else {
+ Epg.insertFakeEntry(Epg.curGuid);
+ Main.logToServer("ERROR in EPG.updateEPG: insertingFakeEntry for guid= " + res.guid + " (" + Epg.guidTitle[res.guid] +")");
+ Epg.startEpgUpdating();
+// Display.showPopup("EPG.updateEPG: stop updating !!!<br>Please file a bug report!<br>Bitte eine Fehlermeldung posten");
+ }
+ return;
+};
+
+Epg.insertFakeEntry = function (guid) {
+ Main.logToServer("Epg.insertFakeEntry for guid= " + guid + " (" + Epg.guidErrors[guid] +")");
+ var now = Display.GetEpochTime();
+
+ entry={};
+ entry.prog = "Unknown";
+ entry.desc = "Empty";
+ entry.start = now;
+ entry.dur = 120;
+
+ Data.updateEpg(guid, entry);
+};
+
+Epg.parseResponse = function (message,text, XHR) {
+
+ $(message).find("programme").each(function(){
+ var guid = $(this).find("guid").text();
+ if (guid != Epg.curGuid) {
+ Main.logToServer("ERROR in Epg.parseResponse : Guid (="+ guid + ") != Epg.curGuid (=" + Epg.curGuid+ ") " );
+ }
+
+ Epg.guidErrors[Epg.curGuid] = 0;
+
+ entry={};
+ entry.prog = $(this).find("title").text();
+ entry.desc = $(this).find("desc").text();
+ entry.start = parseInt($(this).find("start").text());
+ entry.dur = (parseInt($(this).find("end").text()) - parseInt($(this).find("start").text()));
+
+ Main.log("Epg.parseResponse : Guid= "+ guid + " title= " + entry.prog+ " start= " +entry.start + " dur= " + entry.dur);
+// Main.logToServer("Epg.parseResponse : Guid= "+ guid + " title= " + entry.prog+ " start= " +entry.start + " dur= " + entry.dur);
+
+ Data.updateEpg(guid, entry);
+
+ //trigger Display refresh
+ if (Data.getCurrentItem().childs[Main.selectedVideo].payload.guid == guid) {
+ // the updated record is either playing or in Menu
+ if (Player.state != Player.STOPPED) {
+ Main.logToServer("Updating Progress Bar");
+ Display.updateOlForLive (entry.start, entry.dur, Display.GetEpochTime()); // Updates the progress bar
+ }
+ else {
+ Main.logToServer("Updating Right Half");
+ Display.handleDescription(Main.selectedVideo);
+ }
+ }
+
+ Epg.lastGuid = guid;
+ Epg.isActive = false;
+ Main.log("--------------------------------------------");
+ Epg.startEpgUpdating();
+ });
};
-Epg.startEpgUpdating = function() {
- var res = Data.findEpgUpdateTime();
- Main.log("GUID= " + res.guid + " Min= " + res.min);
-};
\ No newline at end of file |