The name of the event emitter. It will be used in the output logs when errors occur in the event listeners.
Start listening to all events. The provided listener will be invoked each time any event is emitted.
The callback that will be invoked when any event is emitted. It will be invoked with the event name and the event information in its arguments.
Broadcast a message to all users, that are currently connected to the server.
The message to send to all the users.
Optional
skipUsername: string(optional) The username of the user you want to skip sending this message to.
Start listening at the specified port number. This function is asynchronous, the server is listening once the server emits a 'listen' event.
Note: If you provided a http server that is already listening, then you can leave the port undefined or use the exact same port number. If you provide a different port number, this method will throw an error.
Optional
port: numberThe port number at which to start the server. When not provided, the server will start listening at an available port.
Start listening to a specific event. The provided listener will be invoked each time the event is emitted.
The name of the event to listen to.
The callback that will be invoked when the event is emitted. It will be invoked with the event information in its arguments.
Start listening to a specific event only once. The provided listener will be invoked the first time the event is emitted.
If a predicate is provided, the listener will only be invoked if the predicate returns true. The listener will be removed after the first time it is invoked. If the predicate returns false, the event subscription will be kept intact, until the predicate returns true.
The name of the event to listen to.
The callback that will be invoked when the event is emitted. It will be invoked with the event information in its arguments.
Optional
predicate: EventListener<Events[K], boolean>An optional predicate that can be used to filter out events. If the predicate returns true, the listener will be invoked.
Create new event emitter based on the existing event emitter with custom logic to define which events are passed through or transformed.
In the configure tap callback function you can create custom logic to pass or transform events to
Example:
type MyEventMap = { 'hello': [name: string], 'one': [], 'unused': [value: number] }
const myEmitter: EventEmitter<MyEventMap> = ...;
type MyPipedEventMap = { 'hello': [name: string], 'two': [] }
const myPipedEmitter = myEmitter.pipe<MyPipedEventMap>(pipe => {
pipe.pass('hello');
pipe.on('one' () => {
pipe.emit('two');
});
});
myPipedEmitter.on('hello', (name: string) => { ... })
myPipedEmitter.on('two', () => { ... })
TODO: Ensure that the pipe has a similar unsubscribe interface as on and once.
Emits an event on the pipe to be received by the new EventEmitter.
The name of the event to emit.
Rest
...args: NextEventMap[NextK]The arguments of the event to emit.
Start listening to a specific event on the source event emitter.
The name of the event to listen to.
The callback that will be invoked when the event is emitted. It will be invoked with the event information in its arguments.
Ensures that events (with the provided event names) are passed through as-is to the next event emitter. Note: Only event names that exist on both sides of the pipe and that have the same argument array signature are allowed to be passed.
Rest
...eventNames: MutualEventKey[]The names of the events you want to pass through as-is to the next event emitter. Only events that exist on both sides of the pipe and that have the same argument array signature are allowed to be passed.
Wait for a specific event. The returned promise will resolve when the event is emitted. The promise will resolve with the event information.
The name of the event to wait for.
Optional
predicate: EventListener<Events[K], boolean>Optionally provides a predicate that is invoked with every occurrence of the event. The promise will only resolve once the predicate returns true. It will be invoked with the event information in its arguments. If the predicate throws an error, the promise will be rejected with that error.
Server is a websocket server that abstracts individual websocket connections into users.