add restart if data stops for more than a second

This commit is contained in:
2023-11-24 13:53:49 -06:00
parent e4fa85f455
commit 002fdb6a8e
+11 -3
View File
@@ -24,6 +24,7 @@ if (!options.device) {
} }
let ws; let ws;
let updateTimeout;
if (options.websocket) { if (options.websocket) {
ws = new WebSocketServer({ port: options.websocket }); ws = new WebSocketServer({ port: options.websocket });
} }
@@ -52,7 +53,14 @@ port.on('data', (data) => {
if (aasConsole) { if (aasConsole) {
try { try {
aasConsole.update(data); aasConsole.update(data);
console.log('app: console data updated'); console.log('app: console state update received');
if (updateTimeout) {
clearTimeout(updateTimeout);
}
updateTimeout = setTimeout(() => {
console.log('app: console update timed out re-initializing');
aasConsole.reset();
}, 1000);
if (ws) { if (ws) {
sendToWSClients({ sendToWSClients({
eventName: 'update', eventName: 'update',
@@ -74,9 +82,9 @@ port.on('data', (data) => {
} }
}); });
const initializeInterval = setInterval(function initialize() { const initializeInterval = setInterval(() => {
if (aasConsole.sportInitialized) { if (aasConsole.sportInitialized) {
clearInterval(this); console.log('app: console is already initialized');
} else if (port) { } else if (port) {
console.log('app: requesting console data to start streaming'); console.log('app: requesting console data to start streaming');
port.write(Packets.START_LIVE); port.write(Packets.START_LIVE);