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
const sse = url opts;// opts.withCredentials - Send cookies to cross-origin URLs.// opts.reconnectionDelay - Initial reconnection delay. { while true const message = await sse; console; // message.data - Data sent // message.type - Event type sent }; // Later, stop events & close the connection.sse;
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.