formatSseEvent
Formats one event as the bytes of the stream: retry, id, event, then one data line per line of the payload, then the blank line that ends the event.
Formats one event as the bytes of the stream: retry, id, event, then one data line per line
of the payload, then the blank line that ends the event.
Import#
ts
import { formatSseEvent } from "@shadow-js/dusk/server";
Signature#
ts
function formatSseEvent(message: SseMessage | string): string
Parameters#
| Name | Description |
|---|---|
message |
The event, or a string for an unnamed event with that data. |
Returns#
The text to write.
Throws#
- TypeError for an id or event name with a line break or NUL, or a payload that is not JSON.
- RangeError for a
retrythat is not a non-negative integer, or an event over 64 KiB.
Examples#
ts
formatSseEvent({ id: "7", event: "tick", data: "a\nb" }); // "id: 7\nevent: tick\ndata: a\ndata: b\n\n"