Source

utils/socket-events.js

let ioInstance = null;
/**
 * Attach a Socket.IO server instance so that other modules (e.g. controllers)
 * can emit real-time events without tight coupling to the HTTP bootstrap code.
 *
 * This should be called once during application startup from the place where
 * the Socket.IO server is created.
 * @param {SocketIOServer} io Socket.IO server instance.
 */
export function setSocketServer(io) {
    ioInstance = io;
}
/**
 * Get the currently registered Socket.IO server instance, if any.
 * @returns {SocketIOServer | null} Socket.IO server instance or null.
 */
export function getSocketServer() {
    return ioInstance;
}
/**
 * Emit an \"investigation:updated\" event to all subscribers of the given investigation room.
 * @param {string} investigationId Investigation identifier used as room name.
 * @param {object} payload Arbitrary payload to send with the event.
 * @param {string | null} payload.updatedBy The ID of the user who updated the investigation.
 * @param {string | null} payload.updatedAt The date and time the investigation was updated.
 * @param {unknown} payload.updatedFields The fields that were updated.
 */
export function emitInvestigationUpdated(investigationId, payload = {}) {
    if (!ioInstance || !investigationId) {
        return;
    }
    ioInstance.to(investigationId).emit("investigation:updated", {
        investigationId,
        ...payload,
    });
}