1 /* 2 * This is system cordova_plugin (TV specific API). 3 * Apache License (2004). See http://www.apache.org/licenses/LICENSE-2.0 4 * 5 * Copyright (c) 2014, LG Electronics, Inc. 6 */ 7 8 9 /** 10 * This represents the configuration API itself, and provides a global namespace for operating configuration service. 11 * @class 12 */ 13 cordova.define('cordova/plugin/configuration', function (require, exports, module) { // jshint ignore:line 14 15 function log(msg) { 16 //console.log//will be removed // jshint ignore:line 17 } 18 19 var service; 20 if (window.PalmSystem) { // jshint ignore:line 21 log("Window.PalmSystem Available"); 22 service = require('cordova/plugin/webos/service'); 23 } else { 24 service = { 25 Request : function (uri, params) { 26 log(uri + " invoked. But I am a dummy because PalmSystem is not available"); 27 28 if (typeof params.onFailure === 'function') { 29 params.onFailure({ returnValue:false, 30 errorText:"PalmSystem Not Available. Cordova is not installed?"}); 31 } 32 }}; 33 } 34 35 36 /** 37 * configuration interface 38 */ 39 var Configuration = function () { 40 }; 41 42 function checkErrorCodeNText(result, errorCode, errorText) { 43 44 if (result.errorCode == undefined || result.errorCode == null ) { 45 result.errorCode = errorCode; 46 } 47 if (result.errorText == undefined || result.errorText == null) { 48 result.errorText = errorText; 49 } 50 } 51 52 /** 53 * @namespace Configuration.PictureMode 54 */ 55 Configuration.PictureMode = { 56 /** 57 * vivid 58 * @since 1.0 59 * @constant 60 */ 61 VIVID : "vivid", 62 /** 63 * standard 64 * @since 1.0 65 * @constant 66 */ 67 STANDARD : "normal", 68 /** 69 * APS (Auto Power Saving) 70 * @since 1.0 71 * @constant 72 */ 73 APS : "eco", 74 /** 75 * cinema 76 * @since 1.0 77 * @constant 78 */ 79 CINEMA : "cinema", 80 /** 81 * game 82 * @since 1.0 83 * @constant 84 */ 85 GAME : "game", 86 /** 87 * sports 88 * @since 1.0 89 * @constant 90 */ 91 SPORTS : "sports", 92 /** 93 * expert1 94 * @since 1.0 95 * @constant 96 */ 97 EXPERT1 : "expert1", 98 /** 99 * expert2 (calibration) 100 * @since 1.0 101 * @constant 102 */ 103 EXPERT2 : "expert2" 104 }; 105 106 107 /** 108 * @namespace Configuration.AppMode 109 */ 110 Configuration.AppMode = { 111 /** 112 * local 113 * @since 1.1 114 * @constant 115 */ 116 LOCAL : "local", 117 /** 118 * usb 119 * @since 1.1 120 * @constant 121 */ 122 USB : "usb", 123 /** 124 * remote 125 * @since 1.1 126 * @constant 127 */ 128 REMOTE : "remote" 129 }; 130 131 var version = null; 132 function checkPlatformVersion(cb) { 133 134 if (version === null) { 135 136 service.Request('luna://com.webos.service.tv.systemproperty', { 137 method: 'getSystemInfo', 138 parameters: { 139 keys: ["sdkVersion"] 140 }, 141 onSuccess: function(result) { 142 log("getPlatformInfo: onSuccess"); 143 144 var temp = result.sdkVersion.split('.'); 145 if (temp.length >= 1 && temp[0] === '1') { 146 version = 1; 147 } else if (temp.length >= 1 && temp[0] === '2') { 148 version = 2; 149 } else { 150 version = 0; 151 } 152 153 delete result.returnValue; 154 155 cb(version); 156 157 }, 158 onFailure: function(error) { 159 log("getPlatformInfo: onFailure"); 160 delete error.returnValue; 161 version = 0; 162 163 cb(version); 164 } 165 }); 166 167 } else { 168 cb(version); 169 } 170 } 171 172 /** 173 * Sets picture mode. Each <a href="Configuration.PictureMode.html#constructor">PictureMode</a> has a set of predefined picture properties. And each picture properties can be changed with setPictureProperty(). 174 * 175 * @class Configuration 176 * @param {Function} successCallback success callback function. 177 * @param {Function} errorCallback failure callback function. 178 * @param {Object} options 179 * <div align=left> 180 * <table class="hcap_spec" width=400> 181 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 182 * <tbody> 183 * <tr><th>mode</th><th>String</th><th><a href="Configuration.PictureMode.html#constructor">Configuration.PictureMode</a></th><th>required</th></tr> 184 * </tbody> 185 * </table> 186 * </div> 187 * @example 188 * // Javascript code 189 * function setPictureMode () { 190 * var options = { 191 * mode : Configuration.PictureMode.VIVID 192 * }; 193 * 194 * function successCb() { 195 * // Do something 196 * } 197 * 198 * function failureCb(cbObject) { 199 * var errorCode = cbObject.errorCode; 200 * var errorText = cbObject.errorText; 201 * console.log ("Error Code [" + errorCode + "]: " + errorText); 202 * } 203 * 204 * var configuration = new Configuration(); 205 * configuration.setPictureMode(successCb, failureCb, options); 206 * } 207 * @since 1.0 208 * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br> 209 * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p> 210 * @see 211 * <a href="Configuration%23getPictureMode.html">Configuration.getPictureMode()</a><br> 212 */ 213 Configuration.prototype.setPictureMode = function (successCallback, errorCallback, options) { 214 215 log("setPictureMode: " + JSON.stringify(options)); 216 217 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 218 method : "set", 219 parameters : { 220 category : "picture", 221 settings : { "pictureMode" : options.mode } 222 }, 223 onSuccess : function(result) { 224 log("setPictureMode: On Success"); 225 226 if (result.returnValue === true) { 227 if(successCallback && typeof successCallback === 'function') { 228 successCallback(); 229 } 230 } 231 }, 232 onFailure : function(result) { 233 log("setPictureMode: On Failure"); 234 delete result.returnValue; 235 if (errorCallback && typeof errorCallback === 'function') { 236 checkErrorCodeNText(result, "CSPM", "Configuration.setPictureMode returns failure."); 237 errorCallback(result); 238 } 239 } 240 }); 241 242 log("Configuration.setPictureMode Done"); 243 }; 244 245 /** 246 * Gets picture mode. Each <a href="Configuration.PictureMode.html#constructor">PictureMode</a> has a set of predefined picture properties. 247 * 248 * @class Configuration 249 * @param {Function} successCallback success callback function. 250 * @param {Function} errorCallback failure callback function. 251 * @return {Object} 252 * <div align=left> 253 * <table class="hcap_spec" width=400> 254 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 255 * <tbody> 256 * <tr><th>mode</th><th>String</th><th><a href="Configuration.PictureMode.html#constructor">Configuration.PictureMode</a></th></tr> 257 * </tbody> 258 * </table> 259 * </div> 260 * 261 * @example 262 * // Javascript code 263 * function getPictureMode () { 264 * function successCb(cbObject) { 265 * console.log("cbObject : " + JSON.stringify(cbObject)); 266 * console.log("mode : " + cbObject.mode); 267 * 268 * // Do something 269 * ... 270 * } 271 * 272 * function failureCb(cbObject) { 273 * var errorCode = cbObject.errorCode; 274 * var errorText = cbObject.errorText; 275 * console.log ("Error Code [" + errorCode + "]: " + errorText); 276 * } 277 * 278 * var configuration = new Configuration(); 279 * configuration.getPictureMode(successCb, failureCb); 280 * } 281 * @since 1.0 282 * @see 283 * <a href="Configuration%23setPictureMode.html">Configuration.setPictureMode()</a><br> 284 */ 285 Configuration.prototype.getPictureMode = function (successCallback, errorCallback) { 286 287 log("getPictureMode: "); 288 289 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 290 method : "get", 291 parameters : { 292 category : "picture", 293 keys : ["pictureMode"] 294 }, 295 onSuccess : function(result) { 296 log("getPictureMode: On Success"); 297 298 if (result.returnValue === true) { 299 if (successCallback && typeof successCallback === 'function') { 300 var cbObj = {}; 301 cbObj.mode = result.settings.pictureMode; 302 303 successCallback(cbObj); 304 } 305 } 306 }, 307 onFailure : function(result) { 308 log("getPictureMode: On Failure"); 309 delete result.returnValue; 310 if (errorCallback && typeof errorCallback === 'function') { 311 checkErrorCodeNText(result, "CGPM", "Configuration.getPictureMode returns failure."); 312 errorCallback(result); 313 } 314 } 315 }); 316 317 log("Configuration.getPictureMode Done"); 318 319 }; 320 321 /** 322 * Sets picture property. Each picture mode has a set of picture properties. 323 * If picture mode is changed, picture properties of that mode will be set accordingly. 324 * 325 * 326 * <div align=left> 327 * <table class="hcap_spec" width=400> 328 * <thead><tr><th>Property</th><th>VIVID</th><th>STANDARD</th><th>APS</th><th>CINEMA</th><th>SPORTS</th><th>GAME</th><th>EXPERTS1</th><th>EXPERTS2</th></tr></thead> 329 * <tbody> 330 * <tr><th>backlight</th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 331 * <tr class="odd"><th>contrast</th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 332 * <tr><th>brightness</th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 333 * <tr class="odd"><th>sharpness</th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> X </th><th> X </th></tr> 334 * <tr><th>hSharpness</th><th> X </th><th> X </th><th> X </th><th> X </th><th> X </th><th> X </th><th> O </th><th> O </th></tr> 335 * <tr class="odd"><th>vSharpness</th><th> X </th><th> X </th><th> X </th><th> X </th><th> X </th><th> X </th><th> O </th><th> O </th></tr> 336 * <tr><th>color</th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 337 * <tr class="odd"><th>tint</th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 338 * <tr><th>colorTemperature</th><th> O </th><th> O </th><th> O </th><th> X </th><th> O </th><th> O </th><th> X </th><th> X </th></tr> 339 * <tr class="odd"><th>dynamicContrast</th><th> X </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 340 * <tr><th>superResolution</th><th> X </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 341 * <tr class="odd"><th>colorGamut</th><th> X </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 342 * <tr><th>dynamicColor</th><th> X </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 343 * <tr class="odd"><th>noiseReduction</th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 344 * <tr><th>mpegNoiseReduction</th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 345 * <tr class="odd"><th>blackLevel</th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 346 * <tr><th>gamma</th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th><th> O </th></tr> 347 * </tbody> 348 * </table> 349 * </div> 350 * 351 * @class Configuration 352 * @param {Function} successCallback success callback function. 353 * @param {Function} errorCallback failure callback function. 354 * @param {Object} options 355 * <div align=left> 356 * <table class="hcap_spec" width=400> 357 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 358 * <tbody> 359 * <tr><th>backlight</th><th>Number</th><th>backlight of display (0~100) </th><th>optional</th></tr> 360 * <tr class="odd"><th>contrast</th><th>Number</th><th>contrast of display (0~100) </th><th>optional</th></tr> 361 * <tr><th>brightness</th><th>Number</th><th>brightness of display (0~100) </th><th>optional</th></tr> 362 * <tr class="odd"><th>sharpness</th><th>Number</th><th>sharpness of display (0~50) </th><th>optional</th></tr> 363 * <tr><th>hSharpness</th><th>Number</th><th>hSharpness of display (0~50)</th><th>optional</th></tr> 364 * <tr class="odd"><th>vSharpness</th><th>Number</th><th>vSharpness of display (0~50) </th><th>optional</th></tr> 365 * <tr><th>color</th><th>Number</th><th>color of display (0~100) </th><th>optional</th></tr> 366 * <tr class="odd"><th>tint</th><th>Number</th><th>tint of display (0~100) R:0, G:100</th><th>optional</th></tr> 367 * <tr><th>colorTemperature</th><th>Number</th><th>colorTemperature of display (0~100) W:0, C:100 </th><th>optional</th></tr> 368 * <tr class="odd"><th>dynamicContrast</th><th>String</th><th>dynamicContrast of display (off/low/medium/high) </th><th>optional</th></tr> 369 * <tr><th>superResolution</th><th>String</th><th>superResolution of display (off/low/medium/high) </th><th>optional</th></tr> 370 * <tr class="odd"><th>colorGamut</th><th>String</th><th>colorGamut of display (wide/standard) </th><th>optional</th></tr> 371 * <tr><th>dynamicColor</th><th>String</th><th>dynamicColor of display (off/low/medium/high) </th><th>optional</th></tr> 372 * <tr class="odd"><th>noiseReduction</th><th>String</th><th>noiseReduction of display (auto/off/low/medium/high) </th><th>optional</th></tr> 373 * <tr><th>mpegNoiseReduction</th><th>String</th><th>mpegNoiseReduction of display (auto/off/low/medium/high) </th><th>optional</th></tr> 374 * <tr class="odd"><th>blackLevel</th><th>String</th><th>blackLevel of display (low/high) </th><th>optional</th></tr> 375 * <tr><th>gamma</th><th>String</th><th>gamma of display (low/medium/high/high2) </th><th>optional</th></tr> 376 * </tbody> 377 * </table> 378 * </div> 379 * 380 * Note : 'high2' option is depends on platform. 381 * @example 382 * // Javascript code 383 * function setPictureProperty () { 384 * var options = { 385 * // For example, expert1 mode. 386 * backlight : 50, 387 * contrast : 50, 388 * brightness : 50, 389 * hSharpness : 50, 390 * vSharpness : 50, 391 * color : 50, 392 * tint : 50, 393 * colorTemparature : 50, 394 * dynamicContrast : "low", 395 * superResolution : "low", 396 * colorGamut : "wide", 397 * dynamicColor : "high", 398 * noiseReduction : "medium", 399 * mpegNoiseReduction : "low", 400 * blackLevel : "low", 401 * gamma : "medium" 402 * }; 403 * 404 * function successCb() { 405 * // Do something 406 * } 407 * 408 * function failureCb(cbObject) { 409 * var errorCode = cbObject.errorCode; 410 * var errorText = cbObject.errorText; 411 * console.log ("Error Code [" + errorCode + "]: " + errorText); 412 * } 413 * 414 * var configuration = new Configuration(); 415 * configuration.setPictureProperty(successCb, failureCb, options); 416 * } 417 * @since 1.0 418 * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br> 419 * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p> 420 * @see 421 * <a href="Configuration%23getPictureProperty.html">Configuration.getPictureProperty()</a><br> 422 */ 423 Configuration.prototype.setPictureProperty = function (successCallback, errorCallback, options) { 424 425 log("setPictureProperty: " + JSON.stringify(options)); 426 427 checkPlatformVersion(function(ver){ 428 429 var sets = {}; 430 431 for (var key in options) { 432 if (key !== undefined && key !== null) { 433 sets[key] = options[key]; 434 if (key === 'tint' || key === 'colorTemperature') {sets[key] -=50;} 435 else if (key === 'blackLevel') { 436 sets[key] = {"unknown":options[key]}; 437 if (options[key] !== "low" && options[key] !== "high" ) { 438 log("setPictureProperty: gamma value error " + JSON.stringify(options)); 439 var result = {}; 440 checkErrorCodeNText(result, "CSPP", "Configuration.setPictureProperty, There is No matched item : blackLevel."); 441 errorCallback(result); 442 return; 443 } 444 } else if (key === 'gamma' && ver === 2 && options[key] === "high") { 445 sets[key] = "high1"; 446 } 447 } 448 } 449 450 log(JSON.stringify(sets)); 451 452 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 453 method : "set", 454 parameters : { 455 category : "picture", 456 settings : sets 457 }, 458 onSuccess : function(result) { 459 log("setPictureProperty: On Success"); 460 461 if (result.returnValue === true) { 462 if (successCallback && typeof successCallback === 'function') { 463 successCallback(); 464 } 465 } 466 }, 467 onFailure : function(result) { 468 log("setPictureProperty: On Failure"); 469 delete result.returnValue; 470 if (errorCallback && typeof errorCallback === 'function') { 471 checkErrorCodeNText(result, "CSPP", "Configuration.setPictureProperty returns failure."); 472 errorCallback(result); 473 } 474 } 475 }); 476 477 log("Configuration.setPictureProperty Done"); 478 479 }); 480 481 }; 482 483 /** 484 * Gets picture property. Each <a href="Configuration.PictureMode.html#constructor">PictureMode</a> has a set of predefined picture properties. 485 * 486 * @class Configuration 487 * @param {Function} successCallback success callback function. 488 * @param {Function} errorCallback failure callback function. 489 * @return {Object} 490 * <div align=left> 491 * <table class="hcap_spec" width=400> 492 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Available</th></tr></thead> 493 * <tbody> 494 * <tr><th>backlight</th><th>Number</th><th>backlight of display (0~100) </th><th>optional</th></tr> 495 * <tr class="odd"><th>contrast</th><th>Number</th><th>contrast of display (0~100) </th><th>optional</th></tr> 496 * <tr><th>brightness</th><th>Number</th><th>brightness of display (0~100) </th><th>optional</th></tr> 497 * <tr class="odd"><th>sharpness</th><th>Number</th><th>sharpness of display (0~50) </th><th>optional</th></tr> 498 * <tr><th>hSharpness</th><th>Number</th><th>hSharpness of display (0~50)</th><th>optional</th></tr> 499 * <tr class="odd"><th>vSharpness</th><th>Number</th><th>vSharpness of display (0~50) </th><th>optional</th></tr> 500 * <tr><th>color</th><th>Number</th><th>color of display (0~100) </th><th>optional</th></tr> 501 * <tr class="odd"><th>tint</th><th>Number</th><th>tint of display (0~100) R:0, G:100</th><th>optional</th></tr> 502 * <tr><th>colorTemperature</th><th>Number</th><th>colorTemperature of display (0~100) W:0, C:100 </th><th>optional</th></tr> 503 * <tr class="odd"><th>dynamicContrast</th><th>String</th><th>dynamicContrast of display (off/low/medium/high) </th><th>optional</th></tr> 504 * <tr><th>superResolution</th><th>String</th><th>superResolution of display (off/low/medium/high) </th><th>optional</th></tr> 505 * <tr class="odd"><th>colorGamut</th><th>String</th><th>colorGamut of display (wide/standard) </th><th>optional</th></tr> 506 * <tr><th>dynamicColor</th><th>String</th><th>dynamicColor of display (off/low/medium/high) </th><th>optional</th></tr> 507 * <tr class="odd"><th>noiseReduction</th><th>String</th><th>noiseReduction of display (auto/off/low/medium/high) </th><th>optional</th></tr> 508 * <tr><th>mpegNoiseReduction</th><th>String</th><th>mpegNoiseReduction of display (auto/off/low/medium/high) </th><th>optional</th></tr> 509 * <tr class="odd"><th>blackLevel</th><th>String</th><th>blackLevel of display (low/high) </th><th>optional</th></tr> 510 * <tr><th>gamma</th><th>String</th><th>gamma of display (low/medium/high) </th><th>optional</th></tr> 511 * </tbody> 512 * </table> 513 * </div> 514 * 515 * @example 516 * // Javascript code 517 * function getPictureProperty () { 518 * function successCb(cbObject) { 519 * console.log("cbObject : " + JSON.stringify(cbObject)); 520 * 521 * console.log("back light : " + cbObject.backlight); 522 * console.log("contrast : " + cbObject.contrast); 523 * console.log("brightness : " + cbObject.brightness); 524 * console.log("color : " + cbObject.color); 525 * console.log("tint : " + cbObject.tint); 526 * 527 * // Do something 528 * ... 529 * } 530 * 531 * function failureCb(cbObject) { 532 * var errorCode = cbObject.errorCode; 533 * var errorText = cbObject.errorText; 534 * console.log ("Error Code [" + errorCode + "]: " + errorText); 535 * } 536 * 537 * var configuration = new Configuration(); 538 * configuration.getPictureProperty(successCb, failureCb); 539 * } 540 * @since 1.0 541 * @see 542 * <a href="Configuration%23setPictureProperty.html">Configuration.setPictureProperty()</a><br> 543 */ 544 Configuration.prototype.getPictureProperty = function (successCallback, errorCallback) { 545 546 log("getPictureProperty: "); 547 548 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 549 method : "get", 550 parameters : { 551 category : "picture", 552 keys : ["brightness", "contrast", "color", "tint", "backlight", "sharpness", "hSharpness", "vSharpness", "colorTemperature", "dynamicContrast", "superResolution", "colorGamut", "dynamicColor", "noiseReduction", "mpegNoiseReduction", "blackLevel", "gamma" ] 553 }, 554 onSuccess : function(result) { 555 log("getPictureProperty: On Success"); 556 557 if (result.returnValue === true) { 558 if (successCallback && typeof successCallback === 'function') { 559 var cbObj = {}; 560 for (var key in result.settings) { 561 if (key !== undefined && key !== null) { 562 cbObj[key] = (isNaN(result.settings[key]) ? result.settings[key] : Number(result.settings[key]) ); 563 if (key === 'tint' || key === 'colorTemperature') {cbObj[key] +=50;} 564 else if (key === 'blackLevel') {cbObj[key] = result.settings[key].unknown;} 565 } 566 567 } 568 569 successCallback(cbObj); 570 } 571 } 572 }, 573 onFailure : function(result) { 574 log("getPictureProperty: On Failure"); 575 delete result.returnValue; 576 if (errorCallback && typeof errorCallback === 'function') { 577 checkErrorCodeNText(result, "CGPP", "Configuration.getPictureProperty returns failure."); 578 errorCallback(result); 579 } 580 } 581 }); 582 583 log("Configuration.getPictureProperty Done"); 584 585 }; 586 587 var mapTable = {"alias" : "signageName"}; 588 589 /** 590 * Sets property. 591 * @class Configuration 592 * @param {Function} successCallback success callback function. 593 * @param {Function} errorCallback failure callback function. 594 * @param {Object} options string in JSON format. Refer to Configuration.getProperty for available keys of property(e.g. '{"alias":"display_1"}'). 595 * 596 * @example 597 * // Javascript code 598 * function setProperty () { 599 * var options = '{"alias":"display_1"}'; 600 * 601 * function successCb() { 602 * // Do something 603 * } 604 * 605 * function failureCb(cbObject) { 606 * var errorCode = cbObject.errorCode; 607 * var errorText = cbObject.errorText; 608 * console.log ("Error Code [" + errorCode + "]: " + errorText); 609 * } 610 * 611 * var configuration = new Configuration(); 612 * configuration.setProperty(successCb, failureCb, options); 613 * } 614 * 615 * @return 616 * <p>If the method is successfully executed, success callback function is called without a parameter.</br> 617 * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p> 618 * @since 1.0 619 */ 620 Configuration.prototype.setProperty = function (successCallback, errorCallback, options) { 621 622 log("setProperty: " + JSON.stringify(options)); 623 624 var ret = JSON.parse(options); 625 var sets = {}; 626 for (var key in ret) { 627 if (mapTable[key] !== undefined) { 628 sets[(mapTable[key])] = ret[key]; 629 } 630 } 631 632 633 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 634 method : "set", 635 parameters : { 636 category : "commercial", 637 settings : sets 638 }, 639 onSuccess : function(result) { 640 log("setProperty: On Success"); 641 642 if (result.returnValue === true) { 643 if (successCallback && typeof successCallback === 'function') { 644 successCallback(); 645 } 646 } 647 }, 648 onFailure : function(result) { 649 log("setProperty: On Failure"); 650 delete result.returnValue; 651 if (errorCallback && typeof errorCallback === 'function') { 652 checkErrorCodeNText(result, "CSP", "Configuration.setProperty returns failure."); 653 errorCallback(result); 654 } 655 } 656 }); 657 658 log("Configuration.setProperty Done"); 659 660 }; 661 662 /** 663 * Gets the property of platform using key. This property can be either platform specific or user set value. 664 * @class Configuration 665 * @param {Function} successCallback success callback function. 666 * @param {Function} errorCallback failure callback function. 667 * @param {Object} options string in JSON. It should have "keys" string in JSON which has an array of keys for the value. For example, '{"keys":["alias","key2"]}' . 668 * <div align=left> 669 * <table class="hcap_spec" width=400> 670 * <thead><tr><th>Key</th><th>Description</th><th>Format</th><th>Read/Write</th><th>Example</th></tr></thead> 671 * <tbody> 672 * <tr><th>alias</th><th>Display alias name</th><th>String</th><th>read/write</th><th>display_1</th></tr> 673 * </tbody> 674 * </table> 675 * </div> 676 * 677 * @return {Object} String in JSON. For example, '{"alias":"display_1"}'. 678 * 679 * @example 680 * // Javascript code 681 * function getProperty () { 682 * var options = '{"keys":["alias"]}'; 683 * 684 * function successCb(cbObject) { 685 * console.log("cbObject : " + JSON.stringify(cbObject)); 686 * var parsedString = JSON.parse(cbObject); 687 * 688 * for(var key in parsedString) { 689 * var value = parsedString[key]; 690 * console.log(key + ": " + value); 691 * } 692 * } 693 * 694 * function failureCb(cbObject) { 695 * var errorCode = cbObject.errorCode; 696 * var errorText = cbObject.errorText; 697 * console.log ("Error Code [" + errorCode + "]: " + errorText); 698 * } 699 * 700 * var configuration = new Configuration(); 701 * configuration.getProperty(successCb, failureCb, options); 702 * } 703 * 704 * @since 1.0 705 */ 706 Configuration.prototype.getProperty = function (successCallback, errorCallback, options) { 707 708 log("getProperty: "); 709 710 var ret = JSON.parse(options); 711 var keys = ret.keys; 712 var arrayKeys = []; 713 714 for (var key in keys) { 715 if (key !== null && key !== undefined) { 716 log("key" + keys[key]); 717 arrayKeys.push(mapTable[keys[key]]); 718 } 719 } 720 721 log(arrayKeys); 722 723 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 724 method : "get", 725 parameters : { 726 category : "commercial", 727 keys : arrayKeys 728 }, 729 onSuccess : function(result) { 730 log("getProperty: On Success"); 731 732 if (result.returnValue === true) { 733 if (successCallback && typeof successCallback === 'function') { 734 var cbObj = {}; 735 736 for (var key in keys) { 737 if (key !== null || key !== undefined) { 738 log("key" + keys[key]); 739 if (result.settings[mapTable[keys[key]]] !== undefined || result.settings[mapTable[keys[key]]] !== null) { 740 cbObj[keys[key]] = result.settings[mapTable[keys[key]]]; 741 } 742 } 743 } 744 745 successCallback(JSON.stringify(cbObj)); 746 } 747 } 748 }, 749 onFailure : function(result) { 750 log("getProperty: On Failure"); 751 delete result.returnValue; 752 if (errorCallback && typeof errorCallback === 'function') { 753 checkErrorCodeNText(result, "CGP", "Configuration.getProperty returns failure."); 754 errorCallback(result); 755 } 756 } 757 }); 758 759 log("Configuration.getProperty Done"); 760 761 }; 762 763 /** 764 * Sets current time. 765 * @class Configuration 766 * @param {Function} successCallback success callback function. 767 * @param {Function} errorCallback failure callback function. 768 * @param {Object} options 769 * <div align=left> 770 * <table class="hcap_spec" width=400> 771 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 772 * <tbody> 773 * <tr><th>year</th><th>Number</th><th>year (2000~2037)</th><th>required</th></tr> 774 * <tr class="odd"><th>month</th><th>Number</th><th>month (1~12)</th><th>required</th></tr> 775 * <tr><th>day</th><th>Number</th><th>day (1~31)</th><th>required</th></tr> 776 * <tr class="odd"><th>hour</th><th>Number</th><th>hour (0~23)</th><th>required</th></tr> 777 * <tr><th>minute</th><th>Number</th><th>minute (0~59)</th><th>required</th></tr> 778 * <tr class="odd"><th>sec</th><th>Number</th><th>sec (0~59)</th><th>required</th></tr> 779 * <tr><th>ntp</th><th>Boolean</th><th>NTP(Network Time Protocol) is enabled. If ntp is enabled, other setting values are ignored. true : enabled / false : disabled (default)</th><th>optional</th></tr> 780 * </tbody> 781 * </table> 782 * </div> 783 * 784 * @example 785 * // Javascript code 786 * function setCurrentTime () { 787 * var options = { 788 * year : 2014, 789 * month : 1, 790 * day : 6, 791 * hour : 14, 792 * minute : 40, 793 * sec : 50 794 * }; 795 * 796 * function successCb() { 797 * // Do something 798 * } 799 * 800 * function failureCb(cbObject) { 801 * var errorCode = cbObject.errorCode; 802 * var errorText = cbObject.errorText; 803 * console.log ("Error Code [" + errorCode + "]: " + errorText); 804 * } 805 * 806 * var configuration = new Configuration(); 807 * configuration.setCurrentTime(successCb, failureCb, options); 808 * } 809 * 810 * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br> 811 * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p> 812 * @since 1.0 813 * @since 1.3 options.ntp 814 * @see 815 * <a href="Configuration%23getCurrentTime.html">Configuration.getCurrentTime()</a><br> 816 */ 817 Configuration.prototype.setCurrentTime = function (successCallback, errorCallback, options) { 818 819 log("setCurrentTime: " + JSON.stringify(options)); 820 var input = new Date(options.year, options.month-1, options.day, options.hour, options.minute, options.sec); 821 822 if (options.year < 2000 || 823 options.year > 2037 || 824 input.getFullYear() !== options.year || 825 input.getMonth() !== (options.month-1) || 826 input.getDate() !== options.day || 827 input.getHours() !== options.hour || 828 input.getMinutes() !== options.minute || 829 input.getSeconds() !== options.sec) { 830 831 if (typeof errorCallback === 'function') { 832 log("setCurrentTime: out of range or invalid parameter type"); 833 var result = {}; 834 checkErrorCodeNText(result, "CSCT", "Configuration.setCurrentTime returns failure for out of range."); 835 errorCallback(result); 836 return; 837 } 838 } 839 840 log("setCurrentTime: " + input); 841 842 var utcSec = input.getTime() / 1000; 843 844 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 845 method : "setSystemTime", 846 parameters : { 847 utc : utcSec, 848 ntp : options.ntp 849 }, 850 onSuccess : function() { 851 log("setCurrentTime: On Success"); 852 if (typeof successCallback === 'function') { 853 successCallback(); 854 } 855 }, 856 onFailure : function(result) { 857 log("setCurrentTime: On Failure"); 858 /* 859 delete result.returnValue; 860 if (typeof errorCallback === 'function') { 861 checkErrorCodeNText(result, "CSCT", "Configuration.setCurrentTime returns failure."); 862 errorCallback(result); 863 } 864 */ 865 866 // will be removed after storage service submission 106 867 service.Request("luna://com.palm.systemservice/time/", { 868 method : "setSystemTime", 869 parameters : { 870 utc : utcSec 871 }, 872 onSuccess : function() { 873 log("setCurrentTime: On Success"); 874 if (typeof successCallback === 'function') { 875 successCallback(); 876 } 877 }, 878 onFailure : function(result) { 879 log("setCurrentTime: On Failure"); 880 delete result.returnValue; 881 if (typeof errorCallback === 'function') { 882 checkErrorCodeNText(result, "CSCT", "Configuration.setCurrentTime returns failure."); 883 errorCallback(result); 884 } 885 } 886 }); 887 // end 888 } 889 }); 890 891 log("Configuration.setCurrentTime Done"); 892 893 }; 894 895 /** 896 * Gets current time. 897 * @class Configuration 898 * @param {Function} successCallback success callback function. 899 * @param {Function} errorCallback failure callback function. 900 * @return {Object} 901 * <div align=left> 902 * <table class="hcap_spec" width=400> 903 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 904 * <tbody> 905 * <tr><th>year</th><th>Number</th><th>year (2000~2037)</th><th>required</th></tr> 906 * <tr class="odd"><th>month</th><th>Number</th><th>month (1~12)</th><th>required</th></tr> 907 * <tr><th>day</th><th>Number</th><th>day (1~31)</th><th>required</th></tr> 908 * <tr class="odd"><th>hour</th><th>Number</th><th>hour (0~23)</th><th>required</th></tr> 909 * <tr><th>minute</th><th>Number</th><th>minute (0~59)</th><th>required</th></tr> 910 * <tr class="odd"><th>sec</th><th>Number</th><th>sec (0~59)</th><th>required</th></tr> 911 * <tr><th>ntp</th><th>Boolean</th><th>NTP(Network Time Protocol) is enabled. true : enabled / false : disabled (default)</th><th>optional</th></tr> 912 * </tbody> 913 * </table> 914 * </div> 915 * 916 * @example 917 * // Javascript code 918 * function getCurrentTime () { 919 * function successCb(cbObject) { 920 * console.log("cbObject : " + JSON.stringify(cbObject)); 921 * } 922 * 923 * function failureCb(cbObject) { 924 * var errorCode = cbObject.errorCode; 925 * var errorText = cbObject.errorText; 926 * console.log ("Error Code [" + errorCode + "]: " + errorText); 927 * } 928 * 929 * var configuration = new Configuration(); 930 * configuration.getCurrentTime(successCb, failureCb); 931 * } 932 * 933 * @since 1.0 934 * @since 1.3 returns.ntp 935 * @see 936 * <a href="Configuration%23setCurrentTime.html">Configuration.setCurrentTime()</a><br> 937 */ 938 Configuration.prototype.getCurrentTime = function (successCallback, errorCallback) { 939 940 log("getCurrentTime: "); 941 942 service.Request("luna://com.palm.systemservice/time/", { 943 method : "getEffectiveBroadcastTime", 944 onSuccess : function(result) { 945 log("getCurrentTime : On Success"); 946 947 if(result.returnValue === true) { 948 var cbObj = {}; 949 var d = new Date(result.adjustedUtc * 1000); 950 cbObj.year = d.getFullYear(); 951 cbObj.month = d.getMonth() + 1; 952 cbObj.day = d.getDate(); 953 cbObj.hour = d.getHours(); 954 cbObj.minute = d.getMinutes(); 955 cbObj.sec = d.getSeconds(); 956 957 service.Request("luna://com.palm.systemservice/", { 958 method : "getPreferences", 959 parameters : { 960 keys : ["useNetworkTime"] 961 }, 962 onSuccess : function(res) { 963 log("getPreferences : On Success"); 964 965 if(res.returnValue === true) { 966 967 cbObj.ntp = res.useNetworkTime; 968 969 if (successCallback && typeof successCallback === 'function') { 970 successCallback(cbObj); 971 } 972 973 } else { 974 975 if (errorCallback && typeof errorCallback === 'function') { 976 checkErrorCodeNText(result, "CGCT", "Configuration.getCurrentTime returns failure."); 977 errorCallback(result); 978 } 979 } 980 }, 981 onFailure : function(result) { 982 log("getCurrentTime: On Failure"); 983 delete result.returnValue; 984 if (errorCallback && typeof errorCallback === 'function') { 985 checkErrorCodeNText(result, "CGCT", "Configuration.getCurrentTime returns failure."); 986 errorCallback(result); 987 } 988 } 989 }); 990 } else { 991 if (errorCallback && typeof errorCallback === 'function') { 992 checkErrorCodeNText(result, "CGCT", "Configuration.getCurrentTime returns failure."); 993 errorCallback(result); 994 } 995 } 996 997 }, 998 onFailure : function(result) { 999 log("getCurrentTime: On Failure"); 1000 delete result.returnValue; 1001 if (errorCallback && typeof errorCallback === 'function') { 1002 checkErrorCodeNText(result, "CGCT", "Configuration.getCurrentTime returns failure."); 1003 errorCallback(result); 1004 } 1005 } 1006 }); 1007 1008 log("Configuration.getCurrentTime Done"); 1009 1010 }; 1011 1012 /** 1013 * Restarts the application. 1014 * @class Configuration 1015 * @param {Function} successCallback success callback function. 1016 * @param {Function} errorCallback failure callback function. 1017 * 1018 * @example 1019 * // Javascript code 1020 * function restartApplication () { 1021 * function successCb() { 1022 * console.log("restart success : "); 1023 * } 1024 * 1025 * function failureCb(cbObject) { 1026 * var errorCode = cbObject.errorCode; 1027 * var errorText = cbObject.errorText; 1028 * console.log ("Error Code [" + errorCode + "]: " + errorText); 1029 * } 1030 * 1031 * var configuration = new Configuration(); 1032 * configuration.restartApplication(successCb, failureCb); 1033 * } 1034 * 1035 * @since 1.0 1036 */ 1037 Configuration.prototype.restartApplication = function (successCallback, errorCallback) { 1038 1039 log("restartApp: "); 1040 1041 service.Request("luna://com.webos.service.commercial.signage.storageservice/", { 1042 method : "restart_application", 1043 onSuccess : function(result) { 1044 log("restartApp: On Success"); 1045 1046 if (successCallback && typeof successCallback === 'function') { 1047 successCallback(result); 1048 } 1049 }, 1050 onFailure : function(result) { 1051 log("restartApp: On Failure"); 1052 delete result.returnValue; 1053 if (errorCallback && typeof errorCallback === 'function') { 1054 checkErrorCodeNText(result, "CRA", "Configuration.restartApp returns failure."); 1055 errorCallback(result); 1056 } 1057 } 1058 }); 1059 1060 log("Configuration.restartApp Done"); 1061 1062 }; 1063 1064 1065 /** 1066 * Gets server property. Server property has information about application mode and server settings for application upgrade and launch. 1067 * 1068 * @class Configuration 1069 * @param {Function} successCallback success callback function. 1070 * @param {Function} errorCallback failure callback function. 1071 * @return {Object} 1072 * <div align=left> 1073 * <table class="hcap_spec" width=400> 1074 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 1075 * <tbody> 1076 * <tr><th>serverIp</th><th>String</th><th>IP address (local, usb : to upgrade / remote : to launch )</th></tr> 1077 * <tr class="odd"><th>serverPort</th><th>Number</th><th>Port number (local, usb : to upgrade / remote : to launch )</th></tr> 1078 * <tr><th>secureConnection</th><th>Boolean</th><th>true : https, false : http </th></tr> 1079 * <tr class="odd"><th>appLaunchMode</th><th>String</th><th>launch mode <a href="Configuration.AppMode.html#constructor">Configuration.AppMode</th></tr> 1080 * <tr><th>fqdnMode</th><th>Boolean</th><th>true : use fqdn settings for application upgrade or launch, <br>false : use serverIp and serverPort settings for application upgrade or launch</th></tr> 1081 * <tr class="odd"><th>fqdnAddr</th><th>String</th><th>FQDN url. for example, http://lge.com/index.html or https://lge.com/index.html </th></tr> 1082 * </tbody> 1083 * </table> 1084 * </div> 1085 * 1086 * @example 1087 * // Javascript code 1088 * function getServerProperty () { 1089 * function successCb(cbObject) { 1090 * console.log("cbObject : " + JSON.stringify(cbObject)); 1091 * 1092 * console.log("server IP : " + cbObject.serverIp); 1093 * console.log("server Port : " + cbObject.serverPort); 1094 * console.log("secure Connection : " + cbObject.secureConnection); 1095 * console.log("applicationLaunchMode : " + cbObject.appLaunchMode); 1096 * console.log("fully Qualified Domain Name Mode : " + cbObject.fqdnMode); 1097 * console.log("fully Qualified Domain Name Address: " + cbObject.fqdnAddr); 1098 * 1099 * // Do something 1100 * ... 1101 * } 1102 * 1103 * function failureCb(cbObject) { 1104 * var errorCode = cbObject.errorCode; 1105 * var errorText = cbObject.errorText; 1106 * console.log ("Error Code [" + errorCode + "]: " + errorText); 1107 * } 1108 * 1109 * var configuration = new Configuration(); 1110 * configuration.getServerProperty(successCb, failureCb); 1111 * } 1112 * @since 1.1 1113 * @see 1114 * <a href="Configuration%23setServerProperty.html">Configuration.setServerProperty()</a><br> 1115 */ 1116 Configuration.prototype.getServerProperty = function (successCallback, errorCallback) { 1117 1118 log("getServerProperty: "); 1119 1120 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 1121 method : "get", 1122 parameters : { 1123 category : "commercial", 1124 keys : ["serverIpPort", "siServerIp", "secureConnection", "appLaunchMode", "fqdnAddr", "fqdnMode"] 1125 }, 1126 1127 onSuccess : function(result) { 1128 log("getPictureProperty: On Success"); 1129 1130 if (result.returnValue === true) { 1131 if (successCallback && typeof successCallback === 'function') { 1132 var cbObj = {}; 1133 cbObj.serverIp = result.settings.siServerIp; 1134 cbObj.serverPort = parseInt(result.settings.serverIpPort, 10); 1135 cbObj.secureConnection = (result.settings.secureConnection === "off" ? false : true ); 1136 cbObj.appLaunchMode = result.settings.appLaunchMode; 1137 cbObj.fqdnMode = (result.settings.fqdnMode === "off" ? false : true ); 1138 cbObj.fqdnAddr = result.settings.fqdnAddr; 1139 1140 successCallback(cbObj); 1141 } 1142 } 1143 }, 1144 onFailure : function(result) { 1145 log("getServerProperty: On Failure"); 1146 delete result.returnValue; 1147 if (errorCallback && typeof errorCallback === 'function') { 1148 checkErrorCodeNText(result, "CGSP", "Configuration.getServerProperty returns failure."); 1149 errorCallback(result); 1150 } 1151 } 1152 }); 1153 1154 log("Configuration.getServerProperty Done"); 1155 1156 }; 1157 1158 /** 1159 * Sets the server property. 1160 * <br> 1161 * <hr> 1162 * <b>scap_installation.json</b><br> 1163 * If scap_installation.json file exists under root directory of usb memory and 'Auto Set' is enabled in server settings menu, 1164 * server properties will be set as described in scap_installation.json and 'Auto Set' will be disabled automatically. 1165 * Factory default setting of 'Auto Set' is 'enabled'.</br> 1166 * scap_installation.json schema is as below. 1167 * 1168 * <div><pre class="code prettyprint"> 1169 { 1170 "$schema": "http://json-schema.org/draft-04/schema#", 1171 "id": "", 1172 "type": "object", 1173 "properties": { 1174 "serverIp": { 1175 "id": "serverIp", 1176 "type": "string" 1177 }, 1178 "serverPort": { 1179 "id": "serverPort", 1180 "type": "integer" 1181 }, 1182 "secureConnection": { 1183 "id": "secureConnection", 1184 "type": "boolean" 1185 }, 1186 "appLaunchMode": { 1187 "id": "appLaunchMode", 1188 "type": "string", 1189 "enum": [ 1190 "local", 1191 "usb", 1192 "remote" 1193 ] 1194 }, 1195 "fqdnMode": { 1196 "id": "fqdnMode", 1197 "type": "boolean" 1198 }, 1199 "fqdnAddr": { 1200 "id": "fqdnAddr", 1201 "type": "string" 1202 }, 1203 "required": [ 1204 "serverIp", 1205 "serverPort", 1206 "secureConnection", 1207 "appLaunchMode", 1208 "fqdnMode", 1209 "fqdnAddr" 1210 ] 1211 } 1212 } 1213 * </pre></div> 1214 * scap_installation.json example is as below. <br> 1215 * {<br> 1216 * "serverIp":"10.177.211.51", <br> 1217 * "serverPort":80, <br> 1218 * "secureConnection":false, <br> 1219 * "appLaunchMode":"local",<br> 1220 * "fqdnMode":true,<br> 1221 * "fqdnAddr":"http://192.168.0.1:2000/lgapp.zip"<br> 1222 * }<br> 1223 * <hr> 1224 * @class Configuration 1225 * @param {Function} successCallback success callback function. 1226 * @param {Function} errorCallback failure callback function. 1227 * @param {Object} options 1228 * <div align=left> 1229 * <table class="hcap_spec" width=400> 1230 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 1231 * <tbody> 1232 * <tr><th>serverIp</th><th>String</th><th>IP address (local, usb : to upgrade / remote : to launch )</th><th>required</th></tr> 1233 * <tr class="odd"><th>serverPort</th><th>Number</th><th>Port number (local, usb : to upgrade / remote : to launch )</th><th>required</th></tr> 1234 * <tr><th>secureConnection</th><th>Boolean</th><th>true : https, false : http </th><th>required</th></tr> 1235 * <tr class="odd"><th>appLaunchMode</th><th>String</th><th>launch mode <a href="Configuration.AppMode.html#constructor">Configuration.AppMode</th><th>required</th></tr> 1236 * <tr><th>fqdnMode</th><th>Boolean</th><th>true : use fqdn settings when an application upgrades or launches, 1237 * <br>false : use serverIp and serverPort settings when an application upgrades or launches</th><th>required</th></tr> 1238 * <tr class="odd"><th>fqdnAddr</th><th>String</th><th>FQDN url. for example, http://lge.com/index.html or https://lge.com/index.html </th><th>required</th></tr> 1239 * </tbody> 1240 * </table> 1241 * </div> 1242 * 1243 * @example 1244 * // Javascript code 1245 * function setServerProperty () { 1246 * var options = { 1247 * serverIp : "192.168.0.2", 1248 * serverPort : 80, 1249 * secureConnection : false, 1250 * appLaunchMode : Configuration.AppMode.REMOTE, 1251 * fqdnMode : false, 1252 * fqdnAddr : "http://signage.domain.com/index.html" 1253 * }; 1254 * 1255 * function successCb() { 1256 * // Do something 1257 * } 1258 * 1259 * function failureCb(cbObject) { 1260 * var errorCode = cbObject.errorCode; 1261 * var errorText = cbObject.errorText; 1262 * console.log ("Error Code [" + errorCode + "]: " + errorText); 1263 * } 1264 * 1265 * var configuration = new Configuration(); 1266 * configuration.setServerProperty(successCb, failureCb, options); 1267 * } 1268 * @since 1.1 1269 * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br> 1270 * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p> 1271 * @see 1272 * <a href="Configuration%23getServerProperty.html">Configuration.getServerProperty()</a><br> 1273 */ 1274 Configuration.prototype.setServerProperty = function (successCallback, errorCallback, options) { 1275 1276 log("setServerProperty: " + JSON.stringify(options)); 1277 1278 1279 if(options === undefined || 1280 typeof options.serverIp !== 'string'|| /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(options.serverIp) === false || 1281 isNaN(options.serverPort) || options.serverPort < 0 || options.serverPort > 65535 || typeof options.serverPort !== 'number' || 1282 typeof options.secureConnection !== 'boolean' || typeof options.appLaunchMode !== 'string' || 1283 (options.appLaunchMode !== Configuration.AppMode.USB && options.appLaunchMode !== Configuration.AppMode.LOCAL && options.appLaunchMode !== Configuration.AppMode.REMOTE) || 1284 typeof options.fqdnMode !== 'boolean' || typeof options.fqdnAddr !== 'string') { 1285 1286 if (errorCallback && typeof errorCallback === 'function') { 1287 var result = {}; 1288 checkErrorCodeNText(result, "CSSP", "Configuration.setServerProperty, Invalid parameters."); 1289 log ("options.serverIp : " + typeof options.serverIp + " options.serverPort : " + typeof options.serverPort + " options.secureConnection : " + typeof options.secureConnection + 1290 " options.appLaunchMode : " + typeof options.appLaunchMode + " options.fqdnMode : " + typeof options.fqdnMode + " options.fqdnAddr : " + options.fqdnAddr); 1291 1292 errorCallback(result); 1293 return; 1294 } 1295 1296 } 1297 1298 var sets = {}; 1299 1300 sets.siServerIp = options.serverIp; 1301 sets.serverIpPort = options.serverPort + ''; 1302 sets.secureConnection = ( options.secureConnection === true ? "on" : "off"); 1303 sets.appLaunchMode = options.appLaunchMode; 1304 sets.fqdnMode = ( options.fqdnMode === true ? "on" : "off" ); 1305 sets.fqdnAddr = options.fqdnAddr; 1306 1307 log(JSON.stringify(sets)); 1308 1309 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 1310 method : "set", 1311 parameters : { 1312 category : "commercial", 1313 settings : sets 1314 }, 1315 onSuccess : function(result) { 1316 log("setServerProperty: On Success"); 1317 1318 if (result.returnValue === true) { 1319 if (successCallback && typeof successCallback === 'function') { 1320 successCallback(); 1321 } 1322 } 1323 }, 1324 onFailure : function(result) { 1325 log("setServerProperty: On Failure"); 1326 delete result.returnValue; 1327 if (errorCallback && typeof errorCallback === 'function') { 1328 checkErrorCodeNText(result, "CSSP", "Configuration.setServerProperty returns failure."); 1329 errorCallback(result); 1330 } 1331 } 1332 }); 1333 1334 log("Configuration.setServerProperty Done"); 1335 }; 1336 1337 /** 1338 * Clears the cache data on signage monitor. 1339 * @class Configuration 1340 * @param {Function} successCallback success callback function. 1341 * @param {Function} errorCallback failure callback function. 1342 * 1343 * @example 1344 * // Javascript code 1345 * function clearCache () { 1346 * function successCb() { 1347 * console.log("clearCache success : "); 1348 * } 1349 * 1350 * function failureCb(cbObject) { 1351 * var errorCode = cbObject.errorCode; 1352 * var errorText = cbObject.errorText; 1353 * console.log ("Error Code [" + errorCode + "]: " + errorText); 1354 * } 1355 * 1356 * var configuration = new Configuration(); 1357 * configuration.clearCache(successCb, failureCb); 1358 * } 1359 * 1360 * @since 1.3 1361 */ 1362 Configuration.prototype.clearCache = function (successCallback, errorCallback) { 1363 1364 log("clearCache: "); 1365 1366 service.Request("luna://com.webos.service.commercial.signage.storageservice/", { 1367 method : "clearCache", 1368 onSuccess : function(result) { 1369 log("clearCache: On Success"); 1370 1371 if (successCallback && typeof successCallback === 'function') { 1372 successCallback(result); 1373 } 1374 }, 1375 onFailure : function(result) { 1376 log("clearCache: On Failure"); 1377 delete result.returnValue; 1378 if (errorCallback && typeof errorCallback === 'function') { 1379 checkErrorCodeNText(result, "CCC", "Configuration.clearCache returns failure."); 1380 errorCallback(result); 1381 } 1382 } 1383 }); 1384 1385 log("Configuration.clearCache Done"); 1386 1387 }; 1388 1389 /** 1390 * Gets list of time zone supported on signage monitor. 1391 * 1392 * @class Configuration 1393 * @param {Function} successCallback success callback function. 1394 * @param {Function} errorCallback failure callback function. 1395 * @return {Object} 1396 * <div align=left> 1397 * <table class="hcap_spec" width=400> 1398 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 1399 * <tbody> 1400 * <tr><th>timeZone[]</th><th>Array</th><th> </th><th>required</th></tr> 1401 * <tr class="odd"><th>timeZone[].continent</th><th>String</th><th>continent</th><th>required</th></tr> 1402 * <tr><th>timeZone[].country</th><th>String</th><th>country</th><th>required</th></tr> 1403 * <tr class="odd"><th>timeZone[].city</th><th>String</th><th>city</th><th>required</th></tr> 1404 * </tbody> 1405 * </table> 1406 * </div> 1407 * 1408 * @example 1409 * // Javascript code 1410 * function getTimeZoneList () { 1411 * function successCb(cbObject) { 1412 * 1413 * for (var i = cbObject.timeZone.length-1; i>=0; i--) { 1414 * console.log("timeZone [" + i + "].continent : " + cbObject.timeZone[i].continent); 1415 * console.log("timeZone [" + i + "].country : " + cbObject.timeZone[i].country); 1416 * console.log("timeZone [" + i + "].city : " + cbObject.timeZone[i].city); 1417 * 1418 * } 1419 * 1420 * // Do something 1421 * 1422 * } 1423 * 1424 * function failureCb(cbObject) { 1425 * var errorCode = cbObject.errorCode; 1426 * var errorText = cbObject.errorText; 1427 * console.log ("Error Code [" + errorCode + "]: " + errorText); 1428 * } 1429 * 1430 * var configuration = new Configuration(); 1431 * configuration.getTimeZoneList(successCb, failureCb); 1432 * } 1433 * @since 1.3 1434 * @see 1435 * <a href="Configuration%23setTimeZone.html">Configuration.setTimeZone()</a><br> 1436 * <a href="Configuration%23getTimeZone.html">Configuration.getTimeZone()</a><br> 1437 */ 1438 Configuration.prototype.getTimeZoneList = function (successCallback, errorCallback) { 1439 1440 log("getTimeZoneList: "); 1441 1442 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 1443 method : "getTimeZoneList", 1444 onSuccess : function(result) { 1445 log("getTimeZoneList: On Success"); 1446 1447 if (result.returnValue === true) { 1448 if (successCallback && typeof successCallback === 'function') { 1449 successCallback(result); 1450 } 1451 } 1452 }, 1453 onFailure : function(result) { 1454 log("getTimeZoneList: On Failure"); 1455 delete result.returnValue; 1456 if (errorCallback && typeof errorCallback === 'function') { 1457 checkErrorCodeNText(result, "CGTL", "Configuration.getTimeZoneList returns failure."); 1458 errorCallback(result); 1459 } 1460 } 1461 }); 1462 1463 log("Configuration.getTimeZoneList Done"); 1464 1465 }; 1466 1467 /** 1468 * Gets time zone. 1469 * 1470 * @class Configuration 1471 * @param {Function} successCallback success callback function. 1472 * @param {Function} errorCallback failure callback function. 1473 * @return {Object} 1474 * <div align=left> 1475 * <table class="hcap_spec" width=400> 1476 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 1477 * <tbody> 1478 * <tr><th>timeZone</th><th>Object</th><th> </th><th>required</th></tr> 1479 * <tr class="odd"><th>timeZone.continent</th><th>String</th><th>continent</th><th>required</th></tr> 1480 * <tr><th>timeZone.country</th><th>String</th><th>country</th><th>required</th></tr> 1481 * <tr class="odd"><th>timeZone.city</th><th>String</th><th>city</th><th>required</th></tr> 1482 * </tbody> 1483 * </table> 1484 * </div> 1485 * 1486 * @example 1487 * // Javascript code 1488 * function getTimeZone () { 1489 * function successCb(cbObject) { 1490 * 1491 * console.log("timeZone.continent : " + cbObject.timeZone.continent); 1492 * console.log("timeZone.country : " + cbObject.timeZone.country); 1493 * console.log("timeZone.city : " + cbObject.timeZone.city); 1494 * 1495 * 1496 * // Do something 1497 * 1498 * } 1499 * 1500 * function failureCb(cbObject) { 1501 * var errorCode = cbObject.errorCode; 1502 * var errorText = cbObject.errorText; 1503 * console.log ("Error Code [" + errorCode + "]: " + errorText); 1504 * } 1505 * 1506 * var configuration = new Configuration(); 1507 * configuration.getTimeZone(successCb, failureCb); 1508 * } 1509 * @since 1.3 1510 * @see 1511 * <a href="Configuration%23setTimeZone.html">Configuration.setTimeZone()</a><br> 1512 * <a href="Configuration%23getTimeZoneList.html">Configuration.getTimeZoneList()</a><br> 1513 */ 1514 Configuration.prototype.getTimeZone = function (successCallback, errorCallback) { 1515 1516 log("getTimeZone: "); 1517 1518 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 1519 method : "getTimeZone", 1520 onSuccess : function(result) { 1521 log("getTimeZone: On Success"); 1522 1523 if (result.returnValue === true) { 1524 if (successCallback && typeof successCallback === 'function') { 1525 successCallback(result); 1526 } 1527 } 1528 }, 1529 onFailure : function(result) { 1530 log("getTimeZone: On Failure"); 1531 delete result.returnValue; 1532 if (errorCallback && typeof errorCallback === 'function') { 1533 checkErrorCodeNText(result, "CGTZ", "Configuration.getTimeZone returns failure."); 1534 errorCallback(result); 1535 } 1536 } 1537 }); 1538 1539 log("Configuration.getTimeZone Done"); 1540 1541 }; 1542 1543 1544 /** 1545 * Sets time zone which should be one of the list from getTimeZoneList. 1546 * 1547 * @class Configuration 1548 * @param {Function} successCallback success callback function. 1549 * @param {Function} errorCallback failure callback function. 1550 * @param {Object} options 1551 * <div align=left> 1552 * <table class="hcap_spec" width=400> 1553 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 1554 * <tbody> 1555 * <tr><th>timeZone</th><th>Object</th><th> </th><th>required</th></tr> 1556 * <tr class="odd"><th>timeZone.continent</th><th>String</th><th>continent</th><th>required</th></tr> 1557 * <tr><th>timeZone.country</th><th>String</th><th>country</th><th>required</th></tr> 1558 * <tr class="odd"><th>timeZone.city</th><th>String</th><th>city</th><th>required</th></tr> 1559 * </tbody> 1560 * </table> 1561 * </div> 1562 * 1563 * @example 1564 * // Javascript code 1565 * function setTimeZone () { 1566 * function successCb(cbObject) { 1567 * 1568 * // Do something 1569 * 1570 * } 1571 * 1572 * function failureCb(cbObject) { 1573 * var errorCode = cbObject.errorCode; 1574 * var errorText = cbObject.errorText; 1575 * console.log ("Error Code [" + errorCode + "]: " + errorText); 1576 * } 1577 * 1578 * var configuration = new Configuration(); 1579 * var timeZone = { 1580 * continent : "Asia", 1581 * country : "South Korea", 1582 * city : "Seoul" 1583 * }; 1584 * var options = { timeZone : timeZone }; 1585 * 1586 * configuration.setTimeZone(successCb, failureCb, options); 1587 * } 1588 * 1589 * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br> 1590 * If an error occurs, failure callback function is called with a failure callback object as a parameter.</p> 1591 * 1592 * @since 1.3 1593 * @see 1594 * <a href="Configuration%23getTimeZone.html">Configuration.getTimeZone()</a><br> 1595 * <a href="Configuration%23getTimeZoneList.html">Configuration.getTimeZoneList()</a><br> 1596 */ 1597 Configuration.prototype.setTimeZone = function (successCallback, errorCallback, options) { 1598 1599 log("setTimeZone: "); 1600 1601 service.Request("luna://com.webos.service.commercial.signage.storageservice/settings/", { 1602 method : "setTimeZone", 1603 parameters : options, 1604 onSuccess : function(result) { 1605 log("setTimeZone: On Success"); 1606 1607 if (result.returnValue === true) { 1608 if (successCallback && typeof successCallback === 'function') { 1609 successCallback(result); 1610 } 1611 } 1612 }, 1613 onFailure : function(result) { 1614 log("setTimeZone: On Failure"); 1615 delete result.returnValue; 1616 if (errorCallback && typeof errorCallback === 'function') { 1617 checkErrorCodeNText(result, "CSTZ", "Configuration.setTimeZone returns failure."); 1618 errorCallback(result); 1619 } 1620 } 1621 }); 1622 1623 log("Configuration.setTimeZone Done"); 1624 1625 }; 1626 1627 // hidden for debug 1628 Configuration.prototype.debug = function (successCallback, errorCallback, options) { 1629 1630 // options.enabled = true / false; 1631 1632 log("debug: " + options.enabled); 1633 1634 service.Request("luna://com.webos.service.commercial.signage.storageservice/", { 1635 method : "debug", 1636 parameters : { 1637 enabled : options.enabled 1638 }, 1639 onSuccess : function(result) { 1640 log("debug: On Success"); 1641 1642 if (successCallback && typeof successCallback === 'function') { 1643 successCallback(result); 1644 } 1645 }, 1646 onFailure : function(result) { 1647 log("debug: On Failure"); 1648 delete result.returnValue; 1649 if (errorCallback && typeof errorCallback === 'function') { 1650 checkErrorCodeNText(result, "CD", "Configuration.debug returns failure."); 1651 errorCallback(result); 1652 } 1653 } 1654 }); 1655 1656 log("Configuration.debug Done"); 1657 1658 }; 1659 1660 module.exports = Configuration; 1661 }); 1662 1663 Configuration = cordova.require('cordova/plugin/configuration'); // jshint ignore:line 1664 1665