function ajaxGet(n,t){var i=new XMLHttpRequest;i.onreadystatechange=function(){if(i.readyState==4)if(i.status==200){var n=i.responseText;typeof t.onSuccess=="function"&&t.onSuccess.apply(this,[i,n])}else typeof t.onError=="function"&&t.onError.apply(this,[i])};i.open("GET",n,!1);i.send(null)}var SocketClient=function(n,t,i,r){var u={websocket:{ws:{host:n}},authServer:t,status:r,socketID:i};return new SocketClientBase(u)},SocketClientBase=function(n){function r(){}var t=null;return this.settings=$.extend(!0,{},{websocket:{ws:{host:null}},authServer:null,status:null,socketID:null,log:{ws:{ws_open:!0,ws_error:!0,lasttry_open:!0,lasttry_error:!0}},logCode:{ws:{open:"1",error:"0"},handshake:{success:"1"}},code:null},n),this.authServer=this.settings.authServer,this.socketID=this.settings.socketID,this.status=this.settings.status,this.socket=null,this.open=!1,this.callbacks={},this.vaild=!1,this.closeCode=[],this.host=null,this.logSuccess=!0,this.init=function(){this.callbacks.onopen=[];this.callbacks.onclose=[];this.callbacks.onerror=[];this.callbacks.onmessage=[];this.host=this.settings.websocket.ws.host;var n=this;try{this.socket=new WebSocket(this.host);$(window).unload(function(){n.socket.onclose=function(){};n.socket.close()});this.socket.onopen=function(){n.open=!0;AACONFIG.ShowMsg&&console.log("hs Socket: ["+n.socketID,n.status+"]: Open");n.send(JSON.stringify({k:n.status}))};this.socket.onclose=function(t){AACONFIG.ShowMsg&&console.log("Socket: ["+n.socketID+']: Close: "'+t+'"');n.onSocketClose.apply(n,[t])};this.socket.onerror=function(t){r();AACONFIG.ShowMsg&&console.log("Socket: ["+n.socketID+']: Error: "'+t+'"');n.onSocketError.apply(n,[t])};this.socket.onmessage=function(t){var r=t.data,i=JSON.parse(r);AACONFIG.ShowMsg&&console.log("hs onmessage: connectionStatus ["+connectionStatus+"], obj: ",i);connectionStatus==0?i.status==1?(connectionStatus=2,n.onSocketOpen.apply(n,[i])):console.log("Connection fail"):connectionStatus==2&&n.onSocketMessage.apply(n,[i]);message=null}}catch(i){this.socket={};n.closeCode.push("S0001");r();setTimeout(function(){t.onSocketClose(i)},2)}},this.bind=function(n,t){this.callbacks[n].push(t)},this.unbind=function(n){this.callbacks[n]=[]},this.onSocketOpen=function(n){AACONFIG.ShowMsg&&console.log("hs onSocketOpen");for(var t in this.callbacks.onopen)if(this.callbacks.onopen[t].apply(this.callbacks.onopen[t],[this.socket,n])===!1)return},this.onSocketClose=function(n){this.open=!1;this.closeCode.push("E"+(n!=null&&n.code!=undefined?n.code:""));for(var t in this.callbacks.onclose)if(this.callbacks.onclose[t].apply(this.callbacks.onclose[t],[this.socket,n])===!1)return},this.onSocketError=function(n){for(var t in this.callbacks.onerror)if(this.callbacks.onerror[t].apply(this.callbacks.onerror[t],[this.socket,n])===!1)return},this.onSocketMessage=function(n){for(var t in this.callbacks.onmessage)if(this.callbacks.onmessage[t].apply(this.callbacks.onmessage[t],[this.socket,n])===!1)return},this.send=function(n){this.open&&(AACONFIG.ShowMsg&&console.log("hs send:"+n),this.socket.send(n))},this.close=function(){try{this.socket.close()}catch(n){}},this.getSocketConn=function(){"WS"},this.getSocketStatus=function(){if(this.closeCode.length>0){for(i=this.closeCode.length-1;i>=0;i--)if(this.closeCode[i].substring(0,1)=="H"||this.closeCode[i].substring(0,1)=="S")return this.closeCode[i];return this.closeCode[this.closeCode.length-1]}return-1},t=this,this.init(),this},TeletextAdapter=function(n){var i={host:null,authServer:null,status:null,socketID:null,lang:"E",onOpen:function(){},onClose:function(){},bindData:function(){}},t;return this.socket=null,this.host=null,this.settings=$.extend(i,n),this.code=this.settings.code,this.reconnect=!0,this.reconnectTimer=null,t=this,this.init=function(){var t,r,i,n;this.reconnect=!0;i={hidden:"visibilitychange",webkitHidden:"webkitvisibilitychange",mozHidden:"mozvisibilitychange",msHidden:"msvisibilitychange"};for(t in i)if(t in document){r=i[t];break}document.addEventListener(r,VisibilityChange);this.socket&&(this.socket.unbind("onopen"),this.socket.unbind("onclose"),this.socket.unbind("onerror"),this.socket.unbind("onmessage"));this.socket=new SocketClient(this.settings.host,this.settings.authServer,this.settings.socketID,this.settings.status);AACONFIG.ShowMsg&&console.log("adapter init",this.settings.status);n=this;this.socket.bind("onopen",function(t,i){n.onSocketOpen.apply(n,[t,i])});this.socket.bind("onclose",function(t,i){n.onSocketClose.apply(n,[t,i])});this.socket.bind("onerror",function(t,i){n.onSocketError.apply(n,[t,i])});this.socket.bind("onmessage",function(t,i){n.onSocketMessage.apply(n,[t,i])});this.socket.encode=function(n){return n};this.socket.decode=function(n){return n}},this.onSocketOpen=function(n){typeof this.settings.onOpen=="function"&&this.settings.onOpen.apply(this,[t]);try{AACONFIG.ShowMsg&&console.log("adapter Socket: ["+this.socket.socketID+"]: Open",this.code);this.send(JSON.stringify({s:this.code}))}catch(i){n.close()}},this.onSocketClose=function(){typeof this.settings.onClose=="function"&&this.settings.onClose.apply(this,[]);this.reconnect&&(this.reconnectTimer=setTimeout(function(){console.log("try Reconnect > "+t.settings.socketID);t.init()},5e3))},this.onSocketError=function(n){n.close()},this.onSocketMessage=function(n,t){AACONFIG.ShowMsg&&console.log("message:"+t);this.handleResponse.apply(this,[t,this.code])},this.sendRequest=function(n){return this.code=n,AACONFIG.ShowMsg&&console.log("Socket: ["+this.socket.socketID+"]: Send Message: s:"+this.code),this.send(JSON.stringify({s:this.code})),!0},this.handleResponse=function(n,t){this.settings.bindData(n,t)},this.send=function(n){AACONFIG.ShowMsg&&console.log("adapter send: "+n);this.socket.send(n)},this.close=function(){console.log("adapter close");this.reconnectTimer!=null&&clearTimeout(this.reconnectTimer);this.reconnect=!1;this.socket&&this.socket.close()},this}