Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jakearchibald/sse-fetcher
Server-sent events rewritten on top of fetch
https://github.com/jakearchibald/sse-fetcher
Last synced: 30 days ago
JSON representation
Server-sent events rewritten on top of fetch
- Host: GitHub
- URL: https://github.com/jakearchibald/sse-fetcher
- Owner: jakearchibald
- License: apache-2.0
- Created: 2018-09-27T15:18:01.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-10-30T14:25:28.000Z (about 6 years ago)
- Last Synced: 2024-08-10T21:28:24.279Z (3 months ago)
- Language: TypeScript
- Homepage:
- Size: 19.5 KB
- Stars: 18
- Watchers: 5
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SSEFetcher
This a class that reads server sent events using `fetch()`. It works in Edge (which doesn't support `EventSource`) if you have a `TextDecoder` polyfill.
## Usage
```js
const sse = new SSEFetcher(url, opts);
// opts.withCredentials - Send cookies to cross-origin URLs.
// opts.reconnectionDelay - Initial reconnection delay.(async function() {
while (true) {
const message = await sse.nextMessage();
console.log(message);
// message.data - Data sent
// message.type - Event type sent
}
})();// Later, stop events & close the connection.
sse.close();
```Demo: https://sse-fetcher.glitch.me/.
## Files
* `lib/index.ts` - Original typescript.
* `dist/SSEFetcher.mjs` - JS module. Default exports SSEFetcher.
* `dist/SSEFetcher.js` - Plain JS. Exposes SSEFetcher on the global.
* `dist/SSEFetcher-min.js` - Minified plain JS. 1k gzipped.