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 InputSource API itself, and provides a global namespace for operating InputSource service.
 11  * @class
 12  */
 13 
 14 cordova.define("cordova/plugin/broadcast", function (require, exports, module) {
 15     var service = require("cordova/plugin/webos/service"),
 16         utils = require("cordova/utils"),
 17         argscheck = require("cordova/argscheck"),
 18         broadcast = function (e) {
 19             this.isATSC = false;
 20             this.tokenChannelChange = 0;
 21             this.tokenSignalState = 0;
 22             this.broadcastDivId = null;
 23             this.broadcastElement = null;
 24             this.currentInput = null;
 25             this.currentSource = null;
 26             this.isLastInput = true;
 27             this.isLastChannel = true;
 28             var that = this;
 29             service.Request("luna://com.webos.service.tv.systemproperty", {
 30                 method: "getSystemInfo",
 31                 parameters: {
 32                     keys: ["atsc"]
 33                 },
 34                 onSuccess: function (cbObject) {
 35                     that.isATSC = cbObject.atsc
 36                 },
 37                 onFailure: function (errorObject) { }
 38             });
 39         };
 40     broadcast.prototype.onchannelchange = function (e) { },
 41     broadcast.prototype.onsignalstatuschange = function (e) { },
 42     broadcast.prototype.initialize = function (successCallback, failureCallback, options) {
 43         argscheck.checkArgs("fFo", "broadcastCordova.initialize", arguments);
 44         var clone_options = utils.clone(options);
 45         this.broadcastDivId = document.getElementById(clone_options.divId);
 46         clone_options.broadcastPlugin = this;
 47         if (1 != clone_options.isLastInput && clone_options.src) {
 48             this.isLastInput = false
 49             if (-1 != clone_options.src.indexOf("tv://")) { 
 50                 if (1 == clone_options.isLastChannel) {
 51                     this.isLastChannel = true;
 52                     clone_options.type = "service/webos-broadcast";
 53                 }
 54                 else {
 55                     this.isLastChannel = false;
 56                     clone_options.type = "service/webos-broadcast-standalone"   
 57                 }
 58                 this.currentInput = "tv";
 59                 this.currentSource = clone_options.src.substr(5);
 60             }
 61             else {
 62                 clone_options.type = "service/webos-external";
 63                 var source_split = clone_options.src.split(":");
 64                 this.currentInput = source_split[1].substr(2).toLowerCase();
 65                 this.currentSource = source_split[2]
 66             }
 67             createNewExternalSignalVideoArea(clone_options);
 68             successCallback && successCallback()
 69         } else {
 70             this.isLastInput = true;
 71             getCurrentInput(successCallback, failureCallback, clone_options)
 72         }
 73     },
 74     broadcast.prototype.channelUp = function (successCallback, failureCallback) {
 75         argscheck.checkArgs("fF", "broadcastCordova.channelUp", arguments);
 76         var param = {
 77             broadcastId: this.broadcastElement.mediaId
 78         };
 79         service.Request("luna://com.webos.service.tv.broadcast", {
 80             method: "changeChannelUp",
 81             parameters: param,
 82             onSuccess: function (cbObject) {
 83                 successCallback && successCallback()
 84             },
 85             onFailure: function (errorObject) {
 86                 delete errorObject.returnValue;
 87                 failureCallback && failureCallback(errorObject);
 88             }
 89         })
 90     },
 91     
 92     broadcast.prototype.channelDown = function (successCallback, failureCallback) {
 93         argscheck.checkArgs("fF", "broadcastCordova.channelDown", arguments);
 94         var param = {
 95             broadcastId: this.broadcastElement.mediaId
 96         };
 97         service.Request("luna://com.webos.service.tv.broadcast", {
 98             method: "changeChannelDown",
 99             parameters: param,
100             onSuccess: function (cbObject) {
101                 successCallback && successCallback()
102             },
103             onFailure: function (errorObject) {
104                 delete errorObject.returnValue;
105                 failureCallback && failureCallback(errorObject)
106             }
107         })
108     },
109     
110     broadcast.prototype.setChannel = function (successCallback, failureCallback, options) {
111         argscheck.checkArgs("fFo", "broadcastCordova.setChannel", arguments);
112         var param = {
113             broadcastId: this.broadcastElement.mediaId,
114             channelId: options.id
115         };
116         service.Request("luna://com.webos.service.tv.broadcast", {
117             method: "changeChannel",
118             parameters: param,
119             onSuccess: function (cbObject) {
120                 successCallback && successCallback()
121             },
122             onFailure: function (errorObject) {
123                 delete errorObject.returnValue;
124                 failureCallback && failureCallback(errorObject)
125             }
126         })
127     },
128     
129     broadcast.prototype.getCurrentChannel = function (successCallback, failureCallback) {
130         argscheck.checkArgs("fF", "broadcastCordova.getCurrentChannel", arguments);
131         var param = {
132             broadcastId: this.broadcastElement.mediaId,
133             subscribe: false
134         };
135         service.Request("luna://com.webos.service.tv.broadcast", {
136             method: "getCurrentChannel",
137             parameters: param,
138             onSuccess: function (cbObject) {
139                 var returnObject = {};
140                 returnObject = S(cbObject.channel, "api");
141                 successCallback && successCallback(returnObject);
142             },
143             onFailure: function (errorObject) {
144                 delete errorObject.returnValue;
145                 failureCallback && failureCallback(errorObject);
146             }
147         })
148     },
149     
150     broadcast.prototype.getSignalStatus = function (successCallback, failureCallback) {
151         argscheck.checkArgs("fF", "broadcastCordova.getSignalStatus", arguments);
152         var param;
153         if ("tv" == this.currentInput) {
154             param = {
155                 broadcastId: this.broadcastElement.mediaId,
156                 subscribe: false
157             };
158             service.Request("luna://com.webos.service.tv.broadcast", {
159                 method: "getChannelState",
160                 parameters: param,
161                 onSuccess: function (cbObject) {
162                     var returnObject = cbObject.channelState;
163                     returnObject.screensaverType = returnObject.channelScreensaverType;
164                     delete returnObject.channelScreensaverType;
165                     successCallback && successCallback(returnObject)
166                 },
167                 onFailure: function (errorObject) {
168                     delete errorObject.returnValue;
169                     failureCallback && failureCallback(errorObject)
170                 }
171             })
172         }
173         else {
174             param = {
175                 externalInputId: this.broadcastElement.mediaId,
176                 subscribe: false
177             };
178             service.Request("luna://com.webos.service.tv.externaldevice/input/", {
179                 method: "getSignalState",
180                 parameters: param,
181                 onSuccess: function (cbObject) {
182                     successCallback && successCallback(cbObject.signalState)
183                 },
184                 onFailure: function (errorObject) {
185                     delete errorObject.returnValue;
186                     failureCallback && failureCallback(errorObject)
187                 }
188             })
189         }
190     },
191     
192     broadcast.prototype.getCurrentProgram = function (successCallback, failureCallback, options) {
193         argscheck.checkArgs("fFo", "broadcastCordova.getCurrentProgram", arguments), service.Request("luna://com.palm.systemservice/time", {
194             method: "getEffectiveBroadcastTime",
195             parameters: {},
196             onSuccess: function (cbObject) {
197                 var returnObject = {};
198                 returnObject.id = options.id;
199                 returnObject.startTime = cbObject.localtime;
200                 returnObject.endTime = cbObject.localtime;
201                 returnObject.request = "nowInfo";
202                 getSignalChannelId(successCallback, failureCallback, returnObject)
203             },
204             onFailure: function (e) {
205                 delete e.returnValue, failureCallback && failureCallback(e)
206             }
207         })
208     },
209     
210     broadcast.prototype.getNextProgram = function (successCallback, failureCallback, options) {
211         argscheck.checkArgs("fFo", "broadcastCordova.getNextProgram", arguments), service.Request("luna://com.palm.systemservice/time", {
212             method: "getEffectiveBroadcastTime",
213             parameters: {},
214             onSuccess: function (r) {
215                 var a = {};
216                 a.id = options.id, a.startTime = r.localtime, a.endTime = r.localtime, a.request = "nextInfo", getSignalChannelId(successCallback, failureCallback, a)
217             },
218             onFailure: function (e) {
219                 delete e.returnValue, failureCallback && failureCallback(e)
220             }
221         })
222     },
223     
224     broadcast.prototype.getProgramCount = function (successCallback, failureCallback, options) {
225         argscheck.checkArgs("fFo", "broadcastCordova.getProgramCount", arguments);
226         var r = utils.clone(options);
227         r.request = "count";
228         getSignalChannelId(successCallback, failureCallback, r)
229     },
230     
231     broadcast.prototype.getProgramList = function (successCallback, failureCallback, options) {
232         argscheck.checkArgs("fFo", "broadcastCordova.getProgramList", arguments);
233         var r = utils.clone(options);
234         r.request = "list";
235         getSignalChannelId(successCallback, failureCallback, r)
236     },
237     
238     broadcast.prototype.getChannelCount = function (successCallback, failureCallback, options) {
239         argscheck.checkArgs("fFo", "broadcastCordova.getChannelCount", arguments);
240         var param = {
241             from: "com.webos.service.tv.channel.dblist:1",
242             select: [""],
243             where: [{
244                 prop: "channelType",
245                 op: "=",
246                 val: options.type
247             }],
248             filter: [{
249                 prop: "Invisible",
250                 op: "=",
251                 val: !1
252             }]
253         };
254         service.Request("luna://com.palm.db/", {
255             method: "search",
256             parameters: {
257                 query: param
258             },
259             onSuccess: function (cbObject) {
260                 var returnObject = {};
261                 returnObject.count = cbObject.results.length;
262                 successCallback && successCallback(returnObject)
263             },
264             onFailure: function (error) {
265                 delete error.returnValue, failureCallback && failureCallback(error)
266             }
267         })
268     }, broadcast.prototype.getChannelList = function (successCallback, failureCallback, options) {
269         argscheck.checkArgs("fFo", "broadcastCordova.getChannelList", arguments);
270         var a = options.startIndex - 1;
271         if (0 > a)
272             a = 0;
273         var c = a + options.count,
274             param = {
275                 from: "com.webos.service.tv.channel.dblist:1",
276                 select: ["channelId", "channelName", "channelMode", "channelNumber", "channelType", "skipped", "locked", "descrambled", "scrambled"],
277                 where: [{
278                     prop: "channelType",
279                     op: "=",
280                     val: options.type
281                 }],
282                 filter: [{
283                     prop: "Invisible",
284                     op: "=",
285                     val: !1
286                 }],
287                 limit: c
288             };
289         service.Request("luna://com.palm.db/", {
290             method: "search",
291             parameters: {
292                 query: param
293             },
294             onSuccess: function (cbObject) {
295                 var returnObject = {};
296                 returnObject.channel = [];
297                 var r = cbObject.results.length - a;
298                 if (r > 0) {
299                     for (var o = 0; r > o; o++)
300                         returnObject.channel[o] = S(cbObject.results[o + a], "db8");
301                 }
302                 successCallback && successCallback(returnObject)
303             },
304             onFailure: function (error) {
305                 delete error.returnValue;
306                 failureCallback && failureCallback(error)
307             }
308         })
309     }, broadcast.prototype.getChannelListByName = function (successCallback, failureCallback, optioins) {
310         argscheck.checkArgs("fFo", "broadcastCordova.getChannelListByName", arguments);
311         var param = {
312             from: "com.webos.service.tv.channel.dblist:1",
313             select: ["channelId", "channelName", "channelMode", "channelNumber", "channelType", "skipped", "locked", "descrambled", "scrambled"],
314             where: [{
315                 prop: "channelName",
316                 op: "%",
317                 val: optioins.name
318             }],
319             filter: [{
320                 prop: "Invisible",
321                 op: "=",
322                 val: false
323             }]
324         };
325         optioins.type && param.filter.push({
326             prop: "channelType",
327             op: "=",
328             val: optioins.type
329         }), service.Request("luna://com.palm.db/", {
330             method: "search",
331             parameters: {
332                 query: param
333             },
334             onSuccess: function (cbObject) {
335                 var returnObject = {};
336                 if (returnObject.channel = [], cbObject.results.length > 0) {
337                     for (var r = 0; r < cbObject.results.length; r++)
338                         returnObject.channel[r] = S(cbObject.results[r], "db8");
339                 }
340                 successCallback && successCallback(returnObject)
341             },
342             onFailure: function (errorObject) {
343                 delete errorObject.returnValue;
344                 failureCallback && failureCallback(errorObject)
345             }
346         })
347     }, 
348     
349     broadcast.prototype.setInput = function (inputSourceSrc) {
350         argscheck.checkArgs("o", "broadcastCordova.setInput", arguments);
351         var isSourceIsChanged = false;
352         if (-1 != inputSourceSrc.src.indexOf("tv://"))  {
353             if (1 == this.isLastChannel)
354                 inputSourceSrc.type = "service/webos-broadcast"
355             else 
356                 inputSourceSrc.type = "service/webos-broadcast-standalone";
357             this.currentInput = "tv";
358             this.currentSource = inputSourceSrc.src.substr(5);
359         }
360         else {
361             inputSourceSrc.type = "service/webos-external";
362             var inputSourceSrcSplit = inputSourceSrc.src.split(":");
363             this.currentInput = inputSourceSrcSplit[1].substr(2).toLowerCase();
364             this.currentSource = inputSourceSrcSplit[2]
365         }
366         for (var childNodesCount = 0; childNodesCount < this.broadcastElement.childNodes.length; childNodesCount++) {
367             if ("SOURCE" == this.broadcastElement.childNodes[childNodesCount].nodeName) {
368                 this.broadcastElement.childNodes[childNodesCount].src = inputSourceSrc.src;
369                 this.broadcastElement.childNodes[childNodesCount].type = inputSourceSrc.type;
370                 this.broadcastElement.load();
371                 isSourceIsChanged = true;
372             }
373         }
374         return isSourceIsChanged;
375     },
376     
377     broadcast.prototype.addEventListener = function (eventListenerName, callback, options) {
378         if ("channelchange" == eventListenerName) {
379             this.tokenChannelChange = service.Request("luna://com.webos.service.tv.broadcast", {
380                 method: "getCurrentChannel",
381                 parameters: {
382                     broadcastId: this.broadcastElement.mediaId,
383                     subscribe: false
384                 },
385                 onSuccess: function (cbObject) {
386                     var returnValue = cbObject.channel;
387                     callback && callback(returnValue)
388                 },
389                 onFailure: function (errorObject) { }
390             })
391         }
392         else if ("signalstatus" == eventListenerName) {
393             if ("tv" == this.currentInput) {
394                 this.tokenSignalState = service.Request("luna://com.webos.service.tv.broadcast", {
395                     method: "getChannelState",
396                     parameters: {
397                         broadcastId: this.broadcastElement.mediaId,
398                         subscribe: false
399                     },
400                     onSuccess: function (cbObject) {
401                         var returnObject = cbObject.channelState;
402                         returnObject.screensaverType = returnObject.channelScreensaverType;
403                         delete returnObject.channelScreensaverType;
404                         callback && callback(returnObject);
405                     },
406                     onFailure: function (errorObject) { }
407                 });
408             } 
409             else {
410                 this.tokenSignalState = service.Request("luna://com.webos.service.tv.externaldevice/input/", {
411                     method: "getSignalState",
412                     parameters: {
413                         externalInputId: this.broadcastElement.mediaId,
414                         subscribe: true
415                     },
416                     onSuccess: function (cbObject) {
417                         var returnObject = cbObject.signalState;
418                         callback && callback(returnObject);
419                     },
420                     onFailure: function (errorObject) { }
421                 });
422             }
423         }
424     };
425     var loadedmetadataEventHandler = function (broadcastPlugin, callback) {
426             h(broadcastPlugin);
427             if ("tv" == broadcastPlugin.currentInput) {
428                 getCurrentChannel(broadcastPlugin);
429                 getChannelState(broadcastPlugin);
430             }
431             else {
432                 getSignalState(broadcastPlugin);
433                 callback();
434             } 
435         },
436         createNewExternalSignalVideoArea = function (options) {
437             var newVideoElement = document.createElement("VIDEO");
438             newVideoElement.setAttribute("id", options.videoId);
439             newVideoElement.setAttribute("width", "100%");
440             newVideoElement.setAttribute("height", "100%");
441             newVideoElement.setAttribute("autoplay", "");
442             newVideoElement.addEventListener("loadedmetadata", function () {
443                 loadedmetadataEventHandler(options.broadcastPlugin, options.callback)
444             }, false);
445             var newSourceElement = document.createElement("SOURCE");
446             newSourceElement.setAttribute("src", options.src);
447             newSourceElement.setAttribute("type", options.type);
448             newVideoElement.appendChild(newSourceElement);
449             options.broadcastPlugin.broadcastDivId.appendChild(newVideoElement);
450             options.broadcastPlugin.broadcastElement = newVideoElement;
451         },
452         getCurrentInput = function (successCallback, errorCallback, options) {
453             service.Request("luna://com.webos.service.eim", {
454                 method: "getCurrentInput",
455                 parameters: {},
456                 onSuccess: function (cbObject) {
457                     if ("ATV" == cbObject.mainInputSourceId || "DTV" == cbObject.mainInputSourceId) {
458                         options.broadcastPlugin.currentInput = "tv";
459                         l(successCallback, errorCallback, options);
460                     }
461                     else {
462                         var mainInputSourceId_SplitArr = cbObject.mainInputSourceId.split("_");
463                         options.broadcastPlugin.currentInput = mainInputSourceId_SplitArr[0].toLowerCase();
464                         options.broadcastPlugin.currentSource = mainInputSourceId_SplitArr[1];
465                         options.src = "ext://" + options.broadcastPlugin.currentInput + ":" + options.broadcastPlugin.currentSource;
466                         options.type = "service/webos-external";
467                         createNewExternalSignalVideoArea(options);
468                         successCallback && successCallback();
469                     }
470                 },
471                 onFailure: function (errorObject) {
472                     delete errorObject.returnValue;
473                     errorCallback && errorCallback(errorObject);
474                 }
475             })
476         },
477         l = function (e, t, n) { },
478         getCurrentChannel = function (e) {
479             e.tokenChannelChange = service.Request("luna://com.webos.service.tv.broadcast", {
480                 method: "getCurrentChannel",
481                 parameters: {
482                     broadcastId: e.broadcastElement.mediaId,
483                     subscribe: true
484                 },
485                 onSuccess: function (t) {
486                     e.currentSource = t.channel.channelId;
487                     var n = {};
488                     n = S(t.channel, "api"), e.onchannelchange(n)
489                 },
490                 onFailure: function (e) { }
491             })
492         },
493         getChannelState = function (e) {
494             e.tokenSignalState = service.Request("luna://com.webos.service.tv.broadcast", {
495                 method: "getChannelState",
496                 parameters: {
497                     broadcastId: e.broadcastElement.mediaId,
498                     subscribe: true
499                 },
500                 onSuccess: function (cbObject) {
501                     var returnObject = cbObject.channelState;
502                     returnObject.screensaverType = returnObject.channelScreensaverType;
503                     delete returnObject.channelScreensaverType;
504                     e.onsignalstatuschange(returnObject);
505                 },
506                 onFailure: function (errorObject) { }
507             })
508         },
509         getSignalState = function (e) {
510             e.tokenSignalState = service.Request("luna://com.webos.service.tv.externaldevice/input/", {
511                 method: "getSignalState",
512                 parameters: {
513                     externalInputId: e.broadcastElement.mediaId,
514                     subscribe: true
515                 },
516                 onSuccess: function (cbObject) {
517                     var n = cbObject.signalState;
518                     e.onsignalstatuschange(n)
519                 },
520                 onFailure: function (errorObject) { }
521             })
522         },
523         h = function (e) {
524             if (e.tokenChannelChange)
525                 e.tokenChannelChange.cancel();
526             if (e.tokenSignalState)
527                 e.tokenSignalState.cancel()
528         },
529         v = function (successCallback, failureCallback, options) {
530             var startTime = getFormattedDate(options.startTime),
531                 endTime = getFormattedDate(options.endTime),
532                 o = {};
533             if ("count" == options.request) {
534                 o = {
535                     from: "com.webos.service.tv.programSCH:4",
536                     select: [""],
537                     where: [{
538                         prop: "signalChannelId",
539                         op: "=",
540                         val: options.signalChannelId
541                     }],
542                     filter: [{
543                         prop: "localStartTime",
544                         op: "<=",
545                         val: endTime
546                     }, {
547                             prop: "localEndTime",
548                             op: ">=",
549                             val: startTime
550                         }]
551                  }
552             }
553             else if ("nextInfo" == options.request) { 
554                 o = {
555                     from: "com.webos.service.tv.programSCH:4",
556                     select: ["programId", "eventId", "localStartTime", "localEndTime", "duration", "programName", "description"],
557                     where: [{
558                         prop: "channelId",
559                         op: "=",
560                         val: options.signalChannelId
561                     }],
562                     filter: [{
563                         prop: "localStartTime",
564                         op: ">",
565                         val: startTime
566                     }],
567                     orderBy: "localStartTime",
568                     limit: 1
569                 }
570             } 
571             else if ("list" == options.request || "nowInfo" == options.request) {
572                 o = {
573                     from: "com.webos.service.tv.programSCH:4",
574                     select: ["programId", "eventId", "localStartTime", "localEndTime", "duration", "programName", "description"],
575                     where: [{
576                         prop: "channelId",
577                         op: "=",
578                         val: options.signalChannelId
579                     }],
580                     filter: [
581                         {
582                             prop: "localStartTime",
583                             op: "<=",
584                             val: endTime
585                         },
586                         {
587                             prop: "localEndTime",
588                             op: ">=",
589                             val: startTime
590                         }
591                     ]
592                 }
593             }
594         },
595         getSignalChannelId = function (successCallback, errorCallback, options) {
596             var DBQuery = {
597                 from: "com.webos.service.tv.channel.dblist:1",
598                 select: ["signalChannelId"],
599                 where: [{
600                     prop: "channelId",
601                     op: "=",
602                     val: options.id
603                 }]
604             };
605             service.Request("luna://com.palm.db/", {
606                 method: "find",
607                 parameters: {
608                     query: DBQuery
609                 },
610                 onSuccess: function (cbObject) {
611                     options.signalChannelId = cbObject.results[0].signalChannelId;
612                     v(successCallback, errorCallback, options);
613                 },
614                 onFailure: function (errorObject) {
615                     delete errorObject.returnValue;
616                     errorCallback && errorCallback(errorObject);
617                 }
618             })
619         },
620         S = function (e, t) {
621             var returnObject = {};
622             returnObject.id = e.channelId;
623             returnObject.number = e.channelNumber;
624             returnObject.name = e.channelName;
625             if ("api" == t) {
626                 returnObject.mode = e.channelModeName;
627                 returnObject.type = e.channelTypeName;
628                 returnObject.isSkipped = e.isSkipped;
629                 returnObject.isLocked = e.isLocked;
630                 returnObject.isDescrambled = e.isDescrambled;
631                 returnObject.isScrambled = e.isScrambled;
632             } 
633             else {
634                 returnObject.mode = e.channelMode;
635                 returnObject.type = e.channelType;
636                 returnObject.isSkipped = e.skipped;
637                 returnObject.isLocked = e.locked;
638                 returnObject.isDescrambled = e.descrambled;
639                 returnObject.isScrambled = e.scrambled
640             }
641             return returnObject;
642         },
643         getFormattedDate = function (dateValue) {
644             var formattedDate = dateValue.year + ",";
645             formattedDate += (dateValue.month < 10 ? "0" : "") + dateValue.month + ",";
646             formattedDate += (dateValue.day < 10 ? "0" : "") + dateValue.day + ",";
647             formattedDate += (dateValue.hour < 10 ? "0" : "") + dateValue.hour + ",";
648             formattedDate += (dateValue.minute < 10 ? "0" : "") + dateValue.minute + ",";
649             formattedDate += (dateValue.second < 10 ? "0" : "") + dateValue.second;
650             return formattedDate;
651         };
652     module.exports = broadcast
653 });
654 var Broadcast = cordova.require("cordova/plugin/broadcast");
655 /**
656  * End of add cordova broadcast
657  */
658 
659 cordova.define('cordova/plugin/inputSource', function (require, exports, module) { // jshint ignore:line
660     
661     function log(msg) {
662     //    //console.log//will be removed // jshint ignore:line
663     }
664     
665     var service;
666     if (window.PalmSystem) { // jshint ignore:line
667         log("Window.PalmSystem Available");
668         service = require('cordova/plugin/webos/service'); 
669     } else {
670         service = {
671             Request : function(uri, params) {
672                 log(uri + " invoked. But I am a dummy because PalmSystem is not available");
673                         
674                 if (typeof params.onFailure === 'function') {
675                     params.onFailure({
676                         returnValue:false,
677                         errorText:"PalmSystem Not Available. Cordova is not installed?"
678                     });
679                }
680         }};
681     }
682 
683     /**
684      * inputSource interface
685      */
686     var InputSource = function () {
687     };
688     
689     var isInitialized = false;
690     var inputSourceVideoID = '';
691     
692     var broadcast = null;
693     
694     function checkErrorCodeNText(result, errorCode, errorText) {
695         
696         if (result.errorCode === undefined || result.errorCode === null ) {
697             result.errorCode = errorCode;
698         }
699         if (result.errorText ===undefined || result.errorText === null) {
700             result.errorText = errorText;
701         }
702     }
703     
704     /**
705      * Imports video tag to show the input source dynamically. This is used to embed input source in an html page.
706      *  
707      * @class InputSource
708      * @param {Function} successCallback success callback function.
709      * @param {Function} errorCallback failure callback function.
710      * @param {Object} options
711      * <div align=left>
712      * <table class="hcap_spec" width=400>
713      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
714      *   <tbody>
715      *       <tr><th>divId</th><th>String</th><th>Div tag ID with the video tag in it. </th><th>required</th></tr>
716      *       <tr class="odd"><th>videoId</th><th>String</th><th>The ID of the video tag to be dynamically created. </th><th>required</th></tr>
717      *       <tr><th>callback</th><th>Function</th><th>An event handler (onloadedmetadata) that is called when the video tag is created. </th><th>required</th></tr>
718      *       <tr class="odd"><th>src</th><th>String</th><th>The src attribute of the video tag. ext://[externalInput]:[portNum]. (eg: "ext://hdmi:1") </th><th>required</th></tr>
719      *   </tbody>
720      * </table>
721      * @return <p>None.</p>
722      * @example
723      * // HTML code
724      *  < body onload="onLoad()" >
725      *     < div id = "videoDiv" style="width:640px; height:380px" >
726      *     < /div >
727      *  < /body >
728      *
729      * // Javascript code
730      * function init () {
731      * }
732      * 
733      * function onLoad() {
734      *   var options = {
735      *      divId : "videoDiv", // It should be matched to div tag name in an html page.
736      *      videoId : "broadcastvideo",
737      *      callback : init,
738      *      src : "ext://hdmi:1"
739      *   };   
740      *     
741      *   function successCb() {
742      *      // Do something
743      *   }
744      *
745      *   function failureCb(cbObject) {
746      *      var errorCode = cbObject.errorCode;
747      *      var errorText = cbObject.errorText;
748      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
749      *   }
750      *   
751      *   var inputSource = new InputSource();
752      *   inputSource.initialize(successCb, failureCb, options);
753      * }
754      * @since 1.0
755      * @since 1.1 options.isLastChannel removed
756      */
757     InputSource.prototype.initialize = function (successCallback, errorCallback, options) {
758     
759         log("initialize: " + JSON.stringify(options));
760         
761         // bound check
762         if (options.divId === undefined || typeof options.divId !== 'string' || options.divId === null || options.divId.length <= 0 ||
763             options.videoId === undefined || typeof options.videoId !== 'string' || options.videoId === null || options.videoId.length <= 0 ||
764             options.callback === undefined || typeof options.callback !== 'function' ||
765             options.src === undefined || typeof options.src !== 'string' || options.src === null || options.src.length <= 0 ) {
766             
767             if (typeof errorCallback === 'function') {
768                 var result = {};
769                 checkErrorCodeNText(result, "II", "InputSource.initialize returns failure. invalid parameters.");
770                 errorCallback(result);
771             }
772             
773             return;
774         }
775         
776         if (document.getElementById(options.divId) === null || document.getElementById(options.divId) === undefined) {
777             if (typeof errorCallback === 'function') {
778                 errorCallback({
779                     errorCode : "II",
780                     errorText : "options.divId:[" + options.divId + "] element not exists or cannot approach"
781                 });
782             }
783             return;
784         }
785         else if (document.getElementById(options.videoId)) {
786             if (typeof errorCallback === 'function') {
787                 errorCallback({
788                     errorCode : "II",
789                     errorText : "options.videoId:[" + options.videoId + "] element already exists."
790                 });
791             }
792             return;
793         }
794         /**
795          * End of add exceptions
796          */
797         
798         convertInputSource(options.src,
799             function success(inputSource) {
800                 // success callback
801                 var tmpOpts        = {};                
802                 tmpOpts.divId      = options.divId;
803                 tmpOpts.videoId    = options.videoId;
804                 tmpOpts.callback   = options.callback;
805                 tmpOpts.src        = inputSource;
806                 broadcast          = new Broadcast(); // jshint ignore:line
807                 broadcast.initialize(successCallback, errorCallback, tmpOpts);
808                 isInitialized      = true;
809                 inputSourceVideoID = options.videoId;
810             },
811             function failure(cbObj) {
812                 // failure callback
813                 log("initialize: failure " + JSON.stringify(cbObj));
814                 
815                 if (typeof errorCallback === 'function') {
816                     var result = {};
817                     checkErrorCodeNText(result, "II", "InputSource.initialize returns failure. invalid parameters.");
818                     errorCallback(result);
819                 }
820             }
821         );
822         
823         log("initialize: Done");
824     };
825 
826     /**
827      * Changes the input source that viewer is currently watching. This method is used to change to other input source after initializing the inputSource object (creating video tag. etc.) using InputSource.initialize() method.
828      * Available input types and number of input sources for each input types may differ model by model. <br>
829      * For example, LS55A model has the following inputs : (HDMI1, HDMI2, DP, DVI) or SM5B model has the following inputs : (HDMI1, DP, DVI, RGB, OPS)
830      * @class InputSource
831      * @param {Function} successCallback success callback function.
832      * @param {Function} errorCallback failure callback function.
833      * @param {Object} options
834      * <div align=left>
835      * <table class="hcap_spec" width=400>
836      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th><th>Required</th></tr></thead>
837      *   <tbody>
838      *       <tr><th>src</th><th>String</th><th>Define the src attribute of video tag. "ext://[externalinput]:[portNum]" (eg, "ext://dp:1")</a> </th><th>required</th></tr>
839      *   </tbody>
840      * </table>
841      * </div>
842      * @return <p>If the method is successfully executed, success callback function is called without a parameter.</br>
843      * If an error occurs, failure callback function is called with failure callback object as a parameter.</p>
844      * @example
845      * // Javascript code
846      * function changeInputSource () {
847      *   var options = {
848      *      src : "ext://hdmi:1"
849      *   };
850      *
851      *   function successCb() {
852      *      // Do something
853      *   }
854      *
855      *   function failureCb(cbObject) {
856      *      var errorCode = cbObject.errorCode;
857      *      var errorText = cbObject.errorText;
858      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
859      *   }
860      *
861      *   var inputSource = new InputSource();
862      *   inputSource.changeInputSource(successCb, failureCb, options);
863      * }
864      * @since 1.0
865      * @see <a href="InputSource%23getInputSourceStatus.html">InputSource.getInputSourceStatus()</a><br>
866      */
867     InputSource.prototype.changeInputSource = function (successCallback, errorCallback, options) {
868     
869         // bound check
870         if ( options.src === undefined || typeof options.src !== 'string' || options.src === null || options.src.length <= 0) {
871             
872             if (typeof errorCallback === 'function') {
873                 var result = {};
874                 checkErrorCodeNText(result, "ICIS", "InputSource.changeInputSource returns failure. invalid argument.");
875                 errorCallback(result);
876             }            
877             return;
878         }
879                 
880         if ((isInitialized === false) || (document.getElementById(inputSourceVideoID) === null || document.getElementById(inputSourceVideoID) === undefined)) {
881             if (typeof errorCallback === 'function') {
882                 var result = {};
883                 checkErrorCodeNText(result, "ICIS", "InputSource.changeInputSource returns failure. Call initialize() first.");
884                 errorCallback(result);
885             }
886             return;
887         }
888         
889         //TODO; deprecated changeInput in broadcast.js 
890         
891         log("changeInputSource: " + JSON.stringify(options));
892         
893         convertInputSource(options.src, function success (inputSource) {
894             // success callback            
895             var tmpOpts      = {};                            
896             tmpOpts.divId    = options.divId;
897             tmpOpts.videoId  = options.videoId;
898             tmpOpts.callback = options.callback;
899             tmpOpts.src      = inputSource;
900 
901             if (broadcast.setInput(tmpOpts)) {
902                 log("changeInputSource: On Success");
903                 if (typeof successCallback === 'function') {
904                     successCallback();
905                 }
906             } else {
907                 if (typeof errorCallback === 'function') {
908                     var result = {};
909                     log("changeInputSource: On Failure");
910                     checkErrorCodeNText(result, "ICIS", "InputSource.changeInputSource returns failure.");
911                     errorCallback(result);
912                 }
913             }
914             
915         }, function failure(cbObj) {
916             // failure callback
917             log("changeInputSource: failure " + JSON.stringify(cbObj));
918             
919             if (typeof errorCallback === 'function') {
920                 var result = {};
921                 checkErrorCodeNText(result, "ICIS", "InputSource.changeInputSource returns failure. invalid argument. ");
922                 errorCallback(result);
923             }
924         });
925         
926         log("changeInputSource: Done");
927     };
928     
929     /**
930      * Gets current input source status. 
931      * @class InputSource
932      * @param {Function} successCallback success callback function.
933      * @param {Function} errorCallback failure callback function.
934      * @return {Object} array of inputSource object, signal state and current input source.
935      * <div align=left>
936      * <table class="hcap_spec" width=400>
937      *   <thead><tr><th>Property</th><th>Type</th><th>Description</th></tr></thead>
938      *   <tbody>
939      *       <tr><th>inputSourceList[]</th><th>Array</th><th>An array with input source object.</th></tr>
940      *       <tr class="odd"><th>inputSourceList[].inputPort</th><th>String</th><th>Input label (ext://hdmi:1, ext://hdmi:2, ext://dp:1, ext://dvi:1 etc) </th></tr>
941      *       <tr><th>currentSignalState</th><th>String</th><th>Status and change information of the input that is currently selected.<br>"good" : good signal, "bad" : poor signal, "unknown" : can't indicate a signal status </th></tr>
942      *       <tr class="odd"><th>currentInputSource</th><th>String</th><th>Input source that the viewer is currently watching.<br>input label </th></tr>       
943      *   </tbody>
944      * </table>
945      * </div>
946      * 
947      * @example
948      * // Javascript code
949      * function getInputSourceStatus () {
950      *   function successCb(cbObject) {
951      *      var inputSourceList = cbObject.inputSourceList;
952      *      for ( var i = 0; i < inputSourceList.length; i++) {
953      *         console.log("inputSourceList[" + i + "] : " + JSON.stringify(inputSourceList[i]));
954      *         console.log("inputSourceList[" + i + "].inputPort : " + inputSourceList[i].inputPort);
955      *      }
956      *      console.log("currentInputSource : " + cbObject.currentInputSource);
957      *      console.log("currentSignalState : " + cbObject.currentSignalState);
958      *      // Do something
959      *   }
960      *
961      *   function failureCb(cbObject) {
962      *      var errorCode = cbObject.errorCode;
963      *      var errorText = cbObject.errorText;
964      *      console.log ("Error Code [" + errorCode + "]: " + errorText);
965      *   }
966      *
967      *   var inputSource = new InputSource();
968      *   inputSource.getInputSourceStatus(successCb, failureCb);
969      * }
970      * @since 1.0
971      * @see <a href="InputSource%23changeInputSource.html">InputSource.changeInputSource()</a><br>
972      */
973     InputSource.prototype.getInputSourceStatus = function (successCallback, errorCallback) {
974     
975         log("getInputSourceStatus: ");
976     
977         service.Request("luna://com.webos.service.eim/", {
978             method : "getAllInputStatus",
979             onSuccess : function(result) {
980                 log("getInputSourceStatus: On Success");
981 
982                 if (result.returnValue === true) {                        
983                     checkPlatformVersion(function(platformInfo){
984                         
985                         var ver = platformInfo.webOSVer;
986                         
987                         log("convertInputSource: " + JSON.stringify(result.totalCount));
988                         log("convertInputSource: " + JSON.stringify(result.devices));
989                         log("version: " + ver);
990                         
991                         var cbObj = {};
992                         var inputList = new Array(result.totalCount);
993                         var convertList = new Array(result.totalCount);
994                         
995                         for (var i=0; i<inputList.length; i++) {
996                             inputList[i] = {};
997                             inputList[i].inputPort = parseInputSource(result.devices[i].label);
998                             
999                             var tempInputSource = null;
1000                             switch (ver) {
1001                                 case 1 : 
1002                                     // fixed input for hdmi:3, hdmi:4. requested by youngjun.lee
1003                                     tempInputSource = result.devices[i].id.split("_");
1004                                     inputList[i].inputPort = 'ext://' + tempInputSource[0].toLowerCase() + ':' + tempInputSource[1];
1005                                     if (inputList[i].inputPort === 'ext://hdmi:3') {
1006                                         inputList[i].inputPort = 'ext://dp:1';
1007                                     } else if (inputList[i].inputPort === 'ext://hdmi:4') {
1008                                         inputList[i].inputPort = 'ext://dvi:1';
1009                                     }
1010                                     // end
1011                                     break;
1012                                 case 2 : 
1013                                     tempInputSource = result.devices[i].id.split("_");
1014                                     inputList[i].inputPort = 'ext://' + tempInputSource[0].toLowerCase() + ':' + tempInputSource[1];
1015                                     if (platformInfo.chipset === 'H15') {
1016                                         if (inputList[i].inputPort === 'ext://dvi:4') {
1017                                             inputList[i].inputPort = 'ext://hdmi:3';
1018                                         }
1019                                         if (inputList[i].inputPort === 'ext://ops:1') {
1020                                             inputList[i].inputPort = 'ext://hdmi:3';
1021                                         }
1022                                         if (inputList[i].inputPort === 'ext://hdmi:4') {
1023                                             inputList[i].inputPort = 'ext://dp:1';
1024                                         }
1025                                     }
1026                                     else {
1027                                         if (inputList[i].inputPort === 'ext://hdmi:3') {
1028                                             inputList[i].inputPort = 'ext://dp:1';
1029                                         } else if (inputList[i].inputPort === 'ext://hdmi:2') {
1030                                             inputList[i].inputPort = 'ext://dvi:1';
1031                                         } else if (inputList[i].inputPort === 'ext://hdmi:4') {
1032                                             inputList[i].inputPort = 'ext://ops:1';
1033                                         }
1034                                     }
1035 
1036                                     break;
1037                                 case 3 : 
1038                                 default :
1039                                     var deviceName = result.devices[i].deviceName.toLowerCase();
1040                                     var port = 1;                                    
1041                                     if (isNaN(deviceName.substring(deviceName.length - 1, deviceName.length)) === false) //number
1042                                     {
1043                                         deviceName = deviceName.substring(0, deviceName.length - 1);
1044                                         port = result.devices[i].id.split("_")[1];
1045                                     }
1046 
1047                                     if(deviceName.toLowerCase() === "displayport")
1048                                         deviceName = "dp";
1049                                     else if(deviceName.toLowerCase() === "ops/dvi")
1050                                         deviceName = "ops";
1051 
1052                                     inputList[i].inputPort = 'ext://' + deviceName.toLowerCase() + ':' + port;              
1053                                     
1054                                     break;
1055                             }
1056                             
1057                             convertList[i] = {};
1058                             convertList[i].inputPort = inputList[i].inputPort;
1059                             convertList[i].id = result.devices[i].id;
1060                         }
1061                         
1062                         cbObj.inputSourceList = inputList;
1063                     
1064                         service.Request("luna://com.webos.service.eim/", {
1065                             method : "getCurrentInput",
1066                             parameters : {},
1067                             onSuccess : function(result) {
1068                                 log("InputSource.getInputSourceStatus: On Success 3");
1069                                 
1070                                 if (result.returnValue === true) {
1071                                     
1072                                     if (typeof successCallback === 'function') {
1073                                         
1074                                         cbObj.currentInputSource = {};
1075                                         
1076                                         for (var i=0; i<convertList.length; i++) {
1077                                             if (convertList[i].id === result.mainInputSourceId) {
1078                                                 cbObj.currentInputSource = convertList[i].inputPort;
1079                                                 break;
1080                                             }
1081                                         }
1082                                         
1083                                         cbObj.currentSignalState = "unknown";
1084                                         
1085                                         if (broadcast !== null) {
1086                                             log("InputSource.getInputSourceStatus : broadcast is not null");
1087                                             
1088                                             broadcast.getSignalStatus(function successCb(cbObject) {
1089                                                 
1090                                                 cbObj.currentSignalState = cbObject.videoSignalState;
1091                                                 log("InputSource.getInputSourceStatus: On Success 2");
1092 
1093                                                 if (typeof successCallback === 'function') {
1094                                                     log("getInputSourceStatus: On Success" + JSON.stringify(cbObj));
1095                                                     successCallback(cbObj);
1096                                                     return;
1097                                                 }
1098                                                 
1099                                             }, function failureCb() {
1100                                                 
1101                                                 log("InputSource.getInputSourceStatus : signal state is fail.");
1102                                                 if (typeof successCallback === 'function') {
1103                                                     log("getInputSourceStatus: On Success" + JSON.stringify(cbObj));
1104                                                     successCallback(cbObj);
1105                                                     return;
1106                                                 }
1107                                             });
1108                                             
1109                                         } else {
1110                                             
1111                                             log("InputSource.getInputSourceStatus : it does not initialize.");
1112                                             if (typeof successCallback === 'function') {
1113                                                 log("getInputSourceStatus: On Success" + JSON.stringify(cbObj));
1114                                                 successCallback(cbObj);
1115                                                 return;
1116                                             }
1117                                         }
1118                                     }
1119                                 }
1120                             },
1121                             onFailure : function(result) {
1122                                 log("InputSource.getInputSourceStatus: On Failure 2");
1123                                 delete result.returnValue;
1124                                 if (typeof errorCallback === 'function') {
1125                                     checkErrorCodeNText(result, "IGISS", "InputSource.getInputSourceStatus returns failure.");
1126                                     errorCallback(result);
1127                                     return;
1128                                 }
1129                             }
1130                         });
1131                     }); // check version
1132                 } // if (result.returnValue === true) {
1133             },
1134             onFailure : function(result) {
1135                 log("getInputSourceStatus: On Failure");
1136                 delete result.returnValue;
1137                 if (typeof errorCallback === 'function') {
1138                     checkErrorCodeNText(result, "IGISS", "InputSource.changeInputSource returns failure on gathering input list.");
1139                     errorCallback(result);
1140                 }
1141             }
1142         });
1143                 
1144     log("InputSource.getInputSourceStatus Done");
1145     
1146     };
1147     
1148     function parseInputSource(str) {
1149         
1150         var index = 1;
1151         var length = str.length;
1152         
1153         if (!isNaN(parseInt(str.charAt(length-1), 10))) {
1154             // has number
1155             index = str.charAt(length-1);
1156             length--;
1157         }
1158         
1159         str = str.substring(0, length) +":"+ index;
1160         str = "ext://" + str.toLowerCase();
1161         
1162         return str;
1163     }
1164         
1165     var version = null;
1166     var platformInfoObj = {}; 
1167     function checkPlatformVersion(cb) {
1168 
1169         if (version === null) {
1170 
1171             service.Request('luna://com.webos.service.tv.systemproperty', {
1172                 method: 'getSystemInfo',
1173                 parameters: {
1174                     keys: ["sdkVersion", "boardType"]
1175                 },
1176                 onSuccess: function(result) {
1177                     log("getPlatformInfo: onSuccess");
1178                     log("version : " + result.sdkVersion);
1179 
1180                     var temp = result.sdkVersion.split('.');
1181                     if (temp.length >= 1 && temp[0] === '1') {
1182                         platformInfoObj = {
1183                             webOSVer: 1,
1184                             chipset: result.boardType.split("_")[0]
1185                         };
1186                     } else if (temp.length >= 1 && temp[0] === '2') {
1187                         platformInfoObj = {
1188                             webOSVer: 2,
1189                             chipset: result.boardType.split("_")[0]
1190                         };
1191                     } else if (temp.length >= 1 && temp[0] === '3') {
1192                         platformInfoObj = {
1193                             webOSVer: 3,
1194                             chipset: result.boardType.split("_")[0]
1195                         };
1196                     } else {
1197                         platformInfoObj = {
1198                             webOSVer: 0,
1199                             chipset: ""
1200                         };
1201                     }
1202                     version = platformInfoObj.webOSVer;
1203                     cb(platformInfoObj);
1204                 },
1205                 onFailure: function(error) {
1206                     log("getPlatformInfo: onFailure");
1207                     platformInfoObj = {
1208                         webOSVer: 0,
1209                         chipset: ""
1210                     }
1211                     cb(platformInfoObj);
1212                 }
1213             });
1214 
1215         } else {
1216             cb(platformInfoObj);
1217         }
1218     }
1219 
1220     function convertInputSource(inputSource, successCallback, errorCallback) {
1221 
1222         var convertedDeviceName = inputSource.toUpperCase().substring(6).split(":")[0];
1223 
1224         if(convertedDeviceName === "DP")
1225             convertedDeviceName = "DISPLAYPORT";
1226 
1227         service.Request("luna://com.webos.service.eim/", {
1228             method : "getAllInputStatus",
1229             onSuccess : function(result) {
1230                 log("convertInputSource: On Success " + inputSource);
1231 
1232                 if (result.returnValue === true) {
1233                     if (typeof successCallback === 'function') {
1234 						var inputList = new Array(result.totalCount);
1235                         checkPlatformVersion(function(platformInfo){
1236                             var ver = platformInfo.webOSVer;                            
1237                             log("convertInputSource: " + JSON.stringify(result.devices));
1238                             log("version: " + ver);
1239 
1240                             if(ver >= 3) //webos3.0
1241                             {
1242                                 for (var i = 0; i < result.devices.length; i++) {
1243                                     var inputSourceParam = inputSource.substring(6).split(":"); //hdmi:1
1244                                     var deviceName = result.devices[i].deviceName;
1245                                     var port = '1';                                    
1246 
1247                                     //1. removed number
1248                                     if (isNaN(deviceName.substring(deviceName.length - 1, deviceName.length)) === false) //if devicename's last char is number
1249                                     {
1250                                         port = deviceName.substring(deviceName.length - 1, deviceName.length);
1251                                         deviceName = deviceName.substring(0, deviceName.length - 1); //removed port
1252                                     }
1253 
1254                                     //2. converted "display"  to "dp"
1255                                     if (deviceName.toLowerCase() === 'displayport')
1256                                         deviceName = 'dp';
1257 
1258                                     //3. check devicename and port are same                                    
1259                                     if (deviceName.toLowerCase().indexOf(inputSourceParam[0].toLowerCase()) >= 0 && port === inputSourceParam[1]) {
1260                                         var tempInputSource = result.devices[i].id.split("_");
1261                                         convertedInput      = "ext://" + tempInputSource[0].toLowerCase() + ":" + tempInputSource[1];
1262 
1263                                         successCallback(convertedInput); 
1264                                         return;
1265                                     }
1266                                 }
1267 
1268                                 log("convertInputSource: On Failure " + inputSource);
1269                                 var errResult = {};
1270                                 checkErrorCodeNText(errResult, "IGISS", "convertInputSource. It does not support inputsource type.");
1271                                 errorCallback(errResult);
1272                             }
1273                             else //webos2.0, 1.0
1274                             {
1275                                 
1276                                 switch (ver) {
1277                                     case 1:
1278                                         // fixed input for hdmi:3, hdmi:4. requested by youngjun.lee
1279                                         if (inputSource === 'ext://dp:1') {
1280                                             inputSource = 'ext://hdmi:3';
1281                                         } else if (inputSource === 'ext://dvi:1') {
1282                                             inputSource = 'ext://hdmi:4';
1283                                         }
1284                                         // end
1285                                         break;
1286                                     case 2:                                        
1287                                         if (platformInfoObj.chipset === 'H15') {
1288                                             if (inputSource === 'ext://dvi:1') {
1289                                                 inputSource = 'ext://hdmi:3';
1290                                             } else if (inputSource === 'ext://ops:1') {
1291                                                 inputSource = 'ext://hdmi:3';
1292                                             }                                            
1293                                             else if (inputSource === 'ext://dp:1') {
1294                                                 inputSource = 'ext://hdmi:3';
1295                                             } else if (inputSource === 'ext://hdmi:4') {
1296                                                 inputSource = 'ext://dp:1';
1297                                             }
1298                                         } else {
1299                                             if (inputSource === 'ext://dp:1') {
1300                                                 inputSource = 'ext://hdmi:3';
1301                                             } else if (inputSource === 'ext://dvi:1') {
1302                                                 inputSource = 'ext://hdmi:2';
1303                                             } else if (inputSource === 'ext://ops:1') {
1304                                                 inputSource = 'ext://hdmi:4';
1305                                             }
1306                                         }
1307                                         break;
1308                                     case 3:
1309                                         if (inputSource === 'ext://dp:1') {
1310                                             inputSource = 'ext://hdmi:3';
1311                                         } else if (inputSource === 'ext://dvi:1') {
1312                                             inputSource = 'ext://hdmi:2';
1313                                         } else if (inputSource === 'ext://ops:1') {
1314                                             inputSource = 'ext://hdmi:4';
1315                                         }
1316 
1317                                         break;
1318                                     default:
1319                                         break;
1320                                 }
1321 
1322                                 for (var i=0; i<inputList.length; i++) {
1323                                     inputList[i] = {};
1324 
1325                                     if (platformInfoObj.chipset === 'H15')
1326                                         inputList[i].inputPort = parseInputSource(result.devices[i].deviceName);
1327                                     else
1328                                         inputList[i].inputPort = parseInputSource(result.devices[i].label);
1329                                     var tempInputSource = result.devices[i].id.split("_");
1330                                     inputList[i].id = 'ext://' + tempInputSource[0].toLowerCase() + ':' + tempInputSource[1];
1331                                     
1332                                     if (inputSource === inputList[i].id) {
1333                                         // ok
1334                                         log("convertInputSource: On Success ok " + inputSource);
1335                                         successCallback(inputSource);
1336                                         return;
1337                                     }
1338                                 }
1339                                 
1340                                 for (var j=0; j<inputList.length; j++) {
1341                                     if (inputSource === inputList[j].inputPort) {
1342                                         // convert source
1343                                         inputSource = inputList[j].id;
1344                                         log("convertInputSource: On Success converted " + inputSource);
1345                                         successCallback(inputSource);
1346                                         return;
1347                                     }
1348                                 }
1349                                 
1350                                 log("convertInputSource: On Failure " + inputSource);
1351                                 var errResult = {};
1352                                 checkErrorCodeNText(errResult, "IGISS", "convertInputSource. It does not support inputsource type.");
1353                                 errorCallback(errResult);                        
1354                             }    
1355                         });                        
1356                     }
1357                 }
1358             },
1359             onFailure : function(result) {
1360                 log("convertInputSource: On Failure");
1361                 delete result.returnValue;
1362                 if (typeof errorCallback === 'function') {
1363                     checkErrorCodeNText(result, "IGISS", "convertInputSource returns failure on gathering input list.");
1364                     errorCallback(result);
1365                 }
1366             }
1367         });
1368     
1369         
1370     }
1371 
1372     module.exports = InputSource;
1373 });
1374 
1375 InputSource = cordova.require('cordova/plugin/inputSource'); // jshint ignore:line