improve mailboxes
This commit is contained in:
+4
-18
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user