42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import * as Y from "yjs";
|
|
|
|
export interface missionStoreModel {
|
|
missionId: string;
|
|
doc: Y.Doc;
|
|
timestamp: number;
|
|
}
|
|
|
|
/**
|
|
* @description store credentials to socket to prevent auth data change while connected
|
|
*/
|
|
export abstract class MissionMap {
|
|
private static store = new Map<string, missionStoreModel>();
|
|
|
|
public static write(identifier: string, data: missionStoreModel, overwrite: boolean = false): void {
|
|
if (!this.exists(identifier) || overwrite) this.store.set(identifier, data);
|
|
}
|
|
|
|
public static updateState(identifier: string, data: Uint8Array): void {
|
|
let mission = this.read(identifier);
|
|
Y.applyUpdate(mission.doc, data);
|
|
this.write(identifier, mission, true);
|
|
}
|
|
|
|
public static updateTimestamp(identifier: string, data: number): void {
|
|
let mission = this.read(identifier);
|
|
mission.timestamp = data;
|
|
this.write(identifier, mission, true);
|
|
}
|
|
|
|
public static read(identifier: string): missionStoreModel {
|
|
return this.store.get(identifier);
|
|
}
|
|
|
|
public static exists(identifier: string): boolean {
|
|
return this.store.has(identifier);
|
|
}
|
|
|
|
public static delete(identifier: string): void {
|
|
this.store.delete(identifier);
|
|
}
|
|
}
|