2020-10-16 14:36:43 +02:00
|
|
|
const EventEmitter = require('events');
|
|
|
|
|
|
|
|
const clientJoinEvent = 'clientJoin';
|
|
|
|
const clientLeaveEvent = 'clientLeave';
|
|
|
|
|
|
|
|
class ClientEventsEmitter extends EventEmitter {
|
|
|
|
emitClientJoin(clientUUid: string, roomId: string): void {
|
|
|
|
this.emit(clientJoinEvent, clientUUid, roomId);
|
|
|
|
}
|
|
|
|
|
|
|
|
emitClientLeave(clientUUid: string, roomId: string): void {
|
|
|
|
this.emit(clientLeaveEvent, clientUUid, roomId);
|
|
|
|
}
|
2020-12-10 17:46:15 +01:00
|
|
|
|
2020-10-16 14:36:43 +02:00
|
|
|
registerToClientJoin(callback: (clientUUid: string, roomId: string) => void): void {
|
|
|
|
this.on(clientJoinEvent, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
registerToClientLeave(callback: (clientUUid: string, roomId: string) => void): void {
|
|
|
|
this.on(clientLeaveEvent, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
unregisterFromClientJoin(callback: (clientUUid: string, roomId: string) => void): void {
|
|
|
|
this.removeListener(clientJoinEvent, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
unregisterFromClientLeave(callback: (clientUUid: string, roomId: string) => void): void {
|
|
|
|
this.removeListener(clientLeaveEvent, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-10 17:46:15 +01:00
|
|
|
export const clientEventsEmitter = new ClientEventsEmitter();
|