function SocketComm(){function g(){o=a}function y(){f=!0}function b(){try{e.onopen=null,e.onmessage=null,e.onclose=null,e.onerror=null,e=null,delete e}catch(t){}}function w(){clearInterval(v),v=null,m=!0,v=setInterval(function(){m?(m=!1,k("webserver/pingRequest")):(showDebug==2&&console.log("PING FAILED: "+r),clearInterval(v),v=null,S(),C(),funcObj.setupWizard.websocket_ping_fail(r,n))},c)}function E(t,o,u){showDebug==2&&console.log("SOCKET CONNECT: "+t+" / "+o);if((t!==undefined&&o!==undefined||u)&&(!i||t!=r||o!=n)){showDebug==2&&console.log("connecting..."),S(),b(),s=!1,i=!0,r=t,n=o,u?e=new Bluetooth:isAndroid&&!isAndroidChrome?e=new WebSocketPolyfill("ws://"+n+":8080","gabbo",t):e=new WebSocket("ws://"+n+":8080","gabbo");try{e.onopen=x,e.onmessage=T,e.onclose=N,e.onerror=L}catch(a){showDebug==2&&console.log("SOCKET ERROR: "+a),i=!1,s=!1}}}function S(){showDebug==2&&console.log("SOCKET RESET AND/OR DISCONNECT: "+s+" / "+A()),clearTimeout(l),l=null,clearInterval(v),v=null,i=!1,h=!1,s=!1,u=!1;try{e.close()}catch(t){}}function x(){showDebug==2&&console.log("SOCKET OPEN: "+n),n!==undefined&&n!==null?(i=!1,o=a,s=!0,u=!0,funcObj.setupWizard.websocket_opened(r,n),w()):(i=!1,console.log("UNDEFINED SOCKIP CAUGHT"))}function T(e,t){showDebug==2&&console.log("socket msg: "+e.data);var i=funcObj.setupWizard.getXMLfromString(e.data),s=$(i).children("header"),o=$(s).children("request")[0],u=$(i).children("body").children()[0],a={},f;m=!0,u!=undefined&&(a={deviceID:$(s).attr("deviceID"),requestID:$(o).attr("requestID"),url:$(s).attr("url"),method:$(s).attr("method"),mainNode:$($(o).children("info")[0]).attr("mainNode"),type:$($(o).children("info")[0]).attr("type"),src:$($(o).children("sourceItem")[0]).attr("source"),acc:$($(o).children("sourceItem")[0]).attr("sourceAccount")},f=$(o).attr("requestID"),i=u);var l=i.nodeName,c=$(i).attr("deviceID");if(c==undefined||c==null||c=="")c=r;c!=undefined&&c!=null&&c!=""&&(c=c.toUpperCase());switch(l){case"info":}funcObj.setupWizard.websocket_receive(c,n,l,i,f,t)}function N(){showDebug==2&&console.log("SOCKET CLOSED: "+r+" / "+u),i=!1,clearInterval(v),v=null,h=!1,funcObj.setupWizard.websocket_closed(r,n,s),s=!1,f||C(),u||funcObj.setupWizard.websocket_open_fail(r,n),u=!1}function C(){showDebug==2&&console.log("RETRY CONNECTION: "+r),clearTimeout(l),l=null,l=setTimeout(function(){var e=n,t=funcObj.devCon.getDevice(r);t!=undefined&&t!=null&&t.ip!=undefined&&t.ip!=null&&(e=t.ip),E(r,e)},5e3)}function k(t,n,i){var o="";i==undefined&&(i=0);var u="GET";n!=undefined&&n.match(/\S/)?(u="POST",n="<body>"+n+"</body>"):n="",o='<msg><header deviceID="'+r+'" url="'+t+'" method="'+u+'"><request requestID="'+i+'"></request></header>'+n+"</msg>";if(showDebug==2){var a=o.indexOf("pass")>=0;if(!a)isQT?console.log("socketSend: "+t+" / "+n+" / "+s+" / "+i):console.log("socketSend: "+t+" / "+n+" / "+s+" / "+i);else{var f=funcObj.setupWizard.getStringfromXML($(o).find("header"))+" - Message body with password redacted";isQT?console.log("socketSend: "+t+" / "+f+" / "+s+" / "+i):console.log("socketSend: "+t+" / "+f+" / "+s+" / "+i)}}try{e.send(o)}catch(l){showDebug==2&&console.log("Couldn't send message: "+t)}}function L(){showDebug==2&&console.log("SOCKET ERROR")}function A(){return s}function O(e){s=e}function M(){o=a}var e,t,n,r,i=!1,s=!1,o,u,a=5,f=!1,l,c=15e3,h,p,d,v,m;this.connect=E,this.disconnect=S,this.socketSend=k,this.socketOpen=x,this.socketClosed=N,this.socketRetry=C,this.getSocketState=A,this.socketMsg=T,this.set_do_not_retry=y,this.setSocketState=O,g()};