Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

koa-websocket

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-websocket

Light wrapper around Koa providing a websocket middleware handler that is koa-route compatible.

  • 2.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
increased by2.57%
Maintainers
1
Weekly downloads
 
Created
Source

koa-websocket

Circle CI

Installation

npm install koa-websocket

Usage

const koa = require('koa'),
  route = require('koa-route'),
  websockify = require('koa-websocket');

const app = websockify(koa());

// Note it's app.ws.use and not app.use
app.ws.use(route.all('/test/:id', function* (next) {
  // `this` is the regular koa context created from the `ws` onConnection `socket.upgradeReq` object.
  // the websocket is added to the context on `this.websocket`.
  this.websocket.send('Hello World');
  this.websocket.on('message', function(message) {
    // do something with the message from client
    console.log(message);
  });
  // yielding `next` will pass the context (this) on to the next ws middleware
  yield next;
}));

app.listen(3000);

Keywords

FAQs

Package last updated on 01 Jun 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc