Middleware(.use) does not emit connect when using a custom namespace
See original GitHub issueYou want to:
- report a bug
- request a feature
Current behaviour
When using a custom namespace with a middleware the server gets a ‘connection’ event, but the client does not receive ‘connect’ event.
This works:
io.use((socket, next) => {
console.log('middleware running...');
next();
}).on('connection', socket => {
console.log('client connected');
});
This does not work:
// Following works, but client does not receive 'connect' or 'connection':
io.of('/admin').use((socket, next) => {
console.log('middleware running...');
next();
}).on('connection', socket => {
console.log('client connected');
});
Sitenotes
Also very strange: If i do the following code then also the default-namespace does not emit any ‘connect’ event even tho the middleware from /admin is not running.
io.on('connection', socket => {
console.log('client connected');
});
io.of('/admin').use((socket, next) => {
console.log('middleware running...');
next();
}).on('connection', socket => {
console.log('client connected');
});
To fix this i have to add .use((socket, next) => { next(); })
to default namespace. But still /admin does not emit ‘connect’.
Steps to reproduce (if the current behaviour is a bug)
Please see above
Expected behaviour
On connection, client should receive ‘connect’
Setup
- OS: macOS Sierra 10.12.6
- browser: Chrome
- Node: v8.2.1
- NPM: 5.4.2
- socket.io version: 2.0.3
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Socket.io custom namespace clients do not receive an error ...
I am developing a project with socket.io communication. The basic structure is that I have set up a custom namespace which requires ...
Read more >Middlewares | Socket.IO
A middleware function is a function that gets executed for every incoming connection.
Read more >Migrating from 2.x to 3.0 | Socket.IO 中文文档
io.set() is removed; No more implicit connection to the default namespace ... Socket.use() is removed; A middleware error will now emit an Error...
Read more >python-socketio Documentation - manpages.ubuntu!
emit ('my message', {'foo': 'bar'}, namespace='/chat') If the namespaces argument of the connect() call isn't given, any namespaces used in event handlers are...
Read more >API Reference — python-socketio documentation
Emit a custom event to a client and wait for the response. ... IO transport is connected, and the namespaces will connect in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@JanisRubens Thanks for the detailed report 👍 , I was eventually able to reproduce. Fixed by https://github.com/socketio/socket.io/pull/3197
I am having the opposite effect: I can only see the logs for the namespaces. But I also connect the client to that namespaces. However I was expecting to be able to use a global middleware for auth.