Socket
Socket
Sign inDemoInstall

koa-event-stream

Package Overview
Dependencies
19
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    koa-event-stream

Koa Server Side Events Middleware


Version published
Weekly downloads
129
decreased by-78.64%
Maintainers
1
Install size
1.83 MB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 13 Jan 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc