From 002fdb6a8ecefc245a148b587ce58ddd9dfd0bec Mon Sep 17 00:00:00 2001 From: Joel Wetzell Date: Fri, 24 Nov 2023 13:53:49 -0600 Subject: [PATCH] add restart if data stops for more than a second --- packages/cli/index.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/cli/index.js b/packages/cli/index.js index ec3511b..5290ab9 100755 --- a/packages/cli/index.js +++ b/packages/cli/index.js @@ -24,6 +24,7 @@ if (!options.device) { } let ws; +let updateTimeout; if (options.websocket) { ws = new WebSocketServer({ port: options.websocket }); } @@ -52,7 +53,14 @@ port.on('data', (data) => { if (aasConsole) { try { 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) { sendToWSClients({ eventName: 'update', @@ -74,9 +82,9 @@ port.on('data', (data) => { } }); -const initializeInterval = setInterval(function initialize() { +const initializeInterval = setInterval(() => { if (aasConsole.sportInitialized) { - clearInterval(this); + console.log('app: console is already initialized'); } else if (port) { console.log('app: requesting console data to start streaming'); port.write(Packets.START_LIVE);