better-sse
Advanced tools
Changelog
0.13.0 - 2024-08-23
state
property in the Session
and Channel
constructor options
objects.State
generics passed to Session
and Channel
extend from Record<string, unknown>
.Changelog
0.11.0 - 2024-02-08
SseError
custom error object that wraps all thrown errors.Session#push
method to throw if the session is not connected.Changelog
0.10.0 - 2023-09-28
Session#batch
method that can be used to batch multiple events into a single transmission over the wire.EventBuffer
class that can be used to write raw spec-compliant SSE fields into a text buffer that can be sent directly over the wire..event
, .data
, .id
, .retry
, .comment
, .dispatch
and .flush
methods in favour of using event buffers instead.Changelog
0.9.0 - 2023-08-14
state
property of sessions registered with a Channel via an optional second generic argument to the Channel
constructor.DefaultChannelState
interface that may be used via module augmentation to alter the default channel state type for all channels.SessionState
interface to be named DefaultSessionState
.Changelog
0.8.0 - 2022-06-02
Session#flush
method.Pragma
, X-Accel-Buffering
headers and add additional values to the Cache-Control
default header to further disable all forms of caching.Http2ServerRequest
and Http2ServerResponse
objects to the Session
constructor req
and res
parameters, respectively.Session#event
, Session#data
, Session#id
, Session#retry
and Session#comment
methods to write to the internal data buffer instead of sending the field data over the wire immediately.Session#dispatch
method to only write a newline (and to the internal data buffer) and not flush the written data to the client.Channel#broadcast
method to generate its own custom event ID and thus add it as an additional argument to its broadcast
event callback function.Channel#register
and Channel#deregister
to not do anything if the channel is already registered or deregistered, respectively.Session
constructor options header
field to overwrite conflicting default headers instead of being ignored.session-disconnected
being fired after instead of before the session is deregistered.null
to Session#id
. Give no arguments at all instead.Changelog
0.7.0 - 2022-01-08
Session#push
method to set a custom event ID.push
event that is emitted with the event data, name and ID when the Session#push
method is called.Channel#state
property to have a safe namespace for keeping information attached to the channel.Session#push
and Channel#broadcast
methods and their corresponding emitted event callbacks to always have the event data first and event name as an optional argument second.Channel#broadcast
method options TypeScript typings to explicitly mandate a boolean
return-type instead of allowing any truthy or falsy value.Channel#broadcast
method event name argument to be optional and default to "message"
if not given.Session#state
generic argument to default to a new SessionState
interface that can be augmented via declaration merging to override the session state type for all session objects without explicitly providing a generic argument to each reference to Session
.Events
interfaces to SessionEvents
and ChannelEvents
respectively and export them publicly allowing the user to properly type non-inlined event handler callback functions.Changelog
0.6.0 - 2021-10-28
Session#iterate
method that allows processing iterables and sending yielded values to the client as events.Session
and Channel
event listener callback function arguments.Session#state
using an optional generic argument for createSession
and the Session
constructor.Session#stream
event
option to eventName
.