add huuuge stuff

This commit is contained in:
2022-11-14 00:53:09 +01:00
parent 0ddfa4d66f
commit 6aa6955fa8
30 changed files with 1768 additions and 72 deletions

52
src/WebSocketPayload.ts Normal file
View File

@ -0,0 +1,52 @@
import {WebSocketEvent} from "./WebSocketEvent";
export class WebSocketPayload {
set event(value: WebSocketEvent) {
this._event = value;
}
set status(value: boolean) {
this._status = value;
}
set data(value: object | undefined) {
this._data = value;
}
private _event: WebSocketEvent;
private _status: boolean;
private _data: object | undefined;
get event(): WebSocketEvent {
return this._event;
}
get status(): boolean {
return this._status;
}
get data(): object | undefined {
return this._data;
}
constructor(event: WebSocketEvent, status: boolean, data?: object) {
this._event = event;
this._status = status;
this._data = data;
}
public static parseFromJSON(json: string): WebSocketPayload | null {
json = (window) ? atob(json) : Buffer.from(json, "base64").toString();
let rawPayload: { event: string, status: boolean, data: object };
try {
rawPayload = JSON.parse(json);
} catch (e) {
return null;
}
let wsEvent = <keyof typeof WebSocketEvent> rawPayload.event;
return new WebSocketPayload(wsEvent, rawPayload.status, rawPayload.data);
}
}