mirror of
https://github.com/BreizhHardware/Jellystat.git
synced 2026-01-18 16:27:20 +01:00
task manager implementation to start/stop tasks WIP implemented socket client for internal communication between threads - needs more testing as connection string is hardcoded added loopback in ws server to pass through toast ws messages from threads - needs more testing fixed potential bug during config fetch function when syncing
31 lines
599 B
JavaScript
31 lines
599 B
JavaScript
const io = require("socket.io-client");
|
|
|
|
class SocketIoClient {
|
|
constructor(serverUrl) {
|
|
this.serverUrl = serverUrl;
|
|
this.client = null;
|
|
}
|
|
|
|
connect() {
|
|
this.client = io(this.serverUrl);
|
|
}
|
|
|
|
waitForConnection() {
|
|
return new Promise((resolve) => {
|
|
if (this.client && this.client.connected) {
|
|
resolve();
|
|
} else {
|
|
this.client.on("connect", resolve);
|
|
}
|
|
});
|
|
}
|
|
|
|
sendMessage(message) {
|
|
if (this.client && this.client.connected) {
|
|
this.client.emit("message", JSON.stringify(message));
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = SocketIoClient;
|