attempt client reconnection of closed websockets
This commit is contained in:
parent
7e519c4736
commit
abe3c9f8aa
@ -1,6 +1,4 @@
|
|||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
console.log('window.onload');
|
|
||||||
|
|
||||||
var play_log = document.getElementById('play-log');
|
var play_log = document.getElementById('play-log');
|
||||||
var last_tag = document.getElementById('last-tag');
|
var last_tag = document.getElementById('last-tag');
|
||||||
|
|
||||||
@ -10,9 +8,24 @@ window.onload = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var host = window.document.location.host.replace(/:.*/, '');
|
var host = window.document.location.host.replace(/:.*/, '');
|
||||||
var ws = new WebSocket('ws://' + host + ':' + jukebox.port);
|
var ws;
|
||||||
ws.onmessage = function (event) {
|
|
||||||
updateLog(JSON.parse(event.data));
|
|
||||||
};
|
|
||||||
|
|
||||||
|
function connectWebsocket() {
|
||||||
|
console.log('Attempting WebSocket connection...');
|
||||||
|
ws = new WebSocket('ws://' + host + ':' + jukebox.port);
|
||||||
|
ws.addEventListener('open', function(event) {
|
||||||
|
console.log('WebSocket connection opened.');
|
||||||
|
});
|
||||||
|
ws.addEventListener('message', function(event) {
|
||||||
|
updateLog(JSON.parse(event.data));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setInterval(function() {
|
||||||
|
if (ws.readyState == WebSocket.CLOSED) {
|
||||||
|
connectWebsocket();
|
||||||
|
}
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
connectWebsocket();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user