Koa.js middleware to stream events (using Server Sent Events) to clients without WebSockets.
- 🎉 First class Typescript support
- 📡 Realtime events over plain HTTP
- 💡 Serve as a REST endpoint route
- ☁️ Stateless by design
- 👌 Simple unopinionated API
$ npm install --save koa-event-stream
...
$ yarn add koa-event-stream
...
import * as Koa from "koa";
import KoaSSE from "../../src/index";
const app = new Koa();
app.use(KoaSSE());
app.use(async (ctx: Koa.Context) => {
let n = 0;
const interval = setInterval(() => {
ctx.sse.send(new Date().toString());
n++;
if (n >= 5) {
ctx.sse.end();
clearInterval(interval);
}
}, 1000);
ctx.sse.on("finish", () => clearInterval(interval));
});
app.listen(5000);
ctx.sse.send(data)
ctx.sse.end()
TBC
Please open an issue for support.
Please contribute using Github Flow. Create a branch, add commits, and open a pull request.
MIT : http://opensource.org/licenses/MIT
Jarvis Prestidge | jarvisprestidge@gmail.com