Keep trying to connect in case the websocket goes down
This commit is contained in:
parent
75e958bb38
commit
d380e0f398
1 changed files with 6 additions and 2 deletions
|
@ -1,7 +1,7 @@
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
var websocket,
|
var websocket,
|
||||||
dateTimeInterval,
|
dateTimeInterval,
|
||||||
websocketReconnectTimeout,
|
websocketReconnectInterval,
|
||||||
eventListeners = [];
|
eventListeners = [];
|
||||||
|
|
||||||
var initWebsocket = function() {
|
var initWebsocket = function() {
|
||||||
|
@ -19,6 +19,10 @@ $(document).ready(function() {
|
||||||
|
|
||||||
websocket.onopen = function(event) {
|
websocket.onopen = function(event) {
|
||||||
console.log('Websocket connection successful');
|
console.log('Websocket connection successful');
|
||||||
|
if (websocketReconnectInterval) {
|
||||||
|
clearInterval(websocketReconnectInterval);
|
||||||
|
websocketReconnectInterval = undefined;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
websocket.onerror = function(event) {
|
websocket.onerror = function(event) {
|
||||||
|
@ -27,7 +31,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
websocket.onclose = function(event) {
|
websocket.onclose = function(event) {
|
||||||
console.log('Websocket closed, code: ' + event.code);
|
console.log('Websocket closed, code: ' + event.code);
|
||||||
websocketReconnectTimeout = setTimeout(function() {
|
websocketReconnectInterval = setInterval(function() {
|
||||||
initWebsocket();
|
initWebsocket();
|
||||||
}, 5000);
|
}, 5000);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue