Files
Jellystat/backend/socket-io-client.js
CyferShepard 81fe4997d1 task scheduler rework
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
2025-03-04 22:23:34 +02:00

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;