Skip to content

Pattern Matching Events

Compare
Choose a tag to compare
@NathanGRomano NathanGRomano released this 28 Jun 08:35
· 16 commits to master since this release

Events can now be matched via RegExp and wildcards.

var router = require('socket.io-events')();
router.on(/^\w+/, function (sock, args, next) {
  // do something but don't consume it!
  next();
});
router.on('*thing', function (sock, args, next) {
  // do something but don't consume it!
  next();
});
router.on('some*', function (sock, args, next) {
  // do something but don't consume it!
  next();
});

var io = require('socket.io')(3000);
io.use(router);
io.on('connection', function (sock) {
  sock.on('something', function (data) {
    sock.emit('something', data);
  });
});