improve mailboxes

This commit is contained in:
marlon-erler
2024-07-08 23:34:16 +02:00
parent 93658124cc
commit a8186e79be
13 changed files with 260 additions and 187 deletions
+4 -18
View File
@@ -1,14 +1,11 @@
import { Mailbox, Subscriber } from "./subscriptionHandler";
import { PACKAGE_FILE, STATIC_DIR, WS } from ".";
import {
WebSocketMessage,
mailboxIdsPerClient,
mailboxes,
} from "./websocket-handler";
import Colors from "colors";
import Fs from "fs/promises";
import Path from "path";
import {
WebSocketMessage,
} from "./websocket-handler";
// CONFIG
const STAT_INDENT = 25;
@@ -69,15 +66,4 @@ export function stringifyMessage(messageObject: WebSocketMessage): string {
export function parseMessage(messageString: string): Object {
return JSON.parse(messageString);
}
// SUBSCRIBERS
export function getMailboxIfExists(ws: WS): Mailbox | undefined {
const id = mailboxIdsPerClient.get(ws);
if (!id) return;
return mailboxes.get(id);
}
export function getMostAppropriateSubscriber(ws: WS): Subscriber {
return getMailboxIfExists(ws) ?? ws;
}
}