partey_workadventure/pusher/src/Services/ClientEventsEmitter.ts

33 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-06-24 10:09:10 +02:00
const EventEmitter = require("events");
2021-06-24 10:09:10 +02:00
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);
}
2021-06-24 10:09:10 +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);
}
}
2021-06-24 10:09:10 +02:00
export const clientEventsEmitter = new ClientEventsEmitter();