mirror of
https://github.com/jwetzell/aas-js.git
synced 2026-08-20 12:29:04 +00:00
add restart if data stops for more than a second
This commit is contained in:
+11
-3
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user