1.0.3 • Published 5 years ago

koa-event-stream v1.0.3

Weekly downloads
3
License
MIT
Repository
-
Last release
5 years ago

koa-event-stream

Language Node Version Yarn Version Licence Info

KoaJs Slack

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

Table of Contents

Installation

$ npm install --save koa-event-stream

...
$ yarn add koa-event-stream

...

Usage

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.send(data)

ctx.sse.end()

ctx.sse.end()

Examples

TBC

Support

Please open an issue for support.

Contributing

Please contribute using Github Flow. Create a branch, add commits, and open a pull request.

License

MIT : http://opensource.org/licenses/MIT

Author

Jarvis Prestidge | jarvisprestidge@gmail.com

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago