1 /* 2 * This is sound 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 * This represents the deviceInfo API itself, and provides a global namespace for operating deviceInfo service. 10 * @class 11 */ 12 cordova.define('cordova/plugin/deviceInfo', function (require, exports, module) { // jshint ignore:line 13 14 var service; 15 if (window.PalmSystem){ // jshint ignore:line 16 console.log("Window.PalmSystem Available"); // jshint ignore:line 17 service = require('cordova/plugin/webos/service'); 18 } else { 19 service = { 20 Request : function(uri, params) { 21 console.log(uri + " invoked. But I am a dummy because PalmSystem is not available"); // jshint ignore:line 22 23 if (typeof params.onFailure === 'function') { 24 params.onFailure({ returnValue:false, 25 errorText:"PalmSystem Not Available. Cordova is not installed?"}); 26 } 27 }}; 28 } 29 30 /** 31 * deviceInfo interface 32 */ 33 var DeviceInfo = function () { 34 }; 35 36 function log(msg) { 37 //console.log//will be removed // jshint ignore:line 38 } 39 40 function checkErrorCodeNText(result, errorCode, errorText) { 41 42 if (result.errorCode === undefined || result.errorCode === null ) { 43 result.errorCode = errorCode; 44 } 45 if (result.errorText === undefined || result.errorText === null) { 46 result.errorText = errorText; 47 } 48 } 49 50 /** 51 * Gets network information. Network information includes IP address assigned to wireless / wired LAN, gateway address, netmask and DNS address. 52 * @class DeviceInfo 53 * @param {Function} successCallback success callback function. 54 * @param {Function} errorCallback failure callback function. 55 * @return {Object} 56 * <div align=left> 57 * <table class="hcap_spec" width=400> 58 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 59 * <tbody> 60 * <tr><th>isInternetConnectionAvailable</th><th>Boolean</th><th>Internet connection true: connected, false: not connected</th></tr> 61 * <tr class="odd"><th>wired</th><th>Object</th><th>Wired network information object. </th></tr> 62 * <tr><th>wired.state</th><th>String</th><th>Wired network connection "connected": connected "disconnected": not connected</th></tr> 63 * <tr class="odd"><th>wired.interfaceName</th><th>String</th><th>Wired network interface name. </th></tr> 64 * <tr><th>wired.ipAddress</th><th>String</th><th>IP address assigned to the wired network interface. </th></tr> 65 * <tr class="odd"><th>wired.netmask</th><th>String</th><th>Netmask assigned to the wired network interface. </th></tr> 66 * <tr><th>wired.gateway</th><th>String</th><th>Gateway address assigned to the wired network interface</th></tr> 67 * <tr class="odd"><th>wired.onInternet</th><th>String</th><th>Internet connection to the wired network "yes": connected "no": not connected. </th></tr> 68 * <tr><th>wired.method</th><th>String</th><th>IP allocation "manual": fixed allocation "dhcp": dynamic allocation</th></tr> 69 * <tr class="odd"><th>wired.dns1</th><th>String</th><th>DNS address assigned to the wired network interface. </th></tr> 70 * <tr><th>wired.dns2</th><th>String</th><th>Secondary DNS address assigned to the wired network interface. </th></tr> 71 * <tr class="odd"><th>wifi</th><th>Object</th><th>Wireless network information object. </th></tr> 72 * <tr><th>wifi.state</th><th>String</th><th>Wireless network connection "connected": connected "disconnected": not connected</th></tr> 73 * <tr class="odd"><th>wifi.interfaceName</th><th>String</th><th>Wireless network interface name. </th></tr> 74 * <tr><th>wifi.ipAddress</th><th>String</th><th>IP address assigned to the wireless network interface. </th></tr> 75 * <tr class="odd"><th>wifi.netmask</th><th>String</th><th>Netmask assigned to the wireless network interface. </th></tr> 76 * <tr><th>wifi.gateway</th><th>String</th><th>Gateway address assigned to the wireless network interface</th></tr> 77 * <tr class="odd"><th>wifi.onInternet</th><th>String</th><th>Internet connection to the wireless network "yes": connected "no": not connected. </th></tr> 78 * <tr><th>wifi.method</th><th>String</th><th>IP allocation "manual": fixed allocation "dhcp": dynamic allocation</th></tr> 79 * <tr class="odd"><th>wifi.dns1</th><th>String</th><th>DNS address assigned to the wireless network interface. </th></tr> 80 * <tr><th>wifi.dns2</th><th>String</th><th>Secondary DNS address assigned to the wireless network interface. </th></tr> 81 * </tbody> 82 * </table> 83 * </div> 84 * 85 * @example 86 * // Javascript code 87 * function getNetworkInformation () { 88 * function successCb(cbObject) { 89 * console.log("cbObject : " + JSON.stringify(cbObject)); 90 * console.log("isInternetConnectionAvailable : " + cbObject.isInternetConnectionAvailable); 91 * console.log("wired.state : " + cbObject.wired.state); 92 * console.log("wired.method : " + cbObject.wired.method); 93 * console.log("wired.ipAddress : " + cbObject.wired.ipAddress); 94 * console.log("wired.netmask : " + cbObject.wired.netmask); 95 * console.log("wired.dns1 : " + cbObject.wired.dns1); 96 * console.log("wired.dns2 : " + cbObject.wired.dns2); 97 * console.log("wifi.state : " + cbObject.wifi.state); 98 * console.log("wifi.method : " + cbObject.wifi.method); 99 * console.log("wifi.ipAddress : " + cbObject.wifi.ipAddress); 100 * console.log("wifi.netmask : " + cbObject.wifi.netmask); 101 * console.log("wifi.dns1 : " + cbObject.wifi.dns1); 102 * console.log("wifi.dns2 : " + cbObject.wifi.dns2); 103 * } 104 * 105 * function failureCb(cbObject) { 106 * var errorCode = cbObject.errorCode; 107 * var errorText = cbObject.errorText; 108 * console.log ("Error Code [" + errorCode + "]: " + errorText); 109 * } 110 * 111 * var deviceInfo = new DeviceInfo(); 112 * deviceInfo.getNetworkInfo(successCb, failureCb); 113 * } 114 * @since 1.0 115 * @see 116 * <a href="DeviceInfo%23getNetworkMacInfo.html">DeviceInfo.getNetworkMacInfo()</a><br>, 117 * <a href="DeviceInfo%23setNetworkInfo.html">DeviceInfo.setNetworkInfo()</a><br> 118 */ 119 DeviceInfo.prototype.getNetworkInfo = function (successCallback, errorCallback) { 120 121 log("getNetworkInfo: "); 122 123 service.Request('luna://com.palm.connectionmanager', { 124 method: 'getstatus', 125 parameters: {}, 126 onSuccess: function(result) { 127 log("getNetworkInfo: onSuccess"); 128 delete result.returnValue; 129 successCallback && successCallback(result); 130 }, 131 onFailure: function(error) { 132 log("getNetworkInfo: onFailure"); 133 delete error.returnValue; 134 errorCallback && errorCallback(error); 135 } 136 }); 137 138 log("DeviceInfo.getNetworkInfo Done"); 139 }; 140 141 /** 142 * Sets network information. Network information includes IP address assigned to wireless / wired LAN, gateway address, netmask and DNS address. 143 * @class DeviceInfo 144 * @param {Function} successCallback success callback function. 145 * @param {Function} errorCallback failure callback function. 146 * @param {Object} options 147 * <div align=left> 148 * <table class="hcap_spec" width=400> 149 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 150 * <tbody> 151 * <tr><th>wired</th><th>Object</th><th>Wired network information object. </th><th>required</th></tr> 152 * <tr class="odd"><th>wired.enabled</th><th>Boolean</th><th>Wired network connection true : enabled false : disabled </th><th>required</th></tr> 153 * <tr><th>wired.method</th><th>String</th><th>IP allocation "manual": fixed allocation "dhcp": dynamic allocation, If DHCP is enabled then ipAddress, gateway, netmask and DNS settings are ignored.</th><th>required</th></tr> 154 * <tr class="odd"><th>wired.ipAddress</th><th>String</th><th>IP address assigned to the wired network interface. </th><th>required</th></tr> 155 * <tr><th>wired.netmask</th><th>String</th><th>Netmask assigned to the wired network interface. </th><th>required</th></tr> 156 * <tr class="odd"><th>wired.gateway</th><th>String</th><th>Gateway address assigned to the wired network interface</th><th>required</th></tr> 157 * <tr><th>wired.dns1</th><th>String</th><th>DNS address assigned to the wired network interface. </th><th>required</th></tr> 158 * <tr class="odd"><th>wired.dns2</th><th>String</th><th>Secondary DNS address assigned to the wired network interface. </th><th>required</th></tr> 159 * <tr><th>wifi</th><th>Object</th><th>Wireless network information object. </th><th>required</th></tr> 160 * <tr class="odd"><th>wifi.method</th><th>String</th><th>IP allocation "manual": fixed allocation "dhcp": dynamic allocation, If DHCP is enabled then ipAddress, gateway, netmask and DNS settings are ignored.</th><th>required</th></tr> 161 * <tr><th>wifi.enabled</th><th>Boolean</th><th>Wireless network connection true : enabled false : disabled </th><th>required</th></tr> 162 * <tr class="odd"><th>wifi.ipAddress</th><th>String</th><th>IP address assigned to the wireless network interface. </th><th>required</th></tr> 163 * <tr><th>wifi.netmask</th><th>String</th><th>Netmask assigned to the wireless network interface. </th><th>required</th></tr> 164 * <tr class="odd"><th>wifi.gateway</th><th>String</th><th>Gateway address assigned to the wireless network interface</th><th>required</th></tr> 165 * <tr><th>wifi.dns1</th><th>String</th><th>DNS address assigned to the wireless network interface. </th><th>required</th></tr> 166 * <tr class="odd"><th>wifi.dns2</th><th>String</th><th>Secondary DNS address assigned to the wireless network interface. </th><th>required</th></tr> 167 * </tbody> 168 * </table> 169 * </div> 170 * 171 * @example 172 * // Javascript code 173 * function setNetworkInformation () { 174 * function successCb() { 175 * console.log("successCb"); 176 * } 177 * 178 * function failureCb(cbObject) { 179 * var errorCode = cbObject.errorCode; 180 * var errorText = cbObject.errorText; 181 * console.log ("Error Code [" + errorCode + "]: " + errorText); 182 * } 183 * 184 * var deviceInfo = new DeviceInfo(); 185 * var wired = { 186 * enabled : true, 187 * method : "manual", 188 * ipAddress : "192.168.0.2", 189 * netmask : "255.255.255.0", 190 * gateway : "192.168.0.1", 191 * dns1 : "156.147.135.180", 192 * dns2 : "156.147.135.181" 193 * }; 194 * var wifi = { 195 * enabled : true, 196 * method : "manual", 197 * ipAddress : "192.168.0.2", 198 * netmask : "255.255.255.0", 199 * gateway : "192.168.0.1", 200 * dns1 : "156.147.135.180", 201 * dns2 : "156.147.135.181" 202 * }; 203 * var options = { 204 * wired : wired, 205 * wifi : wifi 206 * }; 207 * deviceInfo.setNetworkInfo(successCb, failureCb, options); 208 * } 209 * @since 1.3 210 * @see 211 * <a href="DeviceInfo%23getNetworkInfo.html">DeviceInfo.getNetworkInfo()</a><br> 212 */ 213 DeviceInfo.prototype.setNetworkInfo = function (successCallback, errorCallback, options) { 214 215 log("setNetworkInfo: "); 216 217 service.Request('luna://com.webos.service.commercial.signage.storageservice/network/', { 218 method: 'setNetworkInfo', 219 parameters: options, 220 onSuccess: function(result) { 221 log("setNetworkInfo: onSuccess"); 222 delete result.returnValue; 223 successCallback && successCallback(result); 224 }, 225 onFailure: function(error) { 226 log("setNetworkInfo: onFailure"); 227 delete error.returnValue; 228 errorCallback && errorCallback(error); 229 } 230 }); 231 232 log("DeviceInfo.setNetworkInfo Done"); 233 }; 234 235 /** 236 * Gets beacon information. 237 * @class DeviceInfo 238 * @param {Function} successCallback success callback function. 239 * @param {Function} errorCallback failure callback function. 240 * @return {Object} 241 * <div align=left> 242 * <table class="hcap_spec" width=400> 243 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 244 * <tbody> 245 * <tr><th>enabled</th><th>Boolean</th><th>Beacon is enabled true: enabled, false: disabled</th><th>required</th></tr> 246 * <tr class="odd"><th>uuid</th><th>String</th><th>UUID of beacon, 32 hexadecimal digits. Only valid when 'enabled' is true.</th><th>required</th></tr> 247 * <tr><th>major</th><th>Number</th><th>Major number of beacon.(0 ~ 65535) Only valid when 'enabled' is true.</th><th>required</th></tr> 248 * <tr class="odd"><th>minor</th><th>Number</th><th>Minor number of beacon.(0 ~ 65535) Only valid when 'enabled' is true.</th><th>required</th></tr> 249 * </tbody> 250 * </table> 251 * </div> 252 * 253 * @example 254 * // Javascript code 255 * function getBeaconInfo () { 256 * function successCb(cbObject) { 257 * console.log("cbObject : " + JSON.stringify(cbObject)); 258 * console.log("enabled : " + cbObject.enabled); 259 * console.log("uuid : " + cbObject.uuid); 260 * console.log("major : " + cbObject.major); 261 * console.log("minor : " + cbObject.minor); 262 * } 263 * 264 * function failureCb(cbObject) { 265 * var errorCode = cbObject.errorCode; 266 * var errorText = cbObject.errorText; 267 * console.log ("Error Code [" + errorCode + "]: " + errorText); 268 * } 269 * 270 * var deviceInfo = new DeviceInfo(); 271 * deviceInfo.getBeaconInfo(successCb, failureCb); 272 * } 273 * 274 * @since 1.3 275 * @see 276 * <a href="DeviceInfo%23setBeaconInfo.html">DeviceInfo.setBeaconInfo()</a><br>, 277 */ 278 DeviceInfo.prototype.getBeaconInfo = function (successCallback, errorCallback) { 279 280 log("getBeaconInfo: "); 281 282 service.Request("luna://com.webos.service.commercial.signage.storageservice/network/", { 283 method: 'getBeaconInfo', 284 parameters: {}, 285 onSuccess: function(result) { 286 log("getBeaconInfo: onSuccess"); 287 delete result.returnValue; 288 successCallback && successCallback(result); 289 }, 290 onFailure: function(error) { 291 log("getBeaconInfo: onFailure"); 292 delete error.returnValue; 293 errorCallback && errorCallback(error); 294 } 295 }); 296 297 log("DeviceInfo.getBeaconInfo Done"); 298 }; 299 300 301 /** 302 * Sets beacon information. 303 * @class DeviceInfo 304 * @param {Function} successCallback success callback function. 305 * @param {Function} errorCallback failure callback function. 306 * @param {Object} options 307 * <div align=left> 308 * <table class="hcap_spec" width=400> 309 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 310 * <tbody> 311 * <tr><th>enabled</th><th>Boolean</th><th>Beacon is enabled true: enabled, false: disabled</th><th>required</th></tr> 312 * <tr class="odd"><th>uuid</th><th>String</th><th>UUID of beacon, 32 hexadecimal digits. Only valid when 'enabled' is true.</th><th>required</th></tr> 313 * <tr><th>major</th><th>Number</th><th>Major number of beacon.(0 ~ 65535) Only valid when 'enabled' is true.</th><th>required</th></tr> 314 * <tr class="odd"><th>minor</th><th>Number</th><th>Minor number of beacon.(0 ~ 65535) Only valid when 'enabled' is true.</th><th>required</th></tr> 315 * </table> 316 * </div> 317 * 318 * @example 319 * // Javascript code 320 * function setBeaconInfo () { 321 * function successCb() { 322 * console.log("successCb"); 323 * } 324 * 325 * function failureCb(cbObject) { 326 * var errorCode = cbObject.errorCode; 327 * var errorText = cbObject.errorText; 328 * console.log ("Error Code [" + errorCode + "]: " + errorText); 329 * } 330 * 331 * var deviceInfo = new DeviceInfo(); 332 * 333 * var options = { 334 * enabled : true, 335 * uuid : "1A2B3C4D5E1A2B3C4D5E1A2B3C4D5EFF", 336 * major :1234, 337 * minor :4321 338 * }; 339 * 340 * deviceInfo.setBeaconInfo(successCb, failureCb, options); 341 * } 342 * @since 1.3 343 * @see 344 * <a href="DeviceInfo%23getBeaconInfo.html">DeviceInfo.getBeaconInfo()</a><br> 345 */ 346 DeviceInfo.prototype.setBeaconInfo = function (successCallback, errorCallback, options) { 347 348 log("setBeaconInfo: "); 349 350 var regex = function(uuid) { 351 352 if (typeof uuid === "undefined" || uuid === null || uuid.length != 32) { 353 return false; 354 } 355 356 var reg = new RegExp(/^[a-fA-F0-9]*$/g); 357 return reg.exec(uuid) != null ? true : false; 358 359 }; 360 361 if (options.enabled === true && (regex(options.uuid) === false 362 || isNaN(options.major) || options.major < 0 || options.major > 65535 363 || isNaN(options.minor) || options.minor < 0 || options.minor > 65535) ){ 364 365 log("setBeaconInfo: options are invalid."); 366 367 if(errorCallback && typeof errorCallback === 'function') { 368 var result = {}; 369 checkErrorCodeNText(result, "DSBI", "DeviceInfo.setBeaconInfo. Invalid options."); 370 errorCallback(result); 371 } 372 373 return; 374 } 375 376 service.Request('luna://com.webos.service.commercial.signage.storageservice/network/', { 377 method: 'setBeaconInfo', 378 parameters: options, 379 onSuccess: function(result) { 380 log("setBeaconInfo: onSuccess"); 381 delete result.returnValue; 382 successCallback && successCallback(result); 383 }, 384 onFailure: function(error) { 385 log("setBeaconInfo: onFailure"); 386 delete error.returnValue; 387 errorCallback && errorCallback(error); 388 } 389 }); 390 391 log("DeviceInfo.setBeaconInfo Done"); 392 }; 393 394 /** 395 * Gets Soft AP information. 396 * @class DeviceInfo 397 * @param {Function} successCallback success callback function. 398 * @param {Function} errorCallback failure callback function. 399 * @return {Object} 400 * <div align=left> 401 * <table class="hcap_spec" width=400> 402 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 403 * <tbody> 404 * <tr><th>enabled</th><th>Boolean</th><th>Soft AP is enabled true: enabled, false: disabled</th></tr> 405 * <tr class="odd"><th>ssid</th><th>String</th><th>SSID of Soft AP (Maximum length is 32). Only valid when 'enabled' is true.</th></tr> 406 * <tr><th>securityKey</th><th>String</th><th>Security key(6 characters). It is automatically prefixed with "LG". Only valid when 'enabled' is true.</th></tr> 407 * </tbody> 408 * </table> 409 * </div> 410 * 411 * @example 412 * // Javascript code 413 * function getSoftApInfo () { 414 * function successCb(cbObject) { 415 * console.log("cbObject : " + JSON.stringify(cbObject)); 416 * console.log("enabled : " + cbObject.enabled); 417 * console.log("ssid : " + cbObject.ssid); 418 * console.log("securityKey : " + cbObject.securityKey); 419 * } 420 * 421 * function failureCb(cbObject) { 422 * var errorCode = cbObject.errorCode; 423 * var errorText = cbObject.errorText; 424 * console.log ("Error Code [" + errorCode + "]: " + errorText); 425 * } 426 * 427 * var deviceInfo = new DeviceInfo(); 428 * deviceInfo.getSoftApInfo(successCb, failureCb); 429 * } 430 * 431 * @since 1.3 432 * @see 433 * <a href="DeviceInfo%23setSoftApInfo.html">DeviceInfo.setSoftApInfo()</a><br>, 434 */ 435 DeviceInfo.prototype.getSoftApInfo = function (successCallback, errorCallback) { 436 437 log("getSoftApInfo: "); 438 439 service.Request("luna://com.webos.service.commercial.signage.storageservice/network/", { 440 method: 'getSoftApInfo', 441 parameters: {}, 442 onSuccess: function(result) { 443 log("getSoftApInfo: onSuccess"); 444 delete result.returnValue; 445 successCallback && successCallback(result); 446 }, 447 onFailure: function(error) { 448 log("getSoftApInfo: onFailure"); 449 delete error.returnValue; 450 errorCallback && errorCallback(error); 451 } 452 }); 453 454 log("DeviceInfo.getSoftApInfo Done"); 455 }; 456 457 /** 458 * Sets Soft AP information. 459 * @class DeviceInfo 460 * @param {Function} successCallback success callback function. 461 * @param {Function} errorCallback failure callback function. 462 * @param {Object} options 463 * <div align=left> 464 * <table class="hcap_spec" width=400> 465 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 466 * <tbody> 467 * <tr><th>enabled</th><th>Boolean</th><th>Soft AP is enabled true: enabled, false: disabled</th><th>required</th></tr> 468 * <tr class="odd"><th>ssid</th><th>String</th><th>SSID of Soft AP (Maximum length is 32). Only valid when 'enabled' is true.</th><th>required</th></tr> 469 * <tr><th>securityKey</th><th>String</th><th>Security key(6 characters). It is automatically prefixed with "LG". Only valid when 'enabled' is true.</th><th>required</th></tr> 470 * </tbody> 471 * </table> 472 * </div> 473 * 474 * @example 475 * // Javascript code 476 * function setSoftApInfo () { 477 * function successCb(cbObject) { 478 * console.log("cbObject : " + JSON.stringify(cbObject)); 479 * console.log("enabled : " + cbObject.enabled); 480 * console.log("ssid : " + cbObject.ssid); 481 * console.log("securityKey : " + cbObject.securityKey); 482 * } 483 * 484 * function failureCb(cbObject) { 485 * var errorCode = cbObject.errorCode; 486 * var errorText = cbObject.errorText; 487 * console.log ("Error Code [" + errorCode + "]: " + errorText); 488 * } 489 * 490 * var deviceInfo = new DeviceInfo(); 491 * 492 * var options = { 493 * enabled : true, 494 * ssid : "LG SIGNAGE", 495 * securityKey : "404571" 496 * }; 497 * 498 * deviceInfo.setSoftApInfo(successCb, failureCb, options); 499 * } 500 * 501 * @since 1.3 502 * @see 503 * <a href="DeviceInfo%23getSoftApInfo.html">DeviceInfo.getSoftApInfo()</a><br>, 504 */ 505 DeviceInfo.prototype.setSoftApInfo = function (successCallback, errorCallback, options) { 506 507 log("setSoftApInfo: "); 508 509 if ((options.ssid !== null && options.ssid.length > 32) || 510 (options.securityKey != null && options.securityKey.length !== 6)) { 511 512 log("setSoftApInfo: options are invalid."); 513 514 if(errorCallback && typeof errorCallback === 'function') { 515 var result = {}; 516 checkErrorCodeNText(result, "DSSI", "DeviceInfo.setSoftApInfo. Invalid options."); 517 errorCallback(result); 518 } 519 520 return; 521 } 522 523 524 service.Request("luna://com.webos.service.commercial.signage.storageservice/network/", { 525 method: 'setSoftApInfo', 526 parameters: options, 527 onSuccess: function(result) { 528 log("setSoftApInfo: onSuccess"); 529 delete result.returnValue; 530 successCallback && successCallback(result); 531 }, 532 onFailure: function(error) { 533 log("setSoftApInfo: onFailure"); 534 delete error.returnValue; 535 errorCallback && errorCallback(error); 536 } 537 }); 538 539 log("DeviceInfo.setSoftApInfo Done"); 540 }; 541 542 /** 543 * Gets list of detected wifi networks. 544 * @class DeviceInfo 545 * @param {Function} successCallback success callback function. 546 * @param {Function} errorCallback failure callback function. 547 * @return {Object} 548 * <div align=left> 549 * <table class="hcap_spec" width=400> 550 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 551 * <tbody> 552 * <tr><th>networkInfo</th><th>Array</th><th>Array of Wifi network information objects</th></tr> 553 * <tr class="odd"><th>networkInfo.signalLevel</th><th>Number</th><th>Signal level (0 ~ 100)</th></tr> 554 * <tr><th>networkInfo.ssid</th><th>String</th><th>SSID</th></tr> 555 * </tbody> 556 * </table> 557 * </div> 558 * 559 * @example 560 * // Javascript code 561 * function getWifiList () { 562 * function successCb(cbObject) { 563 * 564 * console.log("cbObject : " + JSON.stringify(cbObject)); 565 * 566 * for(var i=0; i < cbObject.networkInfo.length; i++) { 567 * console.log("network info : ssid " + cbObject.networkInfo[i].ssid); 568 * console.log("network info : signalLevel " + cbObject.networkInfo[i].signalLevel); 569 * } 570 * } 571 * 572 * function failureCb(cbObject) { 573 * var errorCode = cbObject.errorCode; 574 * var errorText = cbObject.errorText; 575 * console.log ("Error Code [" + errorCode + "]: " + errorText); 576 * } 577 * 578 * var deviceInfo = new DeviceInfo(); 579 * deviceInfo.getWifiList(successCb, failureCb); 580 * } 581 * @since 1.3 582 * @see 583 * <a href="DeviceInfo%23connectWifi.html">DeviceInfo.connectWifi()</a><br> 584 */ 585 DeviceInfo.prototype.getWifiList = function (successCallback, errorCallback) { 586 587 log("getWifiList: "); 588 589 service.Request('luna://com.webos.service.commercial.signage.storageservice/network/', { 590 method: 'getWifiList', 591 parameters: {}, 592 onSuccess: function(result) { 593 log("getWifiList: onSuccess"); 594 delete result.returnValue; 595 successCallback && successCallback(result); 596 }, 597 onFailure: function(error) { 598 log("getWifiList: onFailure"); 599 delete error.returnValue; 600 errorCallback && errorCallback(error); 601 } 602 }); 603 604 log("DeviceInfo.getWifiList Done"); 605 }; 606 607 /** 608 * Connects wifi network using SSID and password. 609 * @class DeviceInfo 610 * @param {Function} successCallback success callback function. 611 * @param {Function} errorCallback failure callback function. 612 * @param {Object} options 613 * <div align=left> 614 * <table class="hcap_spec" width=400> 615 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 616 * <tbody> 617 * <tr><th>ssid</th><th>String</th><th>SSID (Maximum length is 32)</th><th>required</th></tr> 618 * <tr class="odd"><th>password</th><th>String</th><th>password</th><th>required</th></tr> 619 * <tr><th>hidden</th><th>Boolean</th><th>true : hidden AP. false : open AP(default)</th><th>optional</th></tr> 620 * </tbody> 621 * </table> 622 * </div> 623 * 624 * @example 625 * // Javascript code 626 * function connectWifi () { 627 * function successCb() { 628 * console.log("successCb"); 629 * } 630 * 631 * function failureCb(cbObject) { 632 * var errorCode = cbObject.errorCode; 633 * var errorText = cbObject.errorText; 634 * console.log ("Error Code [" + errorCode + "]: " + errorText); 635 * } 636 * 637 * var deviceInfo = new DeviceInfo(); 638 * 639 * var options = { 640 * ssid : "AP_NAME", 641 * password : "12341234" 642 * }; 643 * 644 * deviceInfo.connectWifi(successCb, failureCb, options); 645 * } 646 * @since 1.3 647 * @see 648 * <a href="DeviceInfo%23getWifiList.html">DeviceInfo.getWifiList()</a><br> 649 */ 650 DeviceInfo.prototype.connectWifi = function (successCallback, errorCallback, options) { 651 652 log("connectWifi: "); 653 654 service.Request('luna://com.webos.service.commercial.signage.storageservice/network/', { 655 method: 'connectWifi', 656 parameters: options, 657 onSuccess: function(result) { 658 log("connectWifi: onSuccess"); 659 delete result.returnValue; 660 successCallback && successCallback(result); 661 }, 662 onFailure: function(error) { 663 log("connectWifi: onFailure"); 664 delete error.returnValue; 665 errorCallback && errorCallback(error); 666 } 667 }); 668 669 log("DeviceInfo.connectWifi Done"); 670 }; 671 672 /** 673 * Starts WPS (Wifi Protected Setup) using PBC (Push Button Configuration) or PIN. 674 * @class DeviceInfo 675 * @param {Function} successCallback success callback function. 676 * @param {Function} errorCallback failure callback function. 677 * @param {Object} options 678 * <div align=left> 679 * <table class="hcap_spec" width=400> 680 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 681 * <tbody> 682 * <tr><th>method</th><th>String</th><th>PBC : Push WPS button on your wireless router after the call with this parameter.<br>PIN : Enter the PIN which is returned with the success callback in your router's setting menu.</th><th>required</th></tr> 683 * </tbody> 684 * </table> 685 * </div> 686 * @return {Object} 687 * <div align=left> 688 * <table class="hcap_spec" width=400> 689 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 690 * <tbody> 691 * <tr><th>pin</th><th>String</th><th>If PIN method is used, this is returned in success callback. </th></tr> 692 * </tbody> 693 * </table> 694 * </div> 695 * 696 * @example 697 * // Javascript code 698 * function startWpsbyPBC () { 699 * function successCb() { 700 * console.log("successCb"); 701 * } 702 * 703 * function failureCb(cbObject) { 704 * var errorCode = cbObject.errorCode; 705 * var errorText = cbObject.errorText; 706 * console.log ("Error Code [" + errorCode + "]: " + errorText); 707 * } 708 * 709 * var deviceInfo = new DeviceInfo(); 710 * 711 * var options = { 712 * method : "PBC" 713 * }; 714 * 715 * deviceInfo.startWps(successCb, failureCb, options); 716 * } 717 * 718 * // Javascript code 719 * function startWpsbyPIN () { 720 * function successCb(cbObject) { 721 * console.log("successCb PIN : " + cbObject.pin); 722 * } 723 * 724 * function failureCb(cbObject) { 725 * var errorCode = cbObject.errorCode; 726 * var errorText = cbObject.errorText; 727 * console.log ("Error Code [" + errorCode + "]: " + errorText); 728 * } 729 * 730 * var deviceInfo = new DeviceInfo(); 731 * 732 * var options = { 733 * method : "PIN" 734 * }; 735 * 736 * deviceInfo.startWps(successCb, failureCb, options); 737 * } 738 * @since 1.3 739 * @see 740 * <a href="DeviceInfo%23stopWps.html">DeviceInfo.stopWps()</a><br> 741 */ 742 DeviceInfo.prototype.startWps = function (successCallback, errorCallback, options) { 743 744 log("startWps: "); 745 746 service.Request('luna://com.webos.service.commercial.signage.storageservice/network/', { 747 method: 'startWps', 748 parameters: options, 749 onSuccess: function(result) { 750 log("startWps: onSuccess"); 751 delete result.returnValue; 752 successCallback && successCallback(result); 753 }, 754 onFailure: function(error) { 755 log("startWps: onFailure"); 756 delete error.returnValue; 757 errorCallback && errorCallback(error); 758 } 759 }); 760 761 log("DeviceInfo.startWps Done"); 762 }; 763 764 /** 765 * Stops WPS (Wifi Protected Setup) operation. 766 * @class DeviceInfo 767 * @param {Function} successCallback success callback function. 768 * @param {Function} errorCallback failure callback function. 769 * 770 * @example 771 * // Javascript code 772 * function stopWps () { 773 * function successCb() { 774 * console.log("successCb"); 775 * } 776 * 777 * function failureCb(cbObject) { 778 * var errorCode = cbObject.errorCode; 779 * var errorText = cbObject.errorText; 780 * console.log ("Error Code [" + errorCode + "]: " + errorText); 781 * } 782 * 783 * var deviceInfo = new DeviceInfo(); 784 * 785 * deviceInfo.stopWps(successCb, failureCb); 786 * } 787 * @since 1.3 788 * @see 789 * <a href="DeviceInfo%23startWps.html">DeviceInfo.startWps()</a><br> 790 */ 791 DeviceInfo.prototype.stopWps = function (successCallback, errorCallback) { 792 793 log("stopWps: "); 794 795 service.Request('luna://com.webos.service.commercial.signage.storageservice/network/', { 796 method: 'stopWps', 797 parameters: {}, 798 onSuccess: function(result) { 799 log("stopWps: onSuccess"); 800 delete result.returnValue; 801 successCallback && successCallback(result); 802 }, 803 onFailure: function(error) { 804 log("stopWPS: onFailure"); 805 delete error.returnValue; 806 errorCallback && errorCallback(error); 807 } 808 }); 809 810 log("DeviceInfo.stopWps Done"); 811 }; 812 813 /** 814 * Gets network MAC information. 815 * @class DeviceInfo 816 * @param {Function} successCallback success callback function. 817 * @param {Function} errorCallback failure callback function. 818 * @return {Object} 819 * <div align=left> 820 * <table class="hcap_spec" width=400> 821 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 822 * <tbody> 823 * <tr><th>wiredInfo</th><th>Object</th><th>An object that has MAC address of the wired network interface. </th></tr> 824 * <tr class="odd"><th>wiredInfo.macAddress</th><th>String</th><th>MAC address of the wired network interface. </th></tr> 825 * <tr><th>wifiInfo</th><th>Object</th><th>An object that has MAC address of the wireless network interface. </th></tr> 826 * <tr class="odd"><th>wifiInfo.macAddress</th><th>String</th><th>MAC address of the wireless network interface. </th></tr> 827 * </tbody> 828 * </table> 829 * </div> 830 * 831 * @example 832 * // Javascript code 833 * function getNetworkMacInformation () { 834 * function successCb(cbObject) { 835 * console.log("cbObject : " + JSON.stringify(cbObject)); 836 * console.log("wiredInfo.macAddress : " + cbObject.wiredInfo.macAddress); 837 * console.log("wifiInfo.macAddress : " + cbObject.wifiInfo.macAddress); 838 * 839 * // Do something 840 * ... 841 * } 842 * 843 * function failureCb(cbObject) { 844 * var errorCode = cbObject.errorCode; 845 * var errorText = cbObject.errorText; 846 * console.log ("Error Code [" + errorCode + "]: " + errorText); 847 * } 848 * 849 * var deviceInfo = new DeviceInfo(); 850 * deviceInfo.getNetworkMacInfo(successCb, failureCb); 851 * } 852 * @since 1.0 853 * @see 854 * <a href="DeviceInfo%23getNetworkInfo.html">DeviceInfo.getNetworkInfo()</a><br> 855 */ 856 DeviceInfo.prototype.getNetworkMacInfo = function (successCallback, errorCallback) { 857 858 log("getNetworkMacInfo: "); 859 860 service.Request('luna://com.webos.service.tv.signage', { 861 method: 'getinfo', 862 parameters: {}, 863 onSuccess: function(result) { 864 log("getNetworkMacInfo: onSuccess"); 865 delete result.returnValue; 866 successCallback && successCallback(result); 867 }, 868 onFailure: function(error) { 869 log("getNetworkMacInfo: onFailure"); 870 delete error.returnValue; 871 errorCallback && errorCallback(error); 872 } 873 }); 874 875 log("DeviceInfo.getNetworkMacInfo Done"); 876 }; 877 878 /** 879 * Gets device platform information. Platform information includes manufacturer, model name, software version, hardware version and product serial number. 880 * @class DeviceInfo 881 * @param {Function} successCallback success callback function. 882 * @param {Function} errorCallback failure callback function. 883 * @return {Object} 884 * <div align=left> 885 * <table class="hcap_spec" width=400> 886 * <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead> 887 * <tbody> 888 * <tr><th>hardwareVersion</th><th>String</th><th>hardware version of signage monitor. </th></tr> 889 * <tr class="odd"><th>manufacturer</th><th>String</th><th>manufacturer of signage monitor. </th></tr> 890 * <tr><th>modelName</th><th>String</th><th>signage monitor model name. </th></tr> 891 * <tr class="odd"><th>sdkVersion</th><th>String</th><th>SDK version of signage monitor. </th></tr> 892 * <tr><th>serialNumber</th><th>String</th><th>signage monitor serial number. </th></tr> 893 * <tr class="odd"><th>firmwareVersion</th><th>String</th><th>firmware version of signage monitor. </th></tr> 894 * </tbody> 895 * </table> 896 * </div> 897 * 898 * @example 899 * // Javascript code 900 * function getPlatformInfo () { 901 * function successCb(cbObject) { 902 * console.log("cbObject : " + JSON.stringify(cbObject)); 903 * console.log("hardwareVersion : " + cbObject.hardwareVersion); 904 * console.log("modelName : " + cbObject.modelName); 905 * console.log("sdkVersion : " + cbObject.sdkVersion); 906 * console.log("serialNumber : " + cbObject.serialNumber); 907 * console.log("firmwareVersion : " + cbObject.firmwareVersion); 908 * 909 * // Do something 910 * ... 911 * } 912 * 913 * function failureCb(cbObject) { 914 * var errorCode = cbObject.errorCode; 915 * var errorText = cbObject.errorText; 916 * console.log ("Error Code [" + errorCode + "]: " + errorText); 917 * } 918 * 919 * var deviceInfo = new DeviceInfo(); 920 * deviceInfo.getPlatformInfo(successCb, failureCb); 921 * } 922 * @since 1.0 923 * @see 924 * <a href="DeviceInfo%23getNetworkMacInfo.html">DeviceInfo.getNetworkMacInfo()</a><br> 925 */ 926 DeviceInfo.prototype.getPlatformInfo = function (successCallback, errorCallback) { 927 928 log("getPlatformInfo: "); 929 930 service.Request('luna://com.webos.service.tv.systemproperty', { 931 method: 'getSystemInfo', 932 parameters: { 933 keys: ["modelName", "serialNumber", "firmwareVersion", "hardwareVersion", "sdkVersion"] 934 }, 935 onSuccess: function(result) { 936 log("getPlatformInfo: onSuccess"); 937 result.manufacturer = "LGE"; 938 result.sdkVersion = "1.3.22083"; 939 delete result.returnValue; 940 delete result.errorText; 941 successCallback && successCallback(result); 942 }, 943 onFailure: function(error) { 944 log("getPlatformInfo: onFailure"); 945 delete error.returnValue; 946 errorCallback && errorCallback(error); 947 } 948 }); 949 950 log("DeviceInfo.getPlatformInfo Done"); 951 }; 952 953 /** 954 * Gets device usage information. Usage information includes cpu and memory status. 955 * @class DeviceInfo 956 * @param {Function} successCallback success callback function. 957 * @param {Function} errorCallback failure callback function. 958 * @param {Object} options 959 * <div align=left> 960 * <table class="hcap_spec" width=400> 961 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead> 962 * <tbody> 963 * <tr><th>cpus</th><th>Boolean</th><th>true to get CPU information, false otherwise.</th><th>optional</th></tr> 964 * <tr class="odd"><th>memory</th><th>Boolean</th><th>true to get memory information, false otherwise.</th><th>optional</th></tr> 965 * </tbody> 966 * </table> 967 * </div> 968 * @return {Object} 969 * <div align=left> 970 * <table class="hcap_spec" width=400> 971 * <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Available</th></tr></thead> 972 * <tbody> 973 * <tr><th>cpus</th><th>Array</th><th>Array of objects containing information about each CPU/core installed: model, and times <br>(an object containing the number of milliseconds the CPU/core spent in: user, nice, sys, idle, and irq).</th><th>optional</th></tr> 974 * <tr class="odd"><tr><th>memory</th><th>Object</th><th>Object containing total and free member fields. <br>'total' is total amount of system memory in bytes and 'free' is amount of free memory in bytes.</th><th>optional</th></tr> 975 * </tbody> 976 * </table> 977 * </div> 978 * 979 * @example 980 * // Javascript code 981 * function getSystemUsageInfo() { 982 * function successCb(cbObject) { 983 * console.log("cbObject : " + JSON.stringify(cbObject)); 984 * console.log("memory.total : " + cbObject.memory.total); 985 * console.log("memory.free : " + cbObject.memory.free); 986 * 987 * for (var i in cbObject.cpus) { 988 * console.log("cpu.model " + cbObject.cpus[i].model); 989 * console.log("cpu.times.user " + cbObject.cpus[i].times.user); 990 * console.log("cpu.times.nice " + cbObject.cpus[i].times.nice); 991 * console.log("cpu.times.sys " + cbObject.cpus[i].times.sys); 992 * console.log("cpu.times.idle " + cbObject.cpus[i].times.idle); 993 * console.log("cpu.times.irq " + cbObject.cpus[i].times.irq); 994 * } 995 * // Do something 996 * } 997 * 998 * function failureCb(cbObject) { 999 * var errorCode = cbObject.errorCode; 1000 * var errorText = cbObject.errorText; 1001 * console.log ("Error Code [" + errorCode + "]: " + errorText); 1002 * } 1003 * 1004 * var deviceInfo = new DeviceInfo(); 1005 * var options = {cpus : true, memory : true}; 1006 * deviceInfo.getSystemUsageInfo(successCb, failureCb, options); 1007 * } 1008 * @since 1.2 1009 * @see 1010 * <a href="DeviceInfo%23getPlatformInfo.html">DeviceInfo.getPlatformInfo()</a><br> 1011 */ 1012 DeviceInfo.prototype.getSystemUsageInfo = function (successCallback, errorCallback, options) { 1013 1014 log("getSystemUsageInfo: "); 1015 1016 service.Request("luna://com.webos.service.commercial.signage.storageservice", { 1017 method : "getSystemUsageInfo", 1018 parameters : { 1019 cpus : options.cpus, 1020 memory : options.memory 1021 }, 1022 onSuccess : function(result) { 1023 if (result.returnValue === true) { 1024 var ret = {}; 1025 if (typeof result.memory !== 'undefined' ) { 1026 ret.memory = result.memory; 1027 } 1028 if (typeof result.cpus !== 'undefined' ) { 1029 ret.cpus = result.cpus; 1030 } 1031 successCallback(ret); 1032 } else { 1033 errorCallback({errorCode:result.errorCode, errorText:result.errorText}); 1034 } 1035 }, 1036 onFailure : function (result) { 1037 errorCallback({errorCode:result.errorCode, errorText:result.errorText}); 1038 } 1039 }); 1040 1041 log("DeviceInfo.getSystemUsageInfo Done"); 1042 }; 1043 1044 1045 module.exports = DeviceInfo; 1046 }); 1047 1048 DeviceInfo = cordova.require('cordova/plugin/deviceInfo'); // jshint ignore:line 1049 1050