2021-12-23 15:27:17 +01:00
|
|
|
import { EventEmitter } from "events";
|
2020-10-16 14:36:43 +02:00
|
|
|
|
2021-06-24 10:09:10 +02:00
|
|
|
const clientJoinEvent = "clientJoin";
|
|
|
|
const clientLeaveEvent = "clientLeave";
|
2020-10-16 14:36:43 +02:00
|
|
|
|
|
|
|
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();
|