diff options
author | thlo <smarttv640@gmail.com> | 2013-07-24 20:32:03 +0200 |
---|---|---|
committer | thlo <t.lohmar@gmx.de> | 2013-07-24 20:32:03 +0200 |
commit | 0ecc9a2ca4c3604ef2590fef5b3072417689a7d3 (patch) | |
tree | 3e8d88ad1c84e9f537d1fa8853ddd00f200760d0 /smarttv-client/Javascript/Config.js | |
parent | d8688559455cc3cd86f41e816568d099f07f3800 (diff) | |
download | vdr-plugin-smarttvweb-0ecc9a2ca4c3604ef2590fef5b3072417689a7d3.tar.gz vdr-plugin-smarttvweb-0ecc9a2ca4c3604ef2590fef5b3072417689a7d3.tar.bz2 |
Widget updates:
- Multi-Server Support
- Number key personalization for recordings
- Timezone fix
- Fix in YouTube Handling
- Fix in Helpbar
- Other misc fixes
Diffstat (limited to 'smarttv-client/Javascript/Config.js')
-rwxr-xr-x | smarttv-client/Javascript/Config.js | 233 |
1 files changed, 214 insertions, 19 deletions
diff --git a/smarttv-client/Javascript/Config.js b/smarttv-client/Javascript/Config.js index 8f0d898..2d4cf52 100755 --- a/smarttv-client/Javascript/Config.js +++ b/smarttv-client/Javascript/Config.js @@ -2,8 +2,10 @@ var Config = { cfgFileName : "",
XHRObj : null,
xmlDocument : null,
+ vdrServers : null,
serverUrl : "", // Will become the main URL for contacting the server. Form "http://<server>:port"
serverAddr : "",
+ serverName : "",
serverAddrDefault: "192.168.1.122:8000",
format :"has",
tgtBufferBitrate : 6000, // kbps
@@ -19,7 +21,10 @@ var Config = { uploadJsFile : "",
directAcessTimeout : 1500,
preferredQuality : 2,
- widgetVersion : "unknown",
+ widgetVersion : "unknown",
+ tzCorrection : 0,
+ recSortType : 0,
+ playKeyBehavior : 0,
deviceType : 0 // Used to differentiate between browsers and platforms
// 0: Samsung
@@ -43,17 +48,22 @@ Config.init = function () { Main.logToServer ("modelName= " + deviceapis.tv.info.getModel());
Main.logToServer ("productType= " + deviceapis.tv.info.getProduct());
*/
+
+ this.vdrServers = new VdrServers();
+ this.vdrServers.instanceName = " MyObj";
+ if (this.serverUrl != "") {
+ // Hardcoded server URL. Done with config
+ Main.log ("Hardcoded server URL. Done with config");
+ Config.fetchConfig();
+ return;
+ }
+
- if (this.deviceType == 0) {
+// if (this.deviceType == 0)
+ switch (this.deviceType){
+ case 0:
// This is a Samsung Smart TV
-
- if (this.serverUrl != "") {
- // Hardcoded server URL. Done with config
- Main.log ("Hardcoded server URL. Done with config");
- Config.fetchConfig();
- return;
- }
-
+
try {
this.cfgFileName = curWidget.id + "/config.dta";
}
@@ -82,8 +92,11 @@ Config.init = function () { return;
}
else {
+ // ok, there should be some config info
Config.readContext();
- }
+ return; //thlo: TODO
+ }
+ break;
}
Server.notifyServer("started");
Config.fetchConfig();
@@ -136,6 +149,12 @@ Config.fetchConfig = function () { Config.uploadJsFile = $(data).find('uploadJsFile').text();
Config.directAcessTimeout = $(data).find('directAcessTimeout').text();
Config.preferredQuality = $(data).find('preferredQuality').text();
+ Config.sortType= parseInt($(data).find('sortType').text());
+ if ((Config.sortType < 0) || (Config.sortType > Data.maxSort) || isNaN(Config.sortType)) {
+ Config.sortType = 0;
+ }
+ Config.playKeyBehavior = parseInt($(data).find('playKeyBehavior').text());
+ Config.playKeyBehavior = isNaN(Config.playKeyBehavior) ? 0 : Config.playKeyBehavior;
Player.skipDuration = Config.skipDuration;
if (Config.directAcessTimeout != "") {
@@ -153,6 +172,8 @@ Config.fetchConfig = function () { Main.log("liveChannels= " + Config.liveChannels);
Main.log("debug= " + Config.debug);
Main.log("usePdlForRecordings= " + Config.usePdlForRecordings);
+ Main.log("sortType= " + Config.sortType);
+ Main.log("playKeyBehavior= " + Config.playKeyBehavior);
Main.log("**** /Config ****");
Main.init();
@@ -170,40 +191,99 @@ Config.fetchConfig = function () { };
-Config.writeContext = function (addr) {
+
+Config.deletedFromContext = function(idx) {
+ Main.log("Config.deletedFromContext: idx= " + idx);
+ Config.vdrServers.serverUrlList.splice(idx, 1);
+
+ Config.writeServerUrlList();
+};
+
+Config.updateContext = function (addr) {
+ Main.log("Config.updateContext with ("+addr+")");
+ Main.logToServer("Config.updateContext with ("+addr+")");
+
+ var found = false;
+
+ for (var i = 0; i < Config.vdrServers.serverUrlList.length; i++) {
+ if (Config.vdrServers.serverUrlList[i] == addr) {
+ found = true;
+ break;
+ }
+
+ }
+ if (found == true) {
+ // don't overwrite, if the address is already there.
+ Main.log("Config.updateContext: don't overwrite -> return");
+ Notify.showNotify("Server already included -> Ignoring", true);
+
+ return;
+ }
+ Config.vdrServers.serverUrlList.push(addr);
+
+ Config.writeServerUrlList();
+ /*
var fileSystemObj = new FileSystem();
var fd = fileSystemObj.openCommonFile(Config.cfgFileName,"w");
- fd.writeLine('serverAddr ' + addr); // SHould be overwritten by Options menue
+// fd.writeLine('serverAddr ' + addr); // SHould be overwritten by Options menue
+ for (var i = 0; i < Config.vdrServers.serverUrlList.length; i++) {
+ Main.log ("Config.updateContext itm= " + Config.vdrServers.serverUrlList[i]);
+ Main.logToServer ("Config.updateContext itm= " + Config.vdrServers.serverUrlList[i]);
+ fd.writeLine('serverAddr ' + Config.vdrServers.serverUrlList[i]);
+ }
+
fileSystemObj.closeCommonFile(fd);
+*/
+ if (Config.serverAddr == "") {
+ // only change the server, when needed.
+ Config.serverAddr = addr;
+ Config.serverUrl = "http://" + Config.serverAddr;
+ Config.fetchConfig();
+ }
};
-Config.updateContext = function (addr) {
- Main.log("Config.updateContext with ("+addr+")");
+/*
+Config.writeContext = function (addr) {
var fileSystemObj = new FileSystem();
var fd = fileSystemObj.openCommonFile(Config.cfgFileName,"w");
fd.writeLine('serverAddr ' + addr); // SHould be overwritten by Options menue
fileSystemObj.closeCommonFile(fd);
+};
+*/
+Config.writeServerUrlList = function () {
+ var fileSystemObj = new FileSystem();
- Config.serverAddr = addr;
- Config.serverUrl = "http://" + Config.serverAddr;
- Config.fetchConfig();
+ var fd = fileSystemObj.openCommonFile(Config.cfgFileName,"w");
+
+ for (var i = 0; i < Config.vdrServers.serverUrlList.length; i++) {
+ Main.log ("Config.writeServerUrlList itm= " + Config.vdrServers.serverUrlList[i]);
+ Main.logToServer ("Config.writeServerUrlList itm= " + Config.vdrServers.serverUrlList[i]);
+ fd.writeLine('serverAddr ' + Config.vdrServers.serverUrlList[i]);
+ }
+
+ fileSystemObj.closeCommonFile(fd);
+
};
Config.readContext = function () {
+ // readConfig is only called once, at start-up.
+ // an array of server addresses should be read.
var fileSystemObj = new FileSystem();
+
try {
var fd = fileSystemObj.openCommonFile(Config.cfgFileName, "r");
-
var line = "";
while (line = fd.readLine()) {
var avp = line.split(" ");
if (avp.length > 1) {
+ Config.vdrServers.serverUrlList.push(avp[1]);
+ Main.log("Config.readContext avp[1]= " + avp[1]);
Config.serverAddr = avp[1];
Config.serverUrl = "http://" + Config.serverAddr;
}
@@ -215,6 +295,7 @@ Config.readContext = function () { }
}
fileSystemObj.closeCommonFile(fd);
+
}
catch (e) {
Main.log("Config.readContext: Error while reading: e= " +e);
@@ -235,6 +316,16 @@ Config.readContext = function () { Config.doFirstLaunch();
}
+
+// Config.vdrServers.serverUrlList.push("192.168.1.142:8000");
+ this.vdrServers.checkServers();
+ if (Config.vdrServers.serverUrlList.length > 1) {
+ // Now I should show the popup to select the server.
+ // 1: Check whether more than one server is active
+ // - I need a new plugin method (getServerName)
+ // 2: If more than one server is active, show server menu
+ }
+
};
@@ -243,3 +334,107 @@ Config.reset = function () { var fileSystemObj = new FileSystem();
fileSystemObj.deleteCommonFile(curWidget.id + "/config.dta");
};
+
+//**************************************************
+function VdrServers() {
+ this.serverUrlList = [];
+ this.activeServers = [];
+ this.responses = 0;
+ this.instanceName = "";
+};
+
+VdrServers.prototype.checkServers = function () {
+
+ Main.log ("check active VDR servers " );
+ this.responses = 0;
+ this.activeServers = [];
+
+ for (var i = 0; i < this.serverUrlList.length; i++) {
+ var obj = new VdrServerChecker(this, i);
+ obj.checkServer(this.serverUrlList[i]);
+ }
+};
+
+VdrServers.prototype.handleResponse = function () {
+ Main.log ("handle responses: Response " + this.responses + " of " + this.serverUrlList.length);
+ this.responses ++;
+ if (this.responses == this.serverUrlList.length) {
+ Main.log ("handle responses: Done. Active Servers= " + this.activeServers.length);
+ switch (this.activeServers.length) {
+ case 0:
+ Display.showPopup("Please start your VDR server");
+ break;
+ case 1:
+ Config.serverAddr = this.activeServers[0].addr;
+ Config.serverUrl = "http://" + Config.serverAddr;
+ Config.serverName = this.activeServers[0].name;
+ Notify.showNotify("Only " + Config.serverName + " found", true);
+
+ $("#selectTitle").text(Config.serverName );
+ $("#logoTitle").text(Config.serverName );
+
+ Config.fetchConfig();
+ break;
+ default:
+ OverlayMenu.menu = [];
+ for (var i = 0; i < this.activeServers.length; i++) {
+ var self = this;
+ OverlayMenu.menu.push ({title: this.activeServers[i].name, func : function (idx) { self.selectCallback(idx); } });
+ }
+ OverlayMenu.show();
+
+ break;
+ }
+ }
+
+};
+
+
+VdrServers.prototype.selectCallback = function (idx) {
+ Config.serverAddr = this.activeServers[idx].addr;
+ Config.serverUrl = "http://" + Config.serverAddr;
+ Config.serverName = this.activeServers[idx].name;
+
+ Main.log ("vdrServers.selectCallback idx= " + idx + " Config.serverUrl= " + Config.serverUrl);
+
+ $("#selectTitle").text(Config.serverName );
+ $("#logoTitle").text(Config.serverName );
+
+ Config.fetchConfig();
+
+
+};
+
+//**************************************************
+function VdrServerChecker(parent, i) {
+ this.ipaddr = "";
+ this.idx = i;
+ this.parent = parent;
+};
+
+VdrServerChecker.prototype.checkServer = function (addr) {
+ this.ipaddr = addr;
+ var url ="http://"+ addr + "/serverName.xml";
+ $.ajax({
+ url: url,
+ type : "GET",
+ context : this,
+ timeout : 400,
+ success : function(data, status, XHR ) {
+ var name = $(data).find('hostname').text();
+ var ip = $(data).find('ipaddress').text();
+ Main.log ("checkServer Success Inst= " + this.ipaddr + " " + name + " " + ip);
+ this.parent.activeServers.push({name : name, addr : ip});
+ this.parent.handleResponse();
+ },
+ error : function (XHR, status, error) {
+ Main.log ("checkServer Error Inst= " + this.ipaddr +" status: " + ((status != null) ? status : "null"));
+ if (status != null)
+ if (status == "error") {
+ this.parent.activeServers.push({name : "Unnamed " + this.idx, addr : this.ipaddr});
+ }
+ this.parent.handleResponse();
+ }
+ });
+
+};
|