websocket reconnects automatically
This commit is contained in:
parent
1c179843f6
commit
84ac3813ed
|
@ -1,7 +1,7 @@
|
||||||
var socket;
|
var socket;
|
||||||
|
|
||||||
function load() {
|
function load() {
|
||||||
socket = init_websocket();
|
init_websocket();
|
||||||
document.querySelector('#player').addEventListener('ended', function() {
|
document.querySelector('#player').addEventListener('ended', function() {
|
||||||
if (document.querySelector('#shuffle').checked) {
|
if (document.querySelector('#shuffle').checked) {
|
||||||
socket.send_event('random_track', {});
|
socket.send_event('random_track', {});
|
||||||
|
@ -11,16 +11,18 @@ function load() {
|
||||||
|
|
||||||
/* Websocket setup */
|
/* Websocket setup */
|
||||||
function init_websocket() {
|
function init_websocket() {
|
||||||
let socket = new WebSocket('wss://' + window.location.hostname + ws_uri);
|
let _socket;
|
||||||
socket.send_event = send_event;
|
_socket = new WebSocket('wss://' + window.location.hostname + ws_uri);
|
||||||
socket.onmessage = onmessage;
|
_socket.send_event = send_event;
|
||||||
socket.onclose = onclose;
|
_socket.onopen = onopen;
|
||||||
socket.onerror = onerror;
|
_socket.onmessage = onmessage;
|
||||||
socket.events = {};
|
_socket.onclose = onclose;
|
||||||
socket.events['artist_albums'] = artist_albums_recv;
|
_socket.onerror = onerror;
|
||||||
socket.events['album_tracks'] = album_tracks_recv;
|
_socket.events = {};
|
||||||
socket.events['track'] = track_recv;
|
_socket.events['artist_albums'] = artist_albums_recv;
|
||||||
return socket;
|
_socket.events['album_tracks'] = album_tracks_recv;
|
||||||
|
_socket.events['track'] = track_recv;
|
||||||
|
window.socket = _socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
function send_event(event_title, data) {
|
function send_event(event_title, data) {
|
||||||
|
@ -79,7 +81,7 @@ async function onclose(event) {
|
||||||
console.log(event);
|
console.log(event);
|
||||||
console.log('Websocket lost connection to server. Re-trying...');
|
console.log('Websocket lost connection to server. Re-trying...');
|
||||||
await sleep(3000);
|
await sleep(3000);
|
||||||
socket = init_websocket();
|
init_websocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
function sleep(ms) {
|
function sleep(ms) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user