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,41 +744,51 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Listen on websockets and process messages from the server
|
function setupSocket() {
|
||||||
socket.addEventListener('message', e => {
|
// Open a global websocket
|
||||||
// Parse received data as JSON
|
socket = new WebSocket(
|
||||||
const data = JSON.parse(e.data)
|
(document.location.protocol === 'https:' ? 'wss' : 'ws') + '://' + window.location.host + '/ws/draw/'
|
||||||
|
)
|
||||||
|
|
||||||
processMessage(data['tid'], data)
|
// Listen on websockets and process messages from the server
|
||||||
})
|
socket.addEventListener('message', e => {
|
||||||
|
// Parse received data as JSON
|
||||||
|
const data = JSON.parse(e.data)
|
||||||
|
|
||||||
// Manage errors
|
processMessage(data['tid'], data)
|
||||||
socket.addEventListener('close', e => {
|
})
|
||||||
console.error('Chat socket closed unexpectedly')
|
|
||||||
})
|
|
||||||
|
|
||||||
// When the socket is opened, set the language in order to receive alerts in the good language
|
// Manage errors
|
||||||
socket.addEventListener('open', e => {
|
socket.addEventListener('close', e => {
|
||||||
socket.send(JSON.stringify({
|
console.error('Chat socket closed unexpectedly, restarting…')
|
||||||
'tid': tournaments[0].id,
|
setupSocket()
|
||||||
'type': 'set_language',
|
})
|
||||||
'language': document.getElementsByName('language')[0].value,
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
|
|
||||||
for (let tournament of tournaments) {
|
// When the socket is opened, set the language in order to receive alerts in the good language
|
||||||
// Manage the start form
|
socket.addEventListener('open', e => {
|
||||||
let format_form = document.getElementById('format-form-' + tournament.id)
|
socket.send(JSON.stringify({
|
||||||
if (format_form !== null) {
|
'tid': tournaments[0].id,
|
||||||
format_form.addEventListener('submit', function (e) {
|
'type': 'set_language',
|
||||||
e.preventDefault()
|
'language': document.getElementsByName('language')[0].value,
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
|
||||||
socket.send(JSON.stringify({
|
for (let tournament of tournaments) {
|
||||||
'tid': tournament.id,
|
// Manage the start form
|
||||||
'type': 'start_draw',
|
let format_form = document.getElementById('format-form-' + tournament.id)
|
||||||
'fmt': document.getElementById('format-' + tournament.id).value
|
if (format_form !== null) {
|
||||||
}))
|
format_form.addEventListener('submit', function (e) {
|
||||||
})
|
e.preventDefault()
|
||||||
|
|
||||||
|
socket.send(JSON.stringify({
|
||||||
|
'tid': tournament.id,
|
||||||
|
'type': 'start_draw',
|
||||||
|
'fmt': document.getElementById('format-' + tournament.id).value
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupSocket()
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue