Auto-restart the draw socket on close
Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
parent
0c80385958
commit
6b962a74b3
|
@ -108,12 +108,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
elem => elem.addEventListener(
|
elem => elem.addEventListener(
|
||||||
'click', () => document.location.hash = '#' + elem.innerText.toLowerCase()))
|
'click', () => document.location.hash = '#' + elem.innerText.toLowerCase()))
|
||||||
|
|
||||||
// Open a global websocket
|
|
||||||
socket = new WebSocket(
|
|
||||||
(document.location.protocol === 'https:' ? 'wss' : 'ws') + '://' + window.location.host
|
|
||||||
+ '/ws/draw/'
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add alert message on the top on the interface.
|
* Add alert message on the top on the interface.
|
||||||
* @param message The content of the alert.
|
* @param message The content of the alert.
|
||||||
|
@ -750,6 +744,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setupSocket() {
|
||||||
|
// Open a global websocket
|
||||||
|
socket = new WebSocket(
|
||||||
|
(document.location.protocol === 'https:' ? 'wss' : 'ws') + '://' + window.location.host + '/ws/draw/'
|
||||||
|
)
|
||||||
|
|
||||||
// Listen on websockets and process messages from the server
|
// Listen on websockets and process messages from the server
|
||||||
socket.addEventListener('message', e => {
|
socket.addEventListener('message', e => {
|
||||||
// Parse received data as JSON
|
// Parse received data as JSON
|
||||||
|
@ -760,7 +760,8 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
|
||||||
// Manage errors
|
// Manage errors
|
||||||
socket.addEventListener('close', e => {
|
socket.addEventListener('close', e => {
|
||||||
console.error('Chat socket closed unexpectedly')
|
console.error('Chat socket closed unexpectedly, restarting…')
|
||||||
|
setupSocket()
|
||||||
})
|
})
|
||||||
|
|
||||||
// When the socket is opened, set the language in order to receive alerts in the good language
|
// When the socket is opened, set the language in order to receive alerts in the good language
|
||||||
|
@ -787,4 +788,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setupSocket()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue