https://github.com/hden/socketio-wildcard
socket.io v2.x with a wildcard event
https://github.com/hden/socketio-wildcard
socket-io socketio socketio-wildcard
Last synced: 9 months ago
JSON representation
socket.io v2.x with a wildcard event
- Host: GitHub
- URL: https://github.com/hden/socketio-wildcard
- Owner: hden
- License: mit
- Created: 2014-05-30T13:44:37.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2025-05-02T00:33:38.000Z (10 months ago)
- Last Synced: 2025-05-15T04:08:15.751Z (9 months ago)
- Topics: socket-io, socketio, socketio-wildcard
- Language: JavaScript
- Homepage:
- Size: 949 KB
- Stars: 200
- Watchers: 7
- Forks: 16
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
socketio-wildcard
=================
[](https://travis-ci.org/hden/socketio-wildcard)
[](https://david-dm.org/hden/socketio-wildcard)
[](https://david-dm.org/hden/socketio-wildcard#info=devDependencies)
[](https://www.npmjs.com/package/socketio-wildcard)
[](http://standardjs.com/)
[](https://codecov.io/gh/hden/socketio-wildcard)
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fhden%2Fsocketio-wildcard?ref=badge_shield)
[](https://nodei.co/npm/socketio-wildcard/)
Socket.io with a wildcard event.
Works with Socket.io `v1.x` - `v2.x`.
Tested with node.js `v8.x` - `v12.x`.
Sunsetting
----------
As of Socket.io v2.0.4 ([commit](https://github.com/socketio/socket.io/commit/5a123beea597c9fda7b722f18343fdc2c2755e79#diff-9b2f90c89d460ee80ced18e01748824e)), you can use a socket middleware to catch every incoming Packet, which satisfies most of socketio-wildcard's use cases.
```js
io.on('connection', (socket) => {
socket.use((packet, next) => {
// Handler
next();
});
});
```
Installation
------------
npm install --save socketio-wildcard
Usage
-----
### Server
```js
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);
```
### Server (with a namespace)
```diff
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);
```
### Client
```js
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(){ /* … */ })
```
Changelog
---------
### [2.0.0] - 2016-05-23
- no breaking change
- update test dependencies for socket.io v2
### [0.3.0] - 2015-12-21
- allow custom event emitter
- support socket.io client
### [0.2.0] - 2015-11-29
- wildcard listener for all events get called first ([@Michael77](https://github.com/Michael77))
- removed coffee-script dependency
Licence
-------
MIT
## License
[](https://app.fossa.io/projects/git%2Bgithub.com%2Fhden%2Fsocketio-wildcard?ref=badge_large)