1 | ;
|
2 |
|
3 | const koa = require('koa'),
|
4 | route = require('koa-route'),
|
5 | websockify = require('../');
|
6 |
|
7 | const app = websockify(koa());
|
8 |
|
9 | // Note it's app.ws.use and not app.use
|
10 | app.ws.use(route.all('/test/:id', function* (next) {
|
11 | // `this` is the socket passed from WebSocketServer to connection listeners
|
12 | this.send('Hello World');
|
13 | this.on('message', function(message) {
|
14 | // do something with the message from client
|
15 | });
|
16 | // yielding `next` will pass the socket on to the next ws middleware
|
17 | }));
|
18 |
|
19 |
|
20 | app.listen(3000);
|