u
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user