koa-websocket
This is a pre-release for compatibility with Koa 2. Doing npm install koa-websocket
will continue to give you 2.x until Koa 2 is stable.
Installation
npm install koa-websocket@next
Usage
const Koa = require('koa'),
route = require('koa-route'),
websockify = require('koa-websocket');
const app = websockify(new Koa());
app.ws.use(function(ctx, next) {
return next(ctx);
});
app.ws.use(route.all('/test/:id', function (ctx) {
ctx.websocket.send('Hello World');
ctx.websocket.on('message', function(message) {
console.log(message);
});
}));
app.listen(3000);