Build & Deploy / build-and-push (backend) (push) Failing after 35s
Build & Deploy / build-and-push (discord-gateway) (push) Failing after 25s
Build & Deploy / build-and-push (proxy) (push) Failing after 25s
- Remove pnpm workspace, moon repo, and all monorepo tooling - Delete packages/shared/, embed shared code directly into each service - Copy packages/shared/src/* -> services/backend/src/shared/ and services/discord-gateway/src/shared/ - Replace all @bete/shared imports with @/shared/ path alias - Remove @bete/shared workspace dependency from both services - Update root package.json scripts from --filter to --prefix - Rewrite Dockerfiles to build each service standalone - Clean up biome.json, .gitignore, remove root drizzle.config.ts
72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
/**
|
|
* Broadcast functions for WebSocket events.
|
|
*
|
|
* These are injected by ws/server.ts when the WebSocket server initializes.
|
|
* Other modules call them to push real-time events to connected frontend clients.
|
|
*
|
|
* Usage:
|
|
* import { broadcastEvent } from "../ws/broadcast.js";
|
|
* broadcastEvent("message_created", messageData);
|
|
*/
|
|
|
|
import { createChildLogger } from "@/shared/logger/index";
|
|
|
|
const logger = createChildLogger("broadcast");
|
|
|
|
type BroadcastFn = (type: string, data: unknown) => void;
|
|
type BroadcastBinaryFn = (data: Buffer) => void;
|
|
|
|
let _broadcast: BroadcastFn | null = null;
|
|
let _broadcastBinary: BroadcastBinaryFn | null = null;
|
|
|
|
let _enabled = true;
|
|
|
|
/** Enable or disable broadcast logging (disabled by default to reduce noise). */
|
|
export function setBroadcastLogging(enabled: boolean): void {
|
|
_enabled = enabled;
|
|
}
|
|
|
|
/**
|
|
* Inject broadcast functions from the WebSocket server initializer.
|
|
* Must be called once during server startup before any broadcast is used.
|
|
*/
|
|
export function setBroadcastFunctions(
|
|
bf: BroadcastFn,
|
|
bfBinary: BroadcastBinaryFn,
|
|
): void {
|
|
_broadcast = bf;
|
|
_broadcastBinary = bfBinary;
|
|
logger.info("Broadcast functions initialized");
|
|
}
|
|
|
|
/** Clear injected functions (used during cleanup). */
|
|
export function clearBroadcastFunctions(): void {
|
|
_broadcast = null;
|
|
_broadcastBinary = null;
|
|
logger.info("Broadcast functions cleared");
|
|
}
|
|
|
|
function shouldLog(type: string): boolean {
|
|
if (!_enabled) return false;
|
|
// Avoid logging high-volume events
|
|
if (type === "voice_pcm_data") return false;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Broadcast a JSON event to all connected WebSocket clients.
|
|
*/
|
|
export function broadcastEvent(type: string, data: unknown): void {
|
|
if (shouldLog(type)) {
|
|
logger.debug({ event: type }, "Broadcasting event");
|
|
}
|
|
_broadcast?.(type, data);
|
|
}
|
|
|
|
/**
|
|
* Broadcast binary data to all connected WebSocket clients.
|
|
*/
|
|
export function broadcastBinary(data: Buffer): void {
|
|
_broadcastBinary?.(data);
|
|
}
|