$ show hden/socketio-wildcard
socketio-wildcard is a small Node.js library that adds a wildcard event listener ('*') to socket.io, allowing developers to catch all incoming events in a single handler. The core implementation is a middleware that intercepts the `onevent` method of a socket, emitting a wildcard event before delegating to the specific event handler. It supports both server-side and client-side usage, with a single-file module that exports a factory function. The library is deprecated as socket.io 2.0.4+ includes native middleware for packet interception, which supersedes the wildcard pattern. The codebase is clean, well-tested, and follows modern JavaScript standards, but its functionality is largely redundant with current socket.io features. The repository includes comprehensive integration tests using mocha and power-assert, and CI configurations for Travis and CircleCI.
The LLM identified 2 files worth highlighting for reuse:
The core of the library. It exports a function that takes an optional custom EventEmitter (defaults to Node's built-in) and returns a middleware function. The middleware overrides the `onevent` method on the socket to emit a wildcard event '*' with the packet data before calling the original emit for the specific event. It handles optional acknowledgement callbacks. This pattern is clean, reusable, and can be extracted to add wildcard support to any EventEmitter-based system.
Integration tests for both server and client usage of the wildcard middleware. It sets up a socket.io server and client, binds the middleware, and verifies that wildcard events are received with the correct packet data and that normal events still fire. The test structure is clear, uses power-assert for descriptive assertions, and demonstrates proper async handling with callbacks. This file serves as a solid example of testing socket.io middleware with real socket connections.