/*! ************************************************************************** sgcWebSocket component written by eSeGeCe copyright © 2020 Email : info@esegece.com Web : http://www.esegece.com ************************************************************************** */ function GUID(){var e=function(){return Math.floor(65536*Math.random()).toString(16)};return e()+e()+e()+e()+e()+e()+e()+e()}function event(e){this.name=e,this.eventAction=null,this.subscribe=function(e){this.eventAction=e},this.fire=function(e,t){null!=this.eventAction&&this.eventAction(e,t)}}function sgcStreamToString(e,t){var s=new FileReader;s.readAsText(e),s.onload=function(){vResult=s.result,t(vResult)}}function sgcWSStreamRead(e,t){var s=e.slice(0,10);sgcStreamToString(s,function(s){var o=parseInt(s),n=e.slice(10,10+o);sgcStreamToString(n,function(s){var n=s,i=e.slice(10+o,e.size);t(n,i)})})}function sgcEncodeB64(e){return e.length>0?1==sgcEncodeBase64?"sgc@b64:"+btoa(e):e:""}function sgcDecodeB64(e){return"object"==typeof arguments[0]==0&&"sgc@b64:"==e.substring(0,8)?atob(e.substring(8,e.length)):e}function sgcWebSocket(){if(0!=arguments.length){if("object"==typeof arguments[0])this.host=arguments[0].host,this.subprotocol=arguments[0].subprotocol,this.user=arguments[0].user,this.password=arguments[0].password,this.transport=arguments[0].transport;else{if("string"!=typeof arguments[0])return;this.host=arguments[0],this.subprotocol=arguments[1],this.transport=arguments[2]}void 0==this.host&&(this.host="127.0.0.1"),void 0==this.subprotocol&&(this.subprotocol=""),void 0==this.transport&&(this.transport=["websocket","sse"]);var e=new event("onopen"),t=new event("onclose"),s=new event("onmessage"),o=new event("onerror");if(DoEventBinary=function(e){n.fire({name:"onstream",stream:e.data})},DoEventMessage=function(e){s.fire({name:"onmessage",message:e.data})},window.WebSocket&&(!this.transport.indexOf||this.transport.indexOf("websocket")>-1)){var n=new event("onstream");this.open=function(){""!==this.host&&""!==this.user&&void 0!==this.user?(void 0==this.password&&""==this.password,""!==this.subprotocol&&void 0!==this.subprotocol?this.websocket=new WebSocket(this.host+"/sgc/auth/url/"+this.user+"/"+this.password,this.subprotocol):this.websocket=new WebSocket(this.host+"/sgc/auth/url/"+this.user+"/"+this.password)):""!==this.host&&""!==this.subprotocol&&void 0!==this.subprotocol?this.websocket=new WebSocket(this.host,this.subprotocol):""!==this.host&&(this.websocket=new WebSocket(this.host)),this.websocket.onopen=function(){e.fire({name:"onopen",message:""})},this.websocket.onmessage=function(e){"object"==typeof e.data?DoEventBinary(e):DoEventMessage(e)},this.websocket.onclose=function(e){t.fire({name:"onclose",message:"",code:e.code,reason:e.reason,clean:e.wasClean})},this.websocket.onerror=function(e){o.fire({name:"onerror",message:e.data})}},void 0==this.websocket&&this.open(),this.send=function(e){this.websocket.send(e)},this.sendbin=function(e){this.websocket.send(e)},this.close=function(){this.websocket.close()},this.state=function(){switch(this.websocket.readyState){case 0:return"connecting";case 1:return"open";case 2:return"closing";case 3:return"closed";default:return"undefined"}},this.on=function(i,r){"open"==i?e.subscribe(r):"close"==i?t.subscribe(r):"message"==i?s.subscribe(r):"stream"==i?n.subscribe(r):"error"==i&&o.subscribe(r)}}else if(window.EventSource&&this.transport.indexOf("sse")>-1){var i="";this.open=function(){""!==this.host&&""!==this.user&&void 0!==this.user?(void 0==this.password&&""==this.password,""!==this.subprotocol&&void 0!==this.subprotocol?this.EventSource=new EventSource(this.host.replace(/^[a-z]{2,3}\:\/{2}[a-z,0-9,.]{1,}\:[0-9]{1,4}.(.*)/,"$1")+"/sgc/auth/url/"+this.user+"/"+this.password+"/"+this.subprotocol):this.EventSource=new EventSource(this.host.replace(/^[a-z]{2,3}\:\/{2}[a-z,0-9,.]{1,}\:[0-9]{1,4}.(.*)/,"$1")+"/sgc/auth/url/"+this.user+"/"+this.password)):""!==this.host&&""!==this.subprotocol&&void 0!==this.subprotocol?this.EventSource=new EventSource(this.subprotocol):""!==this.host&&(this.EventSource=new EventSource("/")),this.EventSource.onopen=function(){e.fire({name:"onopen",message:""})},this.EventSource.onmessage=function(e){""==i?i=e.data:DoEventMessage(e)},this.EventSource.onerror=function(e){o.fire({name:"onerror",message:e.data})}},void 0==this.EventSource&&this.open(),this.send=function(e){if(""!==i){if(window.XMLHttpRequest)xhr=new XMLHttpRequest;else{if(!window.ActiveXObject)return;xhr=new ActiveXObject("Microsoft.XMLHTTP")}xhr.open("POST","/sgc/xhr/"+i,!0),xhr.send(e)}},this.close=function(){this.EventSource.close(),t.fire({name:"onclose",message:"",code:1e3,reason:"",clean:!0})},this.state=function(){switch(this.EventSource.readyState){case 0:return"connecting";case 1:return"open";case 2:return"closed";default:return"undefined"}},this.on=function(i,r){"open"==i?e.subscribe(r):"close"==i?t.subscribe(r):"message"==i?s.subscribe(r):"stream"==i?n.suscribe(r):"error"==i&&o.subscribe(r)}}else alert("WebSockets not supported by your Browser.")}}var sgcEncodeBase64=!1;