better-sse 0.14.0 → 0.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -11
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -30,17 +30,17 @@ Compared to WebSockets it has comparable performance and bandwidth usage, especi
|
|
|
30
30
|
* Compatible with all popular Node HTTP frameworks ([Express](https://nodejs.org/api/http.html), [Fastify](https://fastify.dev/), [Nest](https://nestjs.com/), [Next.js](https://nextjs.org/), etc.)
|
|
31
31
|
* Fully written in TypeScript (+ ships with types directly).
|
|
32
32
|
* [Thoroughly tested](./src/Session.test.ts) (+ 100% code coverage!).
|
|
33
|
-
* [Comprehensively documented](
|
|
34
|
-
* [Channels](
|
|
33
|
+
* [Comprehensively documented](https://matthewwid.github.io/better-sse) with guides and API documentation.
|
|
34
|
+
* [Channels](https://matthewwid.github.io/better-sse/guides/channels) allow you to broadcast events to many clients at once.
|
|
35
35
|
* Configurable reconnection time, message serialization and data sanitization (with good defaults).
|
|
36
36
|
* Trust or ignore the client-given last event ID.
|
|
37
37
|
* Automatically send keep-alive pings to keep connections open.
|
|
38
38
|
* Add or override the response status code and headers.
|
|
39
|
-
* Send [individual fields](
|
|
39
|
+
* Send [individual fields](https://matthewwid.github.io/better-sse/guides/batching#send-individual-event-fields) of events or send [full events with simple helpers](https://matthewwid.github.io/better-sse/reference/api/#sessionpush-data-unknown-eventname-string-eventid-string--this).
|
|
40
40
|
* Pipe [streams](https://nodejs.org/api/stream.html#stream_readable_streams) and [iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators) directly from the server to the client as a series of events.
|
|
41
41
|
* Support for popular EventSource polyfills [`event-source-polyfill`](https://www.npmjs.com/package/event-source-polyfill) and [`eventsource-polyfill`](https://www.npmjs.com/package/eventsource-polyfill).
|
|
42
42
|
|
|
43
|
-
[See a comparison with other Node SSE libraries in the documentation.](
|
|
43
|
+
[See a comparison with other Node SSE libraries in the documentation.](https://matthewwid.github.io/better-sse/reference/comparison)
|
|
44
44
|
|
|
45
45
|
# Installation
|
|
46
46
|
|
|
@@ -61,11 +61,11 @@ _Better SSE ships with types built in. No need to install from DefinitelyTyped f
|
|
|
61
61
|
|
|
62
62
|
The following example shows usage with [Express](http://expressjs.com/), but Better SSE works with any web-server framework that uses the underlying Node [HTTP module](https://nodejs.org/api/http.html).
|
|
63
63
|
|
|
64
|
-
See the [Recipes](
|
|
64
|
+
See the [Recipes](https://matthewwid.github.io/better-sse/reference/recipes/) section of the documentation for use with other frameworks and libraries.
|
|
65
65
|
|
|
66
66
|
---
|
|
67
67
|
|
|
68
|
-
Use [sessions](
|
|
68
|
+
Use [sessions](https://matthewwid.github.io/better-sse/reference/api/#sessionstate) to push events to clients:
|
|
69
69
|
|
|
70
70
|
```typescript
|
|
71
71
|
// Server
|
|
@@ -87,7 +87,7 @@ sse.addEventListener("message", ({ data }) => {
|
|
|
87
87
|
});
|
|
88
88
|
```
|
|
89
89
|
|
|
90
|
-
Use [channels](
|
|
90
|
+
Use [channels](https://matthewwid.github.io/better-sse/reference/api/#channelstate-sessionstate) to send events to many clients at once:
|
|
91
91
|
|
|
92
92
|
```typescript
|
|
93
93
|
import { createSession, createChannel } from "better-sse";
|
|
@@ -103,7 +103,7 @@ app.get("/sse", async (req, res) => {
|
|
|
103
103
|
});
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
Loop over sync and async [iterables](
|
|
106
|
+
Loop over sync and async [iterables](https://matthewwid.github.io/better-sse/reference/api/#sessioniterate-iterable-iterable--asynciterable-options-object--promisevoid) and send each value as an event:
|
|
107
107
|
|
|
108
108
|
```typescript
|
|
109
109
|
const session = await createSession(req, res);
|
|
@@ -113,7 +113,7 @@ const list = [1, 2, 3];
|
|
|
113
113
|
await session.iterate(list);
|
|
114
114
|
```
|
|
115
115
|
|
|
116
|
-
Pipe [readable stream](
|
|
116
|
+
Pipe [readable stream](https://matthewwid.github.io/better-sse/reference/api/#sessionstream-stream-readable-options-object--promiseboolean) data to the client as a stream of events:
|
|
117
117
|
|
|
118
118
|
```typescript
|
|
119
119
|
const session = await createSession(req, res);
|
|
@@ -125,11 +125,11 @@ await session.stream(stream);
|
|
|
125
125
|
|
|
126
126
|
---
|
|
127
127
|
|
|
128
|
-
Check the [API documentation](
|
|
128
|
+
Check the [API documentation](https://matthewwid.github.io/better-sse/reference/api) and [live examples](./examples) for information on getting more fine-tuned control over your data such as managing event IDs, data serialization, event filtering, dispatch controls and more!
|
|
129
129
|
|
|
130
130
|
# Documentation
|
|
131
131
|
|
|
132
|
-
API documentation, getting started guides and usage with other frameworks is [available on
|
|
132
|
+
API documentation, getting started guides and usage with other frameworks is [available on the documentation website](https://matthewwid.github.io/better-sse/).
|
|
133
133
|
|
|
134
134
|
# Contributing
|
|
135
135
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "better-sse",
|
|
3
3
|
"description": "Dead simple, dependency-less, spec-compliant server-sent events implementation for Node, written in TypeScript.",
|
|
4
|
-
"version": "0.14.
|
|
4
|
+
"version": "0.14.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Matthew W. <matthew.widdi@gmail.com>",
|
|
7
7
|
"repository": "github:MatthewWid/better-sse",
|
|
8
|
-
"homepage": "https://github.
|
|
8
|
+
"homepage": "https://matthewwid.github.io/better-sse",
|
|
9
9
|
"bugs": "https://github.com/MatthewWid/better-sse/issues",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"server-sent-events",
|