-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allowing additional hooks to server on connection #24
Comments
Same problem here. only message is allowed.Can someone please describe a bit please!? |
I think the const Router = require('koa-router');
const ws = new Router();
...
ws.get('/', (ctx, next) => {
ctx.websocket.send("Hello client!");
ctx.websocket.on('close', function () {
console.log("Client left.");
});
}); |
The connection event is fired before before any middleware(your router) is executed. If you have access to ctx then you have already connected. More precisely, if you have access to a WebSocket object then you have already connected the socket (unless you are acting as a client). The on('connection', ...) should be on the server object not the websocket. |
It seems like the
connection
event is not exposed, I can't access it. For example, I want to do:but this doesn't seem to work.
The text was updated successfully, but these errors were encountered: