Added interval function to avoid disconnection

This commit is contained in:
Eunchong Kim 2021-08-08 14:11:26 +09:00
parent 6a9305f7e9
commit b5bd28fd45

View File

@ -27,7 +27,7 @@ wss.on('connection', (ws) => {
// Brige data to all clients // Brige data to all clients
ws.onmessage = function(evt) { ws.onmessage = function(evt) {
console.log(evt.data); console.log(evt.data);
wss.clients.forEach((client) => { wss.clients.forEach( (client) => {
client.send(evt.data); client.send(evt.data);
}); });
} }
@ -40,9 +40,15 @@ wss.on('connection', (ws) => {
}); });
// Broadcast updates // Send message every 30 s
//setInterval(() => { // Because Heroku terminate connection in 55 s inactivity
// wss.clients.forEach((client) => { // https://devcenter.heroku.com/articles/error-codes#h15-idle-connection
// client.send(new Date().toTimeString()); setInterval( () => {
// }); var data = {
//}, 1000); ctrl: 'idle',
time: new Date().toTimeString()
}
wss.clients.forEach( (client) => {
client.send( data );
});
}, 30000); // 30 s