mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-11-25 09:46:58 +00:00
Add periodic stream heartbeat to stop disconnection/reconnection cycle
This commit is contained in:
1 parent
8672dbe1e9
commit
8d3edc7cd1
1 file changed
+15
@@ -12,6 +12,7 @@ const DEBUG = {
|
||||
|
||||
// Delays
|
||||
const REPORT_DELAY = config.get('REPORT_DELAY') || 30 * 60 * 1000; //ms
|
||||
const HEARTBEAT_DELAY = config.get('HEARTBEAT_DELAY') || 20 * 1000; //ms
|
||||
|
||||
|
||||
const Stream = new EventEmitter;
|
||||
@@ -47,6 +48,20 @@ const unsubscribe = function(id){
|
||||
subscribers = subscribers.filter((sub)=>{ return sub.id != id; });
|
||||
};
|
||||
|
||||
// Create heartbeat
|
||||
const heartbeatId = setInterval(()=>{
|
||||
if(DEBUG.showEvents){ console.log('STREAM HEARTBEAT @ ', new Date); };
|
||||
subscribers
|
||||
.forEach((sub)=>{
|
||||
sub?.stream?.write(`:\n\n`);
|
||||
});
|
||||
}, HEARTBEAT_DELAY);
|
||||
|
||||
Stream.on('close', ()=>{
|
||||
console.log('STREAM CLOSE');
|
||||
clearInterval(heartbeatId);
|
||||
});
|
||||
|
||||
// Create global sendUpdate listener
|
||||
Stream.on('sendUpdate', (event, data)=>{
|
||||
if(DEBUG.showEvents) console.log('Event:', event, '\nData:', data);
|
||||
|
||||
Reference in new issue
Block a user