Added interval function to avoid disconnection
This commit is contained in:
parent
6a9305f7e9
commit
b5bd28fd45
20
ws_server.js
20
ws_server.js
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user