v0.16.0
Better SSE Version 0.16.0
npm install better-sse@latestyarn add better-sse@latestpnpm add better-sse@latestThis release adds connection adapters that enable Better SSE to be truly be compatible with any protocol, framework or runtime environment.
Changes
Connection Adapters
Where sessions manage the request and response lifecycle, the formatting of data and other SSE-specific behaviour, connection adapters implement the underlying connection itself, such as extracting request headers and query parameters, sending response headers and data chunks, and reporting when the connection closes.
Sessions already use several built-in adapters to provide support for the Fetch API and Node HTTP/1 and HTTP/2 Compatibility APIs. Now, these adapters are made public and can be used to create your own custom compatibility layers simply by extending from one of the built-in adapters or the base Connection class itself and implementing its abstract properties and methods:
import { Connection } from "better-sse"
export class MyCustomConnection extends Connection {
url: URL
request: Request
response: Response
sendHead = (): void => {}
sendChunk = (chunk: string): void => {}
cleanup = (): void => {}
}import { createSession } from "better-sse"
import { MyCustomConnection } from "./MyCustomConnection"
app.get("/sse", async (req, res) => {
const connection = new MyCustomConnection()
const session = await createSession(connection)
session.push("Universal compatibility!")
})See the documentatin for more:
Full Changelog
Added
- Added support for passing custom connection adapters to the
Sessionconstructor that enables compatibility with any protocol, framework or runtime environment.
Changed
- Update event ID generation to use
randomUUIDfrom the Web Crypto API instead ofnode:crypto. - Update Node HTTP/1 and HTTP/2 Compatibility adapters to disable Nagle's algorithm on the underlying socket to reduce latency.
Fixed
- Fixed a warning being printed by the Node internals when adding more than ten listeners to events emitted by sessions and channels.
- Fixed a crash that occurred when passing a
Requestbut no correspondingResponseobject from the Fetch API to theSessionconstructor. - Fixed a crash that occurred when the request had no
Hostheader when using the Node HTTP/1 or Node HTTP/2 Compatibility API.