Socket.io Client: respond to all events with one handler?

前端 未结 14 1932
时光取名叫无心
时光取名叫无心 2020-11-28 04:16

Is it possible to have a socket.io client respond to all events without to have specify each event individually?

For example, something like this (which obviously do

14条回答
  •  北海茫月
    2020-11-28 04:36

    Finally, there is a module called socket.io-wildcard which allows using wildcards on client and server side

    var io         = require('socket.io')();
    var middleware = require('socketio-wildcard')();
    
    io.use(middleware);
    
    io.on('connection', function(socket) {
      socket.on('*', function(){ /* … */ });
    });
    
    io.listen(8000);
    

提交回复
热议问题