Skip to content

v0.16.0

Choose a tag to compare

@MatthewWid MatthewWid released this 29 Dec 06:03
· 3 commits to master since this release

Better SSE Version 0.16.0

npm install better-sse@latest
yarn add better-sse@latest
pnpm add better-sse@latest

This 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 Session constructor that enables compatibility with any protocol, framework or runtime environment.

Changed

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 Request but no corresponding Response object from the Fetch API to the Session constructor.
  • Fixed a crash that occurred when the request had no Host header when using the Node HTTP/1 or Node HTTP/2 Compatibility API.