Skip to content

Middleware(.use) does not emit connect when using a custom namespace #3082

@MickL

Description

@MickL

You 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions