Skip to content

Commit

Permalink
streamdeck-plugin-vue: some changes to backend class
Browse files Browse the repository at this point in the history
  • Loading branch information
zoton2 committed Jan 12, 2022
1 parent b7a995b commit d4de394
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ dist
.yarn/install-state.gz
.pnp.*

streamdeck-plugin/Release/com.zoton2.example.streamDeckPlugin
com.zoton2.example.streamDeckPlugin
DistributionTool.exe
streamdeck-plugin-vue/com.zoton2.example.sdPlugin
16 changes: 12 additions & 4 deletions streamdeck-plugin-vue/src/backend/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ class Backend extends EventEmitter {
});
}

/**
* Helper function to send messages to the Stream Deck WebSocket server if connection is ready.
*/
sendToSDWS(data: unknown): void {
if (this.sdWS && this.sdWS.readyState === 1) {
const str = typeof data !== 'string' ? JSON.stringify(data) : data;
this.sdWS.send(str);
}
}

/**
* node-streamdeck-util connection.
*/
Expand Down Expand Up @@ -163,15 +173,13 @@ class Backend extends EventEmitter {
console.warn('Connection to node-streamdeck-util server closed (%s)', e.code);
this.toggleBackendConnectionStatus(false);
clearTimeout(this.serverWSReconnTimeout);
this.serverWSReconnTimeout = setTimeout(this.connectToServerWS, 5000);
this.serverWSReconnTimeout = setTimeout(() => { this.connectToServerWS(); }, 5000);
}, { once: true });

// Relays any messages sent from the node-streamdeck-util server to the main socket.
this.serverWS.addEventListener('message', (e) => {
const { data } = e;
if (this.sdWS && this.sdWS.readyState === 1) {
this.sdWS.send(data);
}
this.sendToSDWS(data);
});
}

Expand Down

0 comments on commit d4de394

Please sign in to comment.