-
Notifications
You must be signed in to change notification settings - Fork 77
/
jslib.go
4 lines (3 loc) · 18.1 KB
/
jslib.go
1
2
3
4
package gotalk
const JSLibSHA1Base64 = "YLDgrGNN3M7gn9qZDeBmFusYWIQ="
const JSLibString = "var gotalk=(function(){var I=Object.defineProperty,me=Object.prototype.hasOwnProperty,B=(e,t)=>()=>(t||(t={exports:{}},e(t.exports,t)),t.exports),Z=e=>I(e,\"__esModule\",{value:!0}),$=(e,t)=>{Z(e);for(var r in t)I(e,r,{get:t[r],enumerable:!0})},ve=(e,t)=>{if(Z(e),typeof t==\"object\"||typeof t==\"function\")for(var r in t)!me.call(e,r)&&r!==\"default\"&&(n=>{I(e,n,{get:()=>t[n],enumerable:!0})})(r);return e},w=e=>e&&e.__esModule?e:ve(I({},\"default\",{value:e,enumerable:!0}),e);var P=B(C=>{$(C,{sizeOf:()=>ee});function ee(e){for(var t=0,r=0,n;n=e.charCodeAt(r++);t+=n>>11?3:n>>7?2:1);return t}function z(e){return 255&e}if(typeof TextDecoder!=\"undefined\"){var ye=new TextDecoder(\"utf8\"),be=new TextEncoder(\"utf8\");C.decode=function(t){return ye.decode(t)},C.encode=function(t){return be.encode(t)}}else C.decode=function(t){var r=0,n=t.length-r,o,s,i=\"\";for(r=0;r<n;)o=t[r++],s=z(o),s<128||(s>>5==6?o=(o<<6&2047)+(t[r++]&63):s>>4==14?(o=(o<<12&65535)+(z(t[r++])<<6&4095),o+=t[r++]&63):s>>3==30&&(o=(o<<18&2097151)+(z(t[r++])<<12&262143),o+=z(t[r++])<<6&4095,o+=t[r++]&63)),i+=String.fromCharCode(o);return i},C.encode=function(t){for(var r=0,n=t.length,o,s=0,i=new Uint8Array(ee(t));r!==n;)o=t.charCodeAt(r++),o<128?i[s++]=o:o<2048?(i[s++]=o>>6|192,i[s++]=o&63|128):o<65536?(i[s++]=o>>12|224,i[s++]=o>>6&63|128,i[s++]=o&63|128):(i[s++]=o>>18|240,i[s++]=o>>12&63|128,i[s++]=o>>6&63|128,i[s++]=o&63|128);return i}});var j=B(A=>{function V(){}A.global=typeof global!=\"undefined\"?global:typeof self!=\"undefined\"?self:typeof window!=\"undefined\"?window:A;A.console=typeof console!=\"undefined\"?console:{log:V,warn:V,error:V};A.document=typeof document!=\"undefined\"?document:null});var J=B(d=>{const T=w(P());d.Version=1;var te=d.MsgTypeSingleReq=114,re=d.MsgTypeStreamReq=115,Oe=d.MsgTypeStreamReqPart=112,Ie=d.MsgTypeSingleRes=82,Be=d.MsgTypeStreamRes=83,ze=d.MsgTypeErrorRes=69,N=d.MsgTypeRetryRes=101,L=d.MsgTypeNotification=110,U=d.MsgTypeHeartbeat=104,ne=d.MsgTypeProtocolError=102;d.ErrorAbnormal=0;d.ErrorUnsupported=1;d.ErrorInvalidMsg=2;d.ErrorTimeout=3;d.HeartbeatMsgMaxLoad=65535;function R(e,t,r,n){for(var o=t||0,s=0,i,a=r.toString(16),g=n-a.length;g--;)e[o++]=48;for(;!isNaN(i=a.charCodeAt(s++));)e[o++]=i}function oe(e,t){var r=h(t);return R(r,0,e,t),r}function H(e){for(var t=0,r=0,n=0,o=!1;r<e.length;r++)n=e[r],n<64?(n<48&&(o=!0),n-=48):n<71?(n<65&&(o=!0),n-=55):n<103&&96<n?n-=87:o=!0,t=t<<4|n&15;if(o)throw new Error(\"invalid hexint \"+String.fromCharCode.apply(null,e));return t}d.binary={makeFixnum:oe,versionBuf:oe(d.Version,2),parseVersion:H,parseMsg:function(e){var t,r,n,o,s=0,i=0,a;return t=e[0],a=1,t===U?(s=H(e.subarray(a,a+4)),a+=4):t!==L&&t!==ne&&(r=e.subarray(a,a+4),a+=4),t==te||t==re||t==L?(o=H(e.subarray(a,a+3)),a+=3,n=T.decode(e.subarray(a,a+o)),a+=o):t===N&&(s=H(e.subarray(a,a+8)),a+=8),i=H(e.subarray(a,a+8)),{t:t,id:r,name:n,wait:s,size:i}},makeMsg:function(e,t,r,n,o){var s,i,a=t?13:9;return r&&r.length!==0&&(i=T.encode(r),a+=3+i.length),s=h(a),s[0]=e,a=1,t&&t.length===4&&(typeof t==\"string\"?(s[1]=t.charCodeAt(0),s[2]=t.charCodeAt(1),s[3]=t.charCodeAt(2),s[4]=t.charCodeAt(3)):(s[1]=t[0],s[2]=t[1],s[3]=t[2],s[4]=t[3]),a+=4),i&&(R(s,a,i.length,3),a+=3,s.set(i,a),a+=i.length),e===N&&(R(s,a,n,8),a+=8),R(s,a,o,8),s},makeHeartbeatMsg:function(e){var t=h(13),r=1;return t[0]=U,R(t,r,e,4),r+=4,R(t,r,Math.round(new Date().getTime()/1e3),8),r+=8,t}};var we=\"00000000\";function x(e,t){var r=e.toString(16);return we.substr(0,t-r.length)+r}d.text={makeFixnum:x,versionBuf:x(d.Version,2),parseVersion:function(e){return parseInt(e.substr(0,2),16)},parseMsg:function(e){var t,r,n,o=0,s=0,i;return t=e.charCodeAt(0),i=1,t===U?(o=parseInt(e.substr(i,4),16),i+=4):t!==L&&t!==ne&&(r=e.substr(i,4),i+=4),t==te||t==re||t==L?n=e.substring(i+3,e.length-8):t==N&&(o=parseInt(e.substr(i,8),16),i+=8),s=parseInt(e.substr(e.length-8),16),{t:t,id:r,name:n,wait:o,size:s}},makeMsg:function(e,t,r,n,o){var s=String.fromCharCode(e);return t&&t.length===4&&(s+=t),r&&r.length!==0&&(s+=x(T.sizeOf(r),3),s+=r),e===N&&(s+=x(n,8)),s+=x(o,8),s},makeHeartbeatMsg:function(e){var t=String.fromCharCode(U);return t+=x(e,4),t+=x(Math.round(new Date().getTime()/1e3),8),t}}});var ge=B(y=>{$(y,{default:()=>ie});const M=w(j()),f=w(J()),q=w(P());var u=y,ie=y,ae=f.text,fe=f.binary;u.version=\"1.2.1\";u.protocol=f;u.Buf=h;u.developmentMode=!1;u.defaultResponderAddress=\"\";var le=\"\",p={wsproto:\"\",proto:\"\",host:\"\",path:\"\"};function Ee(){M.document&&xe(),u.developmentMode=Me(p.host)}function xe(){var e=M.document.currentScript.src;if(!e)return;var t=e.indexOf(\"://\")+3;if(t==2)return;p.proto=e.substr(0,t-2);var r=e.indexOf(\"/\",t);if(r==-1)return;p.wsproto=p.proto==\"https:\"?\"wss://\":\"ws://\",p.host=e.substring(t,r),e=e.substr(r),t=e.lastIndexOf(\"?\"),t!=-1&&(e=e.substr(0,t)),p.path=e.substring(e.indexOf(\"/\"),e.lastIndexOf(\"/\")+1),u.defaultResponderAddress=p.wsproto+p.host+p.path,le=u.defaultResponderAddress}function Me(e){var t=e,r=t.lastIndexOf(\":\");return r!=-1&&(t=t.substr(0,r)),r=t.lastIndexOf(\".\"),r==-1?t==\"localhost\":t==\"127.0.0.1\"||t.substr(r)==\".local\"}function F(){u.developmentMode&&M.console.warn.apply(M.console,Array.prototype.slice.call(arguments))}function G(e){if(!e||e.length==0)return null;typeof e!=\"string\"&&(e=q.decode(e));try{return JSON.parse(e)}catch(t){F(\"[gotalk] ignoring invalid json\",e)}}function l(e,t){return Object.create(l.prototype,{handlers:{value:e,enumerable:!0},protocol:{value:t||(h?f.binary:f.text),enumerable:!0,writable:!0},heartbeatInterval:{value:20*1e3,enumerable:!0,writable:!0},ws:{value:null,writable:!0,enumerable:!0},keepalive:{value:null,writable:!0,enumerable:!0},_isOpen:{value:!1,writable:!0},_sendq:{value:[],writable:!0},sendBufferLimit:{value:100,writable:!0,enumerable:!0},nextOpID:{value:0,writable:!0},nextStreamID:{value:0,writable:!0},pendingRes:{value:{},writable:!0},hasPendingRes:{get:function(){for(var r in this.pendingRes)return!0}},pendingClose:{value:!1,writable:!0}})}l.prototype=c.mixin(l.prototype);y.Sock=l;function Se(e,t){if(e.pendingClose=!1,e.stopSendingHeartbeats(),e.ws&&(e.ws.onmessage=null,e.ws.onerror=null,e.ws.onclose=null,e.ws=null),e.nextOpID=0,e.hasPendingRes){var r=t||new Error(\"connection closed\");for(var n in e.pendingRes)e.pendingRes[n](r);e.pendingRes={}}}var ke={1e3:\"normal\",1001:\"going away\",1002:\"protocol error\",1003:\"unsupported\",1005:\"no status\",1006:\"abnormal\",1007:\"inconsistent\",1008:\"invalid message\",1009:\"too large\"},E=Symbol(\"CLOSE_ERROR\");function K(e){var t=ke[e];return\"#\"+e+(t?\" (\"+t+\")\":\"\")}l.prototype.adoptWebSocket=function(e){var t=this;if(e.readyState!==WebSocket.OPEN)throw new Error(\"web socket readyState != OPEN\");e.binaryType=\"arraybuffer\",t.ws=e,e.onclose=function(r){var n=e[E]||null;!n&&r.code!==1e3&&(n=new Error(\"websocket closed: \"+K(r.code))),Se(t,n),t._connectionStatusChange(!1),t.emit(\"close\",n)},e.onmessage=function(r){e._bufferedMessages||(e._bufferedMessages=[]),e._bufferedMessages.push(r.data)}};l.prototype.adopt=function(e){if(adopt instanceof WebSocket)return this.adoptWebSocket(e);throw new Error(\"unsupported transport\")};l.prototype.handshake=function(){this.ws.send(this.protocol.versionBuf)};l.prototype.end=function(){var e=this;e.keepalive&&(e.keepalive.disable(),e.keepalive=null),!e.pendingClose&&e.hasPendingRes?e.pendingClose=!0:e.ws&&e.ws.close(1e3)};l.prototype.address=function(){var e=this;return e.ws?e.ws.url:null};var X=y.ErrAbnormal=Error(\"unsupported protocol\");X.isGotalkProtocolError=!0;X.code=f.ErrorAbnormal;var W=y.ErrUnsupported=Error(\"unsupported protocol\");W.isGotalkProtocolError=!0;W.code=f.ErrorUnsupported;var D=y.ErrInvalidMsg=Error(\"invalid protocol message\");D.isGotalkProtocolError=!0;D.code=f.ErrorInvalidMsg;var Q=y.ErrTimeout=Error(\"timeout\");Q.isGotalkProtocolError=!0;Q.code=f.ErrorTimeout;l.prototype.sendHeartbeat=function(e){var t=this,r=t.protocol.makeHeartbeatMsg(Math.round(e*f.HeartbeatMsgMaxLoad));try{t.ws.send(r)}catch(n){throw(!this.ws||this.ws.readyState>WebSocket.OPEN)&&(n=new Error(\"socket is closed\")),n}};l.prototype.startSendingHeartbeats=function(){var e=this;if(e.heartbeatInterval<10)throw new Error(\"Sock.heartbeatInterval is too low\");clearTimeout(e._sendHeartbeatsTimer);var t=function(){clearTimeout(e._sendHeartbeatsTimer),e.sendHeartbeat(0),e._sendHeartbeatsTimer=setTimeout(t,e.heartbeatInterval)};e._sendHeartbeatsTimer=setTimeout(t,1)};l.prototype.stopSendingHeartbeats=function(){var e=this;clearTimeout(e._sendHeartbeatsTimer)};l.prototype.startReading=function(){var e=this,t=e.ws,r;function n(i){if(r=typeof i.data==\"string\"?ae.parseMsg(i.data):fe.parseMsg(h(i.data)),r.t===f.MsgTypeProtocolError){var a=r.size;a===f.ErrorAbnormal?t[E]=X:a===f.ErrorUnsupported?t[E]=W:a===f.ErrorTimeout?t[E]=Q:t[E]=D,t.close(4e3+a)}else r.size!==0&&r.t!==f.MsgTypeHeartbeat?t.onmessage=o:(e.handleMsg(r),r=null)}function o(i){var a=i.data;t.onmessage=n,e.handleMsg(r,typeof a==\"string\"?a:h(a)),r=null}function s(i){var a=typeof i.data==\"string\"?ae.parseVersion(i.data):fe.parseVersion(h(i.data));a!==f.Version?(t[E]=W,e.closeError(f.ErrorUnsupported)):(t.onmessage=n,e.heartbeatInterval>0&&e.startSendingHeartbeats())}t.onmessage=s,t._bufferedMessages&&(t._bufferedMessages.forEach(function(i){t.onmessage({data:i})}),t._bufferedMessages=null)};var S={};l.prototype.handleMsg=function(e,t){var r=this,n=S[e.t];n?n.call(r,e,t):(r.ws&&(r.ws[E]=D),r.closeError(f.ErrorInvalidMsg))};S[f.MsgTypeSingleReq]=function(e,t){var r=this,n,o;if(n=r.handlers.findRequestHandler(e.name),o=function(s){r.sendMsg(f.MsgTypeSingleRes,e.id,null,0,s)},o.error=function(s){var i=s.message||String(s);r.sendMsg(f.MsgTypeErrorRes,e.id,null,0,i)},typeof n!=\"function\")o.error('no such operation \"'+e.name+'\"');else try{n(t,o,e.name)}catch(s){F(\"[gotalk] handler error:\",s.stack||\"\"+s),o.error(\"internal error\")}};function Y(e,t){var r=e.id;typeof r!=\"string\"&&(r=String.fromCharCode.apply(null,r));var n=this,o=n.pendingRes[r];if((e.t!==f.MsgTypeStreamRes||!t||(t.length||t.size)===0)&&(delete n.pendingRes[r],n.pendingClose&&!n.hasPendingRes&&n.end()),typeof o!=\"function\")return;e.t===f.MsgTypeErrorRes?(typeof t!=\"string\"&&(t=q.decode(t)),o(new Error(t),null)):o(null,t)}S[f.MsgTypeSingleRes]=Y;S[f.MsgTypeStreamRes]=Y;S[f.MsgTypeErrorRes]=Y;S[f.MsgTypeNotification]=function(e,t){var r=this.handlers.findNotificationHandler(e.name);r&&r(t,e.name)};S[f.MsgTypeHeartbeat]=function(e){this.emit(\"heartbeat\",{time:new Date(e.size*1e3),load:e.wait})};l.prototype._connectionStatusChange=function(e){if(this._isOpen==e)return;this._isOpen=e,e&&Te(this)};function de(e,t,r){try{e.ws.send(t),r&&e.ws.send(r)}catch(n){if((!e.ws||e.ws.readyState>WebSocket.OPEN)&&(n=new Error(\"socket is closed\"),ue(e,t,r))){M.console.warn(\"gotalk send error: \"+n+\" (retrying)\");return}throw n}}function Te(e){if(e._sendq.length==0)return;var t=e._sendq;e._sendq=[];for(var r,n,o=0;o<t.length;o++)n=t[o],de(e,n[0],n[1])}function ue(e,t,r){return e._sendq.length>=e.sendBufferLimit?!1:(e._sendq.push([t,r]),!0)}l.prototype.sendMsg=function(e,t,r,n,o){var s=0;o&&(typeof o==\"string\"&&this.protocol===f.binary?s=q.sizeOf(o):s=o.length||o.size||0,s==0&&(o=null));var i=this,a=i.protocol.makeMsg(e,t,r,n,s);if(i._isOpen)de(i,a,o);else if(!ue(i,a,o))throw new Error(\"socket is closed\")};l.prototype.closeError=function(e){var t=this,r;if(t.ws){try{t.ws.send(t.protocol.makeMsg(f.MsgTypeProtocolError,null,null,0,e))}catch(n){}t.ws.close(4e3+e)}};l.prototype.notify=function(e,t){var r=JSON.stringify(t);return this.bufferNotify(e,r)};l.prototype.bufferNotify=function(e,t){this.sendMsg(f.MsgTypeNotification,null,e,0,t)};var ce=\"0000\";l.prototype.bufferRequest=function(e,t,r){var n=this;return new Promise(function(o,s){var i=n.nextOpID++;n.nextOpID===1679616&&(n.nextOpID=0),i=i.toString(36),i=ce.substr(0,4-i.length)+i;var a=function(g,_){g?s(g):o(_),r&&r(g,_)};n.pendingRes[i]=a;try{n.sendMsg(f.MsgTypeSingleReq,i,e,0,t)}catch(g){delete n.pendingRes[i],a(g)}})};l.prototype.request=function(e,t,r){var n;t!==void 0&&(r===void 0&&typeof t==\"function\"?r=t:n=JSON.stringify(t));var o=this.bufferRequest(e,n).then(function(s){var i=G(s);return r&&r(null,i),i});return r&&(o=o.catch(function(s){r(s)})),o};l.prototype.requestp=l.prototype.request;l.prototype.bufferRequestp=l.prototype.bufferRequest;var O=function(e,t,r){return Object.create(O.prototype,{s:{value:e},op:{value:t,enumerable:!0},id:{value:r,enumerable:!0}})};c.mixin(O.prototype);O.prototype.write=function(e){this.ended||(this.started?this.s.sendMsg(f.MsgTypeStreamReqPart,this.id,null,0,e):(this.started=!0,this.s.sendMsg(f.MsgTypeStreamReq,this.id,this.op,0,e)),(!e||e.length===0||e.size===0)&&(this.ended=!0))};O.prototype.end=function(){this.write(null)};l.prototype.streamRequest=function(e){var t=this,r=t.nextStreamID++;t.nextStreamID===46656&&(t.nextStreamID=0),r=r.toString(36),r=\"!\"+ce.substr(0,3-r.length)+r;var n=O(t,e,r);return t.pendingRes[r]=function(o,s){o?n.emit(\"end\",o):!s||s.length===0?n.emit(\"end\",null):n.emit(\"data\",s)},n};function b(){return Object.create(b.prototype,{reqHandlers:{value:{}},reqFallbackHandler:{value:null,writable:!0},noteHandlers:{value:{}},noteFallbackHandler:{value:null,writable:!0}})}y.Handlers=b;b.prototype.handleBufferRequest=function(e,t){e?this.reqHandlers[e]=t:this.reqFallbackHandler=t};b.prototype.handleRequest=function(e,t){return this.handleBufferRequest(e,function(r,n,o){var s=function(a){return n(JSON.stringify(a))};s.error=n.error;var i=G(r);t(i,s,o)})};b.prototype.handleBufferNotification=function(e,t){e?this.noteHandlers[e]=t:this.noteFallbackHandler=t};b.prototype.handleNotification=function(e,t){this.handleBufferNotification(e,function(r,n){t(G(r),n)})};b.prototype.findRequestHandler=function(e){var t=this.reqHandlers[e];return t||this.reqFallbackHandler};b.prototype.findNotificationHandler=function(e){var t=this.noteHandlers[e];return t||this.noteFallbackHandler};var pe=!1;function Re(e,t,r){var n;try{n=new WebSocket(t),n.binaryType=\"arraybuffer\",n.onclose=function(o){u.developmentMode&&!pe&&le==u.defaultResponderAddress&&(pe=!0,F(\"gotalk connection failed with code \"+K(o.code)+\". If you are serving gotalk.js yourself, remember to set gotalk.defaultResponderAddress to the gotalk websocket endpoint.\"));var s=new Error(\"connection failed: \"+K(o.code));r&&r(s)},n.onopen=function(o){n.onerror=void 0,e.adoptWebSocket(n),e.handshake(),e._connectionStatusChange(!0),r&&r(null,e),e.emit(\"open\",e),e.startReading()},n.onmessage=function(o){n._bufferedMessages||(n._bufferedMessages=[]),n._bufferedMessages.push(o.data)}}catch(o){F(\"[gotalk] WebSocket init error:\",o.stack||\"\"+o),e._connectionStatusChange(!1),r&&r(o),e.emit(\"close\",o)}}function _e(e){e||(e=u.defaultResponderAddress);var t=e.substr(0,4);if(t!=\"ws:/\"&&t!=\"wss:\"&&(p.proto&&(e[0]==\"/\"?e[1]==\"/\"?e=p.wsproto+e:e=p.wsproto+p.host+e:e=p.wsproto+p.host+\"/\"+e)),!e)throw new Error(\"address not specified\");return e}l.prototype.open=function(e,t){var r=this;return!t&&typeof e==\"function\"&&(t=e,e=null),Re(r,_e(e),t),r};u.open=function(e,t,r,n){return l(r||u.defaultHandlers,n).open(e,t)};l.prototype.openKeepAlive=function(e){var t=this;return t.keepalive&&t.keepalive.disable(),t.keepalive=se(t,e),t.keepalive.enable(),t};u.connection=function(e,t,r){return l(t||u.defaultHandlers,r).openKeepAlive(e)};u.defaultHandlers=b();u.handleBufferRequest=function(e,t){return u.defaultHandlers.handleBufferRequest(e,t)};u.handle=function(e,t){return u.defaultHandlers.handleRequest(e,t)};u.handleBufferNotification=function(e,t){return u.defaultHandlers.handleBufferNotification(e,t)};u.handleNotification=function(e,t){return u.defaultHandlers.handleNotification(e,t)};Ee()});const De=w(P());var h=function(){return typeof Uint8Array==\"undefined\"?null:function(t){return t instanceof Uint8Array?t:new Uint8Array(t instanceof ArrayBuffer?t:new ArrayBuffer(t))}}();function c(){}c.prototype.addListener=function(e,t){if(typeof t!=\"function\")throw TypeError(\"listener must be a function\");if(!this.__events)return Object.defineProperty(this,\"__events\",{value:{},enumerable:!1,writable:!0}),this.__events[e]=[t],this;var r=this.__events[e];return r===void 0?(this.__events[e]=[t],this):(r.push(t),this)};c.prototype.on=c.prototype.addListener;c.prototype.once=function(e,t){var r=!1,n=function(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))};return this.on(e,n)};c.prototype.removeListener=function(e,t){var r,n=this.__events?this.__events[e]:void 0;if(n!==void 0){for(;(r=n.indexOf(t))!==-1;)n.splice(r,1);return n.length===0&&delete this.__events[e],n.length}return this};c.prototype.removeAllListeners=function(e){this.__events&&(e?delete this.__events[e]:delete this.__events)};c.prototype.listeners=function(e){return e?this.__events?this.__events[e]:void 0:this.__events};c.prototype.emit=function(e){var t=this.__events?this.__events[e]:void 0;if(t===void 0)return!1;for(var r=0,n=t.length,o=Array.prototype.slice.call(arguments,1);r!==n;++r)t[r].apply(this,o);return!0};c.mixin=function(t){for(var r=t;r;){if(r.__proto__===Object.prototype)return r.__proto__=c.prototype,t;r=r.__proto__}return t};const m=w(j()),he=w(J());var v=new c;v.available=!1;v.onLine=!0;m.global.addEventListener&&(v.available=!0,v.onLine=typeof navigator!=\"undefined\"?navigator.onLine:!0,m.global.addEventListener(\"offline\",function(e){v.onLine=!1}),m.global.addEventListener(\"online\",function(e){v.onLine=!0,v.emit(\"online\")}));function se(e,t,r,n){r?r<100&&(r=100):r=500,(!n||n<r)&&(n=5e3);var o,s,i,a=0,g,_;return o={isEnabled:!1,isConnected:!1,enable:function(){o.enabled||(o.enabled=!0,a=0,o.isConnected||s())},disable:function(){o.enabled&&(clearTimeout(g),o.enabled=!1,a=0)}},s=function(){clearTimeout(g),e.open(t,function(k){_=new Date,k?i(k):(a=0,o.isConnected=!0,e.once(\"close\",i))})},i=function(k){if(clearTimeout(g),o.isConnected=!1,!o.enabled)return;if(v.available&&!v.onLine&&!(m.document&&m.document.location&&m.document.location.hostname!==\"localhost\"&&m.document.location.hostname!==\"127.0.0.1\"&&m.document.location.hostname!==\"[::1]\")){v.once(\"online\",i),a=0;return}k?k.isGotalkProtocolError?k.code===he.ErrorTimeout?a=0:a=n:a=a?Math.min(n,a*2):r:a=Math.max(100,r-(new Date-_)),g=setTimeout(s,a)},o}return ge();})();\n"