KO
|
EN
gitlite — search
Search
#python
#hacktoberfest
#ruby
#php
#javascript
#wordpress
#dotfiles
#shell
#erlang
#vim
#library
#latex
sockjs_reconnect
★ 25
Open GitHub ↗
SockJS client-side reconnector
Download README (.md)
Explore Similar Repositories
sockjs-client-node
:
SockJS client for Node
ng2-STOMP-Over-WebSocket
:
STOMP Over WebSocket service for angular2
sockjs-unity3d-xhr
:
sockjs client implementation for unity3D using xhr polling (so this works with unity free license)
// repository documentation
Was this content helpful?
★ 0
(0 ratings)
Select Rating:
★
★
★
★
★
Submit Feedback
Recent Feedback
×
Download README
Do you want to download the
README.md
file for
sockjs_reconnect
?
Download (.md)
SockJS Reconnector ================== This is a small module for handling disconnects in the client while using SockJS. The reconnection proceeds in the following manner (by default): * When ```onclose``` is triggered, it first tries to reconnect immediately. * If it remains unconnected, another attempt is done after ```t = 1500 + x``` milliseconds, and then at ```2 * t```, ```4 * t```, ..., ```32 * t```. * If it is still unconnected, the multiplier is reset to ```1``` and the process is repeated. * If it does not connect after ```30``` attempts, it stops trying and performs a page reload. * In case ```onopen``` is triggered at any point, the parameters are reset to the initial values. All the parameters used above are configurable, and here is an example using the module (try stopping/starting the server): ```html <!DOCTYPE html> <html> <head> <script src="http://cdnjs.cloudflare.com/ajax/libs/zepto/1.0/zepto.min.js"> </script> <script src="http://cdn.sockjs.org/sockjs-0.3.min.js"></script> <script src="/static/sockjs_reconnect.min.js"></script> <script> /* Example usage. */ new_status = function(status) { $('#status').text(status); if (status === 'connected') { sock.send('ping'); } } on_message = function(msg) { $('#last-message').text(msg.data); setTimeout(function() { if (sock.conn) { sock.send('ping'); } }, 150); } var sock = new SockReconnect('/sock', null, new_status, on_message); if (window.addEventListener) { window.addEventListener('load', sock.connect, false); } else { window.attachEvent('onload', sock.connect); } </script> </head> <body> <p>Connection status: <span id="status">Disconnected</span></p> <p>Last message: <span id="last-message"></span></p> </body> </html> ```