diff options
| author | Adam Soltys <[email protected]> | 2012-10-24 15:35:47 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2012-10-24 15:35:47 -0700 |
| commit | 70fd095f6084802fd48f4cc0c8f605f85a168a46 (patch) | |
| tree | 66460fc9b7cfa1070ee5348fbed9c85d26a92767 /js/reconnecting-websocket.min.js | |
| parent | 94e17c0d9fb972cfa0bac3267a1761520eee6fd5 (diff) | |
| download | coinos-server-70fd095f6084802fd48f4cc0c8f605f85a168a46.tar.gz coinos-server-70fd095f6084802fd48f4cc0c8f605f85a168a46.zip | |
Use reconnecting websocket
Diffstat (limited to 'js/reconnecting-websocket.min.js')
| -rw-r--r-- | js/reconnecting-websocket.min.js | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/js/reconnecting-websocket.min.js b/js/reconnecting-websocket.min.js new file mode 100644 index 00000000..cf29747e --- /dev/null +++ b/js/reconnecting-websocket.min.js @@ -0,0 +1,2 @@ +// https://github.com/joewalnes/reconnecting-websocket/ +function ReconnectingWebSocket(a){function f(g){c=new WebSocket(a);if(b.debug||ReconnectingWebSocket.debugAll){console.debug("ReconnectingWebSocket","attempt-connect",a)}var h=c;var i=setTimeout(function(){if(b.debug||ReconnectingWebSocket.debugAll){console.debug("ReconnectingWebSocket","connection-timeout",a)}e=true;h.close();e=false},b.timeoutInterval);c.onopen=function(c){clearTimeout(i);if(b.debug||ReconnectingWebSocket.debugAll){console.debug("ReconnectingWebSocket","onopen",a)}b.readyState=WebSocket.OPEN;g=false;b.onopen(c)};c.onclose=function(h){clearTimeout(i);c=null;if(d){b.readyState=WebSocket.CLOSED;b.onclose(h)}else{b.readyState=WebSocket.CONNECTING;if(!g&&!e){if(b.debug||ReconnectingWebSocket.debugAll){console.debug("ReconnectingWebSocket","onclose",a)}b.onclose(h)}setTimeout(function(){f(true)},b.reconnectInterval)}};c.onmessage=function(c){if(b.debug||ReconnectingWebSocket.debugAll){console.debug("ReconnectingWebSocket","onmessage",a,c.data)}b.onmessage(c)};c.onerror=function(c){if(b.debug||ReconnectingWebSocket.debugAll){console.debug("ReconnectingWebSocket","onerror",a,c)}b.onerror(c)}}this.debug=false;this.reconnectInterval=1e3;this.timeoutInterval=2e3;var b=this;var c;var d=false;var e=false;this.url=a;this.readyState=WebSocket.CONNECTING;this.URL=a;this.onopen=function(a){};this.onclose=function(a){};this.onmessage=function(a){};this.onerror=function(a){};f(a);this.send=function(d){if(c){if(b.debug||ReconnectingWebSocket.debugAll){console.debug("ReconnectingWebSocket","send",a,d)}return c.send(d)}else{throw"INVALID_STATE_ERR : Pausing to reconnect websocket"}};this.close=function(){if(c){d=true;c.close()}};this.refresh=function(){if(c){c.close()}}}ReconnectingWebSocket.debugAll=false |
