Making the websocket reconnect client-side logic a bit more consistent
This commit is contained in:
parent
10bf54f961
commit
f3d725c890
1 changed files with 9 additions and 6 deletions
|
@ -4,7 +4,7 @@ $(document).ready(function() {
|
||||||
openedWebsocket,
|
openedWebsocket,
|
||||||
dateTimeInterval,
|
dateTimeInterval,
|
||||||
websocketTimeoutId,
|
websocketTimeoutId,
|
||||||
websocketReconnectMsecs = 4000,
|
websocketReconnectMsecs = 5000,
|
||||||
eventListeners = [];
|
eventListeners = [];
|
||||||
|
|
||||||
var initWebsocket = function() {
|
var initWebsocket = function() {
|
||||||
|
@ -15,14 +15,14 @@ $(document).ready(function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pendingConnection = websocket;
|
pendingConnection = true;
|
||||||
|
|
||||||
var onWebsocketTimeout = function(sock) {
|
var onWebsocketTimeout = function(self) {
|
||||||
return function() {
|
return function() {
|
||||||
console.log('Websocket reconnection timed out, retrying');
|
console.log('Websocket reconnection timed out, retrying');
|
||||||
pendingConnection = false;
|
pendingConnection = false;
|
||||||
sock.close();
|
self.close();
|
||||||
sock.onclose({ code: 1000 });
|
self.onclose();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -65,7 +65,10 @@ $(document).ready(function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
websocket.onclose = function(event) {
|
websocket.onclose = function(event) {
|
||||||
console.log('Websocket closed, code: ' + event.code);
|
if (event) {
|
||||||
|
console.log('Websocket closed - code: ' + event.code + ' - reason: ' + event.reason);
|
||||||
|
}
|
||||||
|
|
||||||
openedWebsocket = undefined;
|
openedWebsocket = undefined;
|
||||||
|
|
||||||
if (!pendingConnection) {
|
if (!pendingConnection) {
|
||||||
|
|
Loading…
Reference in a new issue