mirror of
https://github.com/fosrl/pangolin.git
synced 2026-06-25 16:51:50 +00:00
Add batch messaging functions to rebuild function
This commit is contained in:
@@ -76,6 +76,12 @@ export interface SendMessageOptions {
|
||||
compress?: boolean;
|
||||
}
|
||||
|
||||
export interface BatchSendMessage {
|
||||
clientId: string;
|
||||
message: WSMessage;
|
||||
options?: SendMessageOptions;
|
||||
}
|
||||
|
||||
// Redis message types for cross-node communication
|
||||
export type RedisMessage =
|
||||
| {
|
||||
|
||||
@@ -26,7 +26,8 @@ import {
|
||||
WebSocketRequest,
|
||||
WSMessage,
|
||||
AuthenticatedWebSocket,
|
||||
SendMessageOptions
|
||||
SendMessageOptions,
|
||||
BatchSendMessage
|
||||
} from "./types";
|
||||
import { validateSessionToken } from "@server/auth/sessions/app";
|
||||
|
||||
@@ -212,6 +213,20 @@ const sendToClient = async (
|
||||
return localSent;
|
||||
};
|
||||
|
||||
const sendToClientsBatch = async (
|
||||
entries: BatchSendMessage[]
|
||||
): Promise<void> => {
|
||||
if (entries.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
entries.map((entry) =>
|
||||
sendToClient(entry.clientId, entry.message, entry.options)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const broadcastToAllExcept = async (
|
||||
message: WSMessage,
|
||||
excludeClientId?: string,
|
||||
@@ -552,6 +567,7 @@ export {
|
||||
router,
|
||||
handleWSUpgrade,
|
||||
sendToClient,
|
||||
sendToClientsBatch,
|
||||
broadcastToAllExcept,
|
||||
connectedClients,
|
||||
hasActiveConnections,
|
||||
|
||||
Reference in New Issue
Block a user