This commit is contained in:
seb
2026-10-09 17:55:45 +02:00
parent de7afbcbe9
commit 848ca0aff5
13 changed files with 331 additions and 48 deletions

View File

@@ -57,12 +57,13 @@ export function closeAll() {
/**
* Broadcast a named signal to subscribers of the given company.
* @param {string} signal - SSE event name (e.g. `category`)
* @param {{ companyId: number }} options
* @param {{ companyId: number, data?: string|object }} options
*/
export function emit(signal, { companyId }) {
export function emit(signal, { companyId, data }) {
if (companyId == null) return;
const frame = `event: ${signal}\ndata: {}\n\n`;
const payload = data == null ? '{}' : (typeof data === 'string' ? data : JSON.stringify(data));
const frame = `event: ${signal}\ndata: ${payload}\n\n`;
for (const client of clients) {
if (client.companyId !== companyId) continue;
if (client.res.writableEnded) continue;