@epicgames-ps/lib-pixelstreamingsignalling-ue5.5
@epicgames-ps/lib-pixelstreamingsignalling-ue5.5 / PlayerRegistry / PlayerRegistry
Defined in: Signalling/src/PlayerRegistry.ts:37
Handles all the player connections of a signalling server and can be used to lookup connections by id etc. Fires events when players are added or removed. Events: 'added': (playerId: string) Player was added. 'removed': (playerId: string) Player was removed.
EventEmitter
new PlayerRegistry():
PlayerRegistry
Defined in: Signalling/src/PlayerRegistry.ts:42
EventEmitter.constructor
add(
player):void
Defined in: Signalling/src/PlayerRegistry.ts:52
Assigns a unique id to the player and adds it to the registry
void
addListener(
eventName,listener):this
Defined in: Common/dist/types/Event/EventEmitter.d.ts:39
Alias for emitter.on(eventName, listener).
string
(...args) => void
this
EventEmitter.addListener
count():
number
Defined in: Signalling/src/PlayerRegistry.ts:105
Gets the total number of connected players.
number
emit(
eventName, ...args):boolean
Defined in: Common/dist/types/Event/EventEmitter.d.ts:133
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments
to each.
Returns true if the event had listeners, false otherwise.
import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listenerstring
...any[]
boolean
EventEmitter.emit
empty():
boolean
Defined in: Signalling/src/PlayerRegistry.ts:98
Returns true when the registry is empty.
boolean
get(
playerId):undefined|IPlayer
Defined in: Signalling/src/PlayerRegistry.ts:87
Gets a player from the registry using the player id. Returns undefined if the player doesn't exist.
string
undefined | IPlayer
has(
playerId):boolean
Defined in: Signalling/src/PlayerRegistry.ts:79
Tests if a player id exists in the registry.
string
boolean
listPlayers():
IPlayer[]
Defined in: Signalling/src/PlayerRegistry.ts:91
IPlayer[]
off(
eventName,listener):this
Defined in: Common/dist/types/Event/EventEmitter.d.ts:88
Alias for emitter.removeListener().
string
(...args) => void
this
EventEmitter.off
on(
eventName,listener):this
Defined in: Common/dist/types/Event/EventEmitter.d.ts:55
Adds the listener function to the end of the listeners array for the event
named eventName.
server.on('connection', (stream) => {
console.log('someone connected!');
});Returns a reference to the EventEmitter, so that calls can be chained.
string
The name of the event.
(...args) => void
The callback function
this
EventEmitter.on
once(
eventName,listener):this
Defined in: Common/dist/types/Event/EventEmitter.d.ts:70
Adds a one-time listener function for the event named eventName. The
next time eventName is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});Returns a reference to the EventEmitter, so that calls can be chained.
string
The name of the event.
(...args) => void
The callback function
this
EventEmitter.once
remove(
player):void
Defined in: Signalling/src/PlayerRegistry.ts:64
Removes a player from the registry. Does nothing if the id does not exist.
void
removeAllListeners(
eventName):this
Defined in: Common/dist/types/Event/EventEmitter.d.ts:93
Removes all listeners, or those of the specified eventName.
Returns a reference to the EventEmitter, so that calls can be chained.
string
this
EventEmitter.removeAllListeners
removeListener(
eventName,listener):this
Defined in: Common/dist/types/Event/EventEmitter.d.ts:84
Removes the specified listener from this EventEmitter.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);Returns a reference to the EventEmitter, so that calls can be chained.
string
(...args) => void
this
EventEmitter.removeListener