Socket.io with a wildcard event.
Works with Socket.io v1.x
- v2.x
.
Tested with node.js v8.x
- v12.x
.
As of Socket.io v2.0.4 (commit), you can use a socket middleware to catch every incoming Packet, which satisfies most of socketio-wildcard's use cases.
io.on('connection', (socket) => {
socket.use((packet, next) => {
// Handler
next();
});
});
npm install --save socketio-wildcard
var io = require('socket.io')();
var middleware = require('socketio-wildcard')();
io.use(middleware);
io.on('connection', function(socket) {
socket.on('*', function(packet){
// client.emit('foo', 'bar', 'baz')
packet.data === ['foo', 'bar', 'baz']
});
});
io.listen(8000);
var io = require('socket.io')();
+var nsp = io.of('/namespace');
var middleware = require('socketio-wildcard')();
-io.use(middleware);
+nsp.use(middleware);
-io.on('connection', function(socket) {
+nsp.on('connection', function(socket) {
socket.on('*', function(packet){
// client.emit('foo', 'bar', 'baz')
packet.data === ['foo', 'bar', 'baz']
});
});
io.listen(8000);
var io = require('socket.io-client');
var socket = io('http://localhost');
// piggyback using the event-emitter bundled with socket.io client
var patch = require('socketio-wildcard')(io.Manager);
patch(socket);
socket.on('*', function(){ /* … */ })
- no breaking change
- update test dependencies for socket.io v2
- allow custom event emitter
- support socket.io client
- wildcard listener for all events get called first (@Michael77)
- removed coffee-script dependency
MIT