Stream name (key of App.Events)
Create a new server-side SSE stream helper.
Stream name (key of App.Events)
Stream name (key of App.Events) used for typing and debug output.
Optional configuration (serializer, ping/retry intervals, debug logger).
ReadonlyoffUnsubscribe from lifecycle events from unsafe.events.
Alias for emitter.removeListener().
ReadonlyonSubscribe to lifecycle events from unsafe.events.
Adds the listener function to the end of the listeners array for the
event named eventName. No checks are made to see if the listener has
already been added. Multiple calls passing the same combination of eventName
and listener will result in the listener being added, and called, multiple
times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The
emitter.prependListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
The name of the event.
The callback function
ReadonlyonceSubscribe once to lifecycle events from unsafe.events.
Adds a one-time listener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
Returns a reference to the EventEmitter, so that calls can be chained.
By default, event listeners are invoked in the order they are added. The
emitter.prependOnceListener() method can be used as an alternative to add the
event listener to the beginning of the listeners array.
import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
The name of the event.
The callback function
ReadonlyunsafeAdvanced/unsafe APIs.
Use these only if you know SSE formatting rules and accept losing type safety.
Lifecycle events (open, close, ping) for the SSE stream.
Send an arbitrary SSE message.
Whether the stream is currently open and writable.
Note: This becomes false when the client disconnects (stream cancel).
The configured stream name (key of App.Events).
Emit an application event to the client.
The event name is taken from App.Events[S] and payload is typed accordingly.
true if written; false if the stream is not open.
Create a SvelteKit Response that streams Server-Sent Events.
Optionalinit: ResponseInitOptional ResponseInit to merge headers/status.
A Response with Content-Type: text/event-stream.
Request the client to close the connection.
This method emits a protocol-level "magic" message over the SSE stream.
IMPORTANT:
true if the magic close request was written; false if stream is not open.
Server-side SSE stream helper for SvelteKit endpoints.
This class creates a
Responsestreamingtext/event-streamdata and provides a typed emit method for sending application events based onApp.Events.It also implements a small control protocol (magic events) used for server-requested termination via stop. Control messages MUST be decodable regardless of any user-defined serializer/deserializer.
Example