text: var $jscomp=$jscomp||{};$jscomp.scope={};$jscomp.findInternal=function(d,a,b){d instanceof String&&(d=String(d));for(var c=d.length,e=0;e<c;e++){var f=d[e];if(a.call(b,f,e,d))return{i:e,v:f}}return{i:-1,v:void 0}};$jscomp.ASSUME_ES5=!1;$jscomp.ASSUME_NO_NATIVE_MAP=!1;$jscomp.ASSUME_NO_NATIVE_SET=!1;$jscomp.SIMPLE_FROUND_POLYFILL=!1;$jscomp.ISOLATE_POLYFILLS=!1;$jscomp.FORCE_POLYFILL_PROMISE=!1;$jscomp.FORCE_POLYFILL_PROMISE_WHEN_NO_UNHANDLED_REJECTION=!1;
  $jscomp.defineProperty=$jscomp.ASSUME_ES5||"function"==typeof Object.defineProperties?Object.defineProperty:function(d,a,b){if(d==Array.prototype||d==Object.prototype)return d;d[a]=b.value;return d};$jscomp.getGlobal=function(d){d=["object"==typeof globalThis&&globalThis,d,"object"==typeof window&&window,"object"==typeof self&&self,"object"==typeof global&&global];for(var a=0;a<d.length;++a){var b=d[a];if(b&&b.Math==Math)return b}throw Error("Cannot find global object");};$jscomp.global=$jscomp.getGlobal(this);
  $jscomp.IS_SYMBOL_NATIVE="function"===typeof Symbol&&"symbol"===typeof Symbol("x");$jscomp.TRUST_ES6_POLYFILLS=!$jscomp.ISOLATE_POLYFILLS||$jscomp.IS_SYMBOL_NATIVE;$jscomp.polyfills={};$jscomp.propertyToPolyfillSymbol={};$jscomp.POLYFILL_PREFIX="$jscp$";var $jscomp$lookupPolyfilledValue=function(d,a){var b=$jscomp.propertyToPolyfillSymbol[a];if(null==b)return d[a];b=d[b];return void 0!==b?b:d[a]};
  $jscomp.polyfill=function(d,a,b,c){a&&($jscomp.ISOLATE_POLYFILLS?$jscomp.polyfillIsolated(d,a,b,c):$jscomp.polyfillUnisolated(d,a,b,c))};$jscomp.polyfillUnisolated=function(d,a,b,c){b=$jscomp.global;d=d.split(".");for(c=0;c<d.length-1;c++){var e=d[c];if(!(e in b))return;b=b[e]}d=d[d.length-1];c=b[d];a=a(c);a!=c&&null!=a&&$jscomp.defineProperty(b,d,{configurable:!0,writable:!0,value:a})};
  $jscomp.polyfillIsolated=function(d,a,b,c){var e=d.split(".");d=1===e.length;c=e[0];c=!d&&c in $jscomp.polyfills?$jscomp.polyfills:$jscomp.global;for(var f=0;f<e.length-1;f++){var k=e[f];if(!(k in c))return;c=c[k]}e=e[e.length-1];b=$jscomp.IS_SYMBOL_NATIVE&&"es6"===b?c[e]:null;a=a(b);null!=a&&(d?$jscomp.defineProperty($jscomp.polyfills,e,{configurable:!0,writable:!0,value:a}):a!==b&&(void 0===$jscomp.propertyToPolyfillSymbol[e]&&($jscomp.propertyToPolyfillSymbol[e]=$jscomp.IS_SYMBOL_NATIVE?$jscomp.global.Symbol(e):
  $jscomp.POLYFILL_PREFIX+e),$jscomp.defineProperty(c,$jscomp.propertyToPolyfillSymbol[e],{configurable:!0,writable:!0,value:a})))};$jscomp.polyfill("Array.prototype.find",function(d){return d?d:function(a,b){return $jscomp.findInternal(this,a,b).v}},"es6","es3");$jscomp.arrayIteratorImpl=function(d){var a=0;return function(){return a<d.length?{done:!1,value:d[a++]}:{done:!0}}};$jscomp.arrayIterator=function(d){return{next:$jscomp.arrayIteratorImpl(d)}};$jscomp.initSymbol=function(){};
  $jscomp.polyfill("Symbol",function(d){if(d)return d;var a=function(e,f){this.$jscomp$symbol$id_=e;$jscomp.defineProperty(this,"description",{configurable:!0,writable:!0,value:f})};a.prototype.toString=function(){return this.$jscomp$symbol$id_};var b=0,c=function(e){if(this instanceof c)throw new TypeError("Symbol is not a constructor");return new a("jscomp_symbol_"+(e||"")+"_"+b++,e)};return c},"es6","es3");
  $jscomp.polyfill("Symbol.iterator",function(d){if(d)return d;d=Symbol("Symbol.iterator");for(var a="Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array".split(" "),b=0;b<a.length;b++){var c=$jscomp.global[a[b]];"function"===typeof c&&"function"!=typeof c.prototype[d]&&$jscomp.defineProperty(c.prototype,d,{configurable:!0,writable:!0,value:function(){return $jscomp.iteratorPrototype($jscomp.arrayIteratorImpl(this))}})}return d},"es6",
  "es3");$jscomp.iteratorPrototype=function(d){d={next:d};d[Symbol.iterator]=function(){return this};return d};$jscomp.iteratorFromArray=function(d,a){d instanceof String&&(d+="");var b=0,c=!1,e={next:function(){if(!c&&b<d.length){var f=b++;return{value:a(f,d[f]),done:!1}}c=!0;return{done:!0,value:void 0}}};e[Symbol.iterator]=function(){return e};return e};$jscomp.polyfill("Array.prototype.keys",function(d){return d?d:function(){return $jscomp.iteratorFromArray(this,function(a){return a})}},"es6","es3");
  var xnm=xnm||{};xnm.aio=xnm.aio||{};xnm.aio.ip=xnm.aio.ip||{};
  xnm.aio.ip.Http=function(){var d=function(a,b){this._options=a;this._deviceInfo=b};d.prototype.executeCommandCreator=function(a,b,c){this.executeCommand(b.value,function(e){c&&c(e)})};d.prototype.executeCommand=function(a,b){if(a)if(this._options&&this._options.ip){var c=this._getPort();if(c){var e=this._getMethod();if(e){var f=this._buildControlUrl(a);if(f){var k=this._buildPostData(a);a=this._buildHttpHeader(a);this._doRequest({host:this._options.ip,port:c,path:f,method:e,username:this._options.username,
  password:this._options.password,headers:a},k,function(l,h){b&&b(l,h)})}else b&&b(Error("build control url error"))}else b&&b(Error("build method error"))}else b&&b(Error("build port error"))}else b&&b(Error("ip is empty"));else b&&b(Error("command is empty"))};d.prototype._getPort=function(){if(this._options&&this._options.port&&0<this._options.port)return this._options.port;if(!this._deviceInfo||!this._deviceInfo.controlport)return 0;var a=parseInt(this._deviceInfo.controlport);return 0>=a?0:a};
  d.prototype._getMethod=function(){return this._deviceInfo?this._deviceInfo.controlpostdata?"POST":this._deviceInfo.controlurl?"GET":null:null};d.prototype._buildControlUrl=function(a){if(!this._deviceInfo||!this._deviceInfo.controlurl)return null;var b=xnm.aio.ip.Util._decodeXml(this._deviceInfo.controlurl);a=this._getCommandCode(a);if(!a)return null;a=xnm.aio.ip.Util._decodeXml(a);return b.replace("%@",a)};d.prototype._buildPostData=function(a){if(!this._deviceInfo||!this._deviceInfo.controlpostdata)return null;
  var b=xnm.aio.ip.Util._decodeXml(this._deviceInfo.controlpostdata);a=this._getCommandCode(a);if(!a)return null;a=xnm.aio.ip.Util._decodeXml(a);return b.replace("%@",a)};d.prototype._buildHttpHeader=function(a){if(!this._deviceInfo||!this._deviceInfo.httpheader)return{"Content-Type":'text/plain; charset="utf-8"',Connection:"close"};a={};var b=xnm.aio.ip.Util._decodeXml(this._deviceInfo.httpheader).split("|");if(b&&0<b.length)for(var c=0;c<b.length;c++){var e=b[c].trim();if(e){var f=e.indexOf(":");
  if(-1!=f){var k=e.substr(0,f);e=e.substr(f+1);k&&(a[k]=e)}}}return a};d.prototype._getCommandCode=function(a){if(!a||!this._deviceInfo||!this._deviceInfo.keys)return null;for(var b=0;b<this._deviceInfo.keys.length;b++){var c=this._deviceInfo.keys[b];if(c.id&&c.id==a)return c.code}return null};d.prototype._doRequest=function(a,b,c){var e={host:a.host,port:a.port,path:a.path,method:a.method,headers:a.headers};a.username&&(a.password||(a.password=""),e.user=a.username,e.password=a.password,e.headers.Authorization=
  "Basic "+(new Buffer(a.username+":"+a.password)).toString("base64"));b&&(e.headers["Content-Length"]=b.length);a=require("http").request(e,function(f){f.setEncoding("utf-8");var k="";f.on("data",function(l){k+=l});f.on("end",function(){var l;200!=f.statusCode&&(l=Error("http response:"+f.statusCode));c&&c(l,k)})});if(a.on)a.on("error",function(f){c&&c(f)});b&&a.write(b);a.end()};return d}();
  xnm.aio.ip.Tcp=function(){var d=function(a,b){this._options=a;this._deviceInfo=b;this._logger=require("x.logger.js").getLogger("xnm.aio.ip.Tcp")};d.prototype.executeCommandCreator=function(a,b,c){this.executeCommand(b.value,function(e){c&&c(e)})};d.prototype.executeCommand=function(a,b){if(a)if(this._options&&this._options.ip)if(this._getPort())if(a=this._buildTcpData(a)){var c="utf8";switch(this._deviceInfo.tcptype){case "text":case "textnl":case "pioneer":c="utf8";break;case "binary":c="binary",
  a=new Buffer(a)}this._doRequest(a,c,function(e){setTimeout(function(){b&&b(e)},150)})}else b&&b(Error("build data return null"));else b&&b(Error("build port error"));else b&&b(Error("ip is empty"));else b&&b(Error("command is empty"))};d.prototype._getPort=function(){if(this._options&&this._options.port&&0<this._options.port)return this._options.port;if(!this._deviceInfo||!this._deviceInfo.controlport)return 0;var a=parseInt(this._deviceInfo.controlport);return 0>=a?0:a};d.prototype._buildTcpData=
  function(a){if(!this._deviceInfo||!this._deviceInfo.tcptype)return null;a=this._getCommandCode(a);if(!a)return null;a=xnm.aio.ip.Util._decodeXml(a);switch(this._deviceInfo.tcptype){case "text":return a;case "textnl":case "pioneer":return a+"\r";case "binary":return xnm.aio.ip.Util._hex2arr(a);default:return null}};d.prototype._getCommandCode=function(a){if(!a||!this._deviceInfo||!this._deviceInfo.keys)return null;for(var b=0;b<this._deviceInfo.keys.length;b++){var c=this._deviceInfo.keys[b];if(c.id&&
  c.id==a)return c.code}return null};d.prototype._doRequest=function(a,b,c){var e=this,f={port:this._options.port,host:this._options.ip},k=!1,l=!1,h=c,g=require("net").connect(f);g.setTimeout(1E3);b&&"binary"!=b&&g.setEncoding(b);this._logger.log("trace","try to connect tcp to:"+e._options.ip);g.on("connect",function(){e._logger.log("trace","tcp connected to:"+e._options.ip);e._logger.log("trace","write data:"+a.toString());k=!0;g.write(a,b);l=!0});g.on("data",function(m){e._logger.log("trace","receive from tcp:"+
  e._options.ip+" data:"+m);l&&g.end()});g.on("error",function(m){k?(e._logger.log("trace","tcp:"+e._options.ip+" error:"+m.message),g.end()):e._logger.log("trace","tcp:"+e._options.ip+" connection error:"+m.message);h&&(h(m),h=null)});g.on("timeout",function(){k?(e._logger.log("trace","tcp:"+e._options.ip+" data timeout"),g.end(),h&&(h(),h=null)):(e._logger.log("trace","tcp:"+e._options.ip+" connection timeout"),g.end(),h&&(h(Error("connection timeout")),h=null))});g.on("close",function(){e._logger.log("trace",
  "tcp:"+e._options.ip+" close socket");h&&(h(),h=null)});g._doConnect&&"function"==typeof g._doConnect&&g._doConnect()};return d}();
  xnm.aio.ip.Udp=function(){var d=function(a,b){this._options=a;this._deviceInfo=b;this._logger=require("x.logger.js").getLogger("xnm.aio.ip.Udp")};d.prototype.executeCommandCreator=function(a,b,c){this.executeCommand(b.value,function(e){c&&c(e)})};d.prototype.executeCommand=function(a,b){a?this._options&&this._options.ip?this._getPort()?(a=this._buildUdpData(a))?this._doRequest(new Buffer(a),function(c){b&&b(c)}):b&&b(Error("build data return null")):b&&b(Error("build port error")):b&&b(Error("ip is empty")):
  b&&b(Error("command is empty"))};d.prototype._getPort=function(){if(this._options&&this._options.port&&0<this._options.port)return this._options.port;if(!this._deviceInfo||!this._deviceInfo.controlport)return 0;var a=parseInt(this._deviceInfo.controlport);return 0>=a?0:a};d.prototype._buildUdpData=function(a){if(!this._deviceInfo||!this._deviceInfo.udptype)return null;a=this._getCommandCode(a);if(!a)return null;a=xnm.aio.ip.Util._decodeXml(a);switch(this._deviceInfo.udptype){case "text":return a;
  case "textnl":return a+"\r";case "binary":return xnm.aio.ip.Util._hex2arr(a);default:return null}};d.prototype._getCommandCode=function(a){if(!a||!this._deviceInfo||!this._deviceInfo.keys)return null;for(var b=0;b<this._deviceInfo.keys.length;b++){var c=this._deviceInfo.keys[b];if(c.id&&c.id==a)return c.code}return null};d.prototype._doRequest=function(a,b){var c=require("dgram").createSocket("udp4");c.send(a,0,a.length,this._options.port,this._options.ip,function(e){c.close();b&&b(e)})};return d}();
  xnm.aio.ip._Proxy=function(){var d=function(a,b){this._options=a;this._deviceInfo=b;this._logger=require("x.logger.js").getLogger("xnm.aio.ip._Proxy")};d.prototype.executeCommandCreator=function(a,b,c){this.executeCommand(b.value,function(e){c&&c(e)})};d.prototype.executeCommand=function(a,b){a?this._options&&this._options.ip?this._getPort()?(a=this._buildData(a))?this._doRequest(a,function(c){b&&b(c)}):b&&b(Error("build data return null")):b&&b(Error("build port error")):b&&b(Error("ip is empty")):
  b&&b(Error("command is empty"))};d.prototype._getPort=function(){if(this._options&&this._options.port&&0<this._options.port)return this._options.port;if(!this._deviceInfo||!this._deviceInfo.controlport)return 0;var a=parseInt(this._deviceInfo.controlport);return 0>=a?0:a};d.prototype._buildData=function(a){return this._deviceInfo?(a=this._getCommandCode(a))?xnm.aio.ip.Util._decodeXml(a):null:null};d.prototype._getCommandCode=function(a){if(!a||!this._deviceInfo||!this._deviceInfo.keys)return null;
  for(var b=0;b<this._deviceInfo.keys.length;b++){var c=this._deviceInfo.keys[b];if(c.id&&c.id==a)return c.code}return null};d.prototype._doRequest=function(a,b){if("samsung_tv"==this._deviceInfo.id){var c=require("xnm.aio.samsung.js").SamsungTV;c=new c(this._options.ip,this._getPort());c._executeCommand(a,function(e){b&&b(e)})}else this._deviceInfo.ircccontrolurl?(c=new (require("xnm.aio.sony.js").IRCC)(this._options.ip,this._getPort(),this._deviceInfo.ircccontrolurl),this._deviceInfo.presharedkey&&
  (c._presharedkey=this._deviceInfo.presharedkey),c._executeCommand(a,function(e){b&&b(e)})):this._deviceInfo.pnccontrolurl?(c=require("xnm.aio.panasonic.js").TV,c=new c(this._options.ip,this._getPort(),this._deviceInfo.pnccontrolurl),c._executeCommand(a,function(e){b&&b(e)})):"onkyo"==this._deviceInfo.tcptype?(new (require("xnm.aio.onkyo.js").AVReceiver)(this._options.ip,this._getPort())).executeCommand(a,function(e){b&&b(e)}):"lgav"==this._deviceInfo.tcptype?(c=require("xnm.aio.lg.js").BDP,c=new c(this._options.ip,
  this._getPort()),c._executeCommand(a,function(e){b&&b(e)})):"panasonicbdp"==this._deviceInfo.tcptype?(c=require("xnm.aio.panasonic.js").BDP,c=new c(this._options.ip,this._getPort()),c._executeCommand(a,function(e){b&&b(e)})):"lgtv"==this._deviceInfo.tcptype?(c=require("xnm.aio.lg.js"),c="lgtv2012"==this._deviceInfo.id?c.TV2012:c.TV,c=new c(this._options.ip,this._getPort(),this._options.authKey),c._executeCommand(a,function(e){b&&b(e)})):"philips2011"==this._deviceInfo.tcptype?(c=require("xnm.aio.philips.js").JointSpaceTV,
  c=new c(this._options.ip,this._getPort()),c._executeCommand(a,function(e){b&&b(e)})):b&&b(Error("unknow ip device proxy type"))};return d}();xnm.aio.ip.Util=function(){return{_decodeXml:function(d){return d.replace(/&apos;/g,"'").replace(/&quot;/g,'"').replace(/&gt;/g,">").replace(/&lt;/g,"<").replace(/&amp;/g,"&")},_hex2arr:function(d){for(var a=[];2<=d.length;)a.push(parseInt(d.substring(0,2),16)),d=d.substring(2,d.length);return a}}}();
  xnm.aio.ip.DM=function(){var d=function(a,b){this.code=a;this.message=b;this.stack=Error().stack};d.prototype=Error();d.prototype.name="IpDMError";d.prototype.code=0;d.ERROR_CODE={DEFAULT:0,INDEX_EXISTS:1,ID_EXISTS:2,INVALID:3,UNKNOW:4,NOT_FOUND:5,IP_EXISTS:6};return{SYS:"ip",getIPDeviceType:function(a,b){b=[];if(a&&(a=a.getDevices()))for(var c=0;c<a.length;c++){var e=a[c],f=$(e).getAttributes();if(f&&f.id&&f.name){var k=this._deviceinfoXml2Json($(e)),l=this.getDeviceInfoType(k);l&&(e={sys:this.SYS,
  type:l,id:f.id,name:f.name,port:f.controlport},"proxy"==l&&!f.controlport&&(f=this._getProxyDeviceClass(k))&&(f=new f,e.port=f.port),b.push(e))}}return b},createDevice:function(a,b,c){b=d.ERROR_CODE;a?a.type?a.id?a.ip?c(null,a):c(new d(b.INVALID,"ip is invalid")):c(new d(b.INVALID,"id is invalid")):c(new d(b.INVALID,"type is invalid")):c(new d(b.INVALID,"info is invalid"))},updateDevice:function(a,b,c){b=d.ERROR_CODE;a?a.type?a.id?a.ip?c(null,a):c(new d(b.INVALID,"ip is invalid")):c(new d(b.INVALID,
  "id is invalid")):c(new d(b.INVALID,"type is invalid")):c(new d(b.INVALID,"info is invalid"))},deleteDevice:function(a,b,c){c()},applyUIFilter:function(a,b,c){var e=function(g,m){if("*"==g)return!0;for(var n=!1,p=0;p<g.length;p++)if(g[p]==m){n=!0;break}return n},f=function(g,m,n){var p=[];switch(n.catagory){case "command":g.command&&g.command.forEach(function(q){e(n.elems,q.type)&&(q=JSON.parse(JSON.stringify(q)),p.push(q))});break;case "status":g.status&&g.status.forEach(function(q){e(n.elems,q.type)&&
  (q=JSON.parse(JSON.stringify(q)),p.push(q))})}return p},k=function(g,m){var n=[],p=xnm.aio.ip.DM.getCommandStatusMap(g,c);p&&(g=f(p,g,m),n=n.concat(g));return n};if(!a.sys)return null;var l=JSON.parse(JSON.stringify(a)),h=null;switch(b.catagory){case "command":h=k(a,b);l.command=h;break;case "status":h=k(a,b);l.status=h;break;default:return null}return h&&0!=h.length?l:null},getDeviceInfo:function(a,b){if(!a.id||!b)return null;var c;(a=b.find('device[id="'+a.id+'"]'))&&0<a.length&&(c=a[0]);c=c?$(c):
  null;return c?this._deviceinfoXml2Json(c):null},getDeviceInfoType:function(a){if("samsung_tv"==a.id||a.ircccontrolurl||a.pnccontrolurl)return"proxy";if(a.tcptype){if("text"==a.tcptype||"textnl"==a.tcptype||"pioneer"==a.tcptype||"binary"==a.tcptype)return"tcp";if("generic"!=a.tcptype)return"proxy"}return a.udptype?"udp":a.controlurl?"http":null},getCommandStatusMap:function(a,b){a=this.getDeviceInfo(a,b);if(!a)return null;b={command:[]};if(a.keys)for(var c=0;c<a.keys.length;c++){var e=a.keys[c];b.command.push({type:"enum",
  name:e.id,ref:{value:e.id}})}return b},_getProxyDeviceClass:function(a){var b=null;"samsung_tv"==a.id?b=require("xnm.aio.samsung.js").SamsungTV:a.ircccontrolurl?b=require("xnm.aio.sony.js").IRCC:a.pnccontrolurl?b=require("xnm.aio.panasonic.js").TV:"onkyo"==a.tcptype?b=require("xnm.aio.onkyo.js").AVReceiver:"lgav"==a.tcptype?b=require("xnm.aio.lg.js").BDP:"panasonicbdp"==a.tcptype?b=require("xnm.aio.panasonic.js").BDP:"lgtv"==a.tcptype?b=require("xnm.aio.lg.js").TV:"philips2011"==a.tcptype&&(b=require("xnm.aio.philips.js").JointSpaceTV);
  return b},_deviceinfoXml2Json:function(a){var b=a.getAttributes();b=JSON.parse(JSON.stringify(b));a=a.children();for(var c=0;c<a.length;c++){var e=a[c];if(e){var f=$(e).attr("id");e=$(e).attr("code");f&&e&&(b.keys||(b.keys=[]),b.keys.push({id:f,code:e}))}}return b}}}();
  xnm.aio.ip.Handler=function(){var d=function(){};d.prototype.devicemanager=xnm.aio.ip.DM;d.prototype.Http=xnm.aio.ip.Http;d.prototype.Tcp=xnm.aio.ip.Tcp;d.prototype.Udp=xnm.aio.ip.Udp;d.prototype.registModule=function(a){a.register(xnm.aio.ip.DM.SYS,"ip")};d.prototype.resolveDevice=function(a,b){b=xnm.aio.ip.DM.getDeviceInfo(a,b);if(!b)return null;switch(xnm.aio.ip.DM.getDeviceInfoType(b)){case "http":return new xnm.aio.ip.Http(a,b);case "tcp":return new xnm.aio.ip.Tcp(a,b);case "udp":return new xnm.aio.ip.Udp(a,
  b);case "proxy":return new xnm.aio.ip._Proxy(a,b);default:return null}};d.prototype.getDeviceCommands=function(a,b){a=(a=xnm.aio.cams.DM.applyUIFilter(a,{catagory:"command",elems:"*"}))?a.command:[];b&&b(null,a)};return d}();"undefined"!=typeof module&&null!=module&&(module.exports=new xnm.aio.ip.Handler);
  