ws-events
Minimal Events for WebSockets.
Example
ws-events
decorates a WebSocket instance. It works both on the server and the
client side.
On the server side:
const wsEvents = const Server = Server const wss = wss
On the client side:
const wsEvents = const ws = ws
API
events = wsEvents(socket)
Create a ws-events
emitter. The emitter wraps the passed-in socket, so all
native WebSocket methods can still be used.
socket
is a standard WebSocket instance.
const socket = socket
events.on(eventName, cb): this
Register an event handler.
events.off(eventName, cb): this
Remove an event handler.
events.off(eventName): this
Remove all handlers for the given event.
events.off(): this
Remove all handlers for all events.
events.emit(eventName, ...arguments): this
Emit an event. When emitting on the server, the handlers on the client will fire. When emitting on the client, the handlers on the server will fire.
events.hasListeners(eventName): bool
Check if there are any handlers for an event.
events.listeners(eventName): Array<function>
Return the listeners for an event.
License
MIT.