This commit is contained in:
2022-11-14 15:41:11 +01:00
parent 1380575845
commit a7fac21442
17 changed files with 236 additions and 63 deletions

33
src/WebSocketHandler.ts Normal file
View File

@ -0,0 +1,33 @@
import {WebSocketPayload} from "./WebSocketPayload";
export class WebSocketHandler {
private static _ws: WebSocket;
static get ws(): WebSocket {
return this._ws;
}
static set ws(value: WebSocket) {
this._ws = value;
}
public static send(payload: WebSocketPayload): Promise<void> {
return new Promise(async (resolve, reject) => {
try {
if( this.ws && this.ws.readyState == 1 )
{
await this.ws.send(payload.toString());
resolve();
}
else
{
reject("Websocket is not connected!");
}
} catch (e) {
reject(e);
}
});
}
}