2021-05-28 00:24:08 +02:00
|
|
|
import { Subject } from "rxjs";
|
2021-05-28 01:14:10 +02:00
|
|
|
import { EnterLeaveEvent, isEnterLeaveEvent } from '../Events/EnterLeaveEvent';
|
|
|
|
import { apiCallback as apiCallback, IframeApiContribution } from './IframeApiContribution';
|
2021-05-25 13:47:41 +02:00
|
|
|
|
|
|
|
|
2021-05-28 00:24:08 +02:00
|
|
|
const enterStreams: Map<string, Subject<EnterLeaveEvent>> = new Map<string, Subject<EnterLeaveEvent>>();
|
|
|
|
const leaveStreams: Map<string, Subject<EnterLeaveEvent>> = new Map<string, Subject<EnterLeaveEvent>>();
|
2021-05-25 13:47:41 +02:00
|
|
|
|
2021-06-18 17:22:56 +02:00
|
|
|
class WorkadventureRoomCommands extends IframeApiContribution<WorkadventureRoomCommands> {
|
2021-05-28 00:24:08 +02:00
|
|
|
callbacks = [
|
|
|
|
apiCallback({
|
|
|
|
callback: (payloadData: EnterLeaveEvent) => {
|
|
|
|
enterStreams.get(payloadData.name)?.next();
|
|
|
|
},
|
|
|
|
type: "enterEvent",
|
|
|
|
typeChecker: isEnterLeaveEvent
|
|
|
|
}),
|
|
|
|
apiCallback({
|
|
|
|
type: "leaveEvent",
|
|
|
|
typeChecker: isEnterLeaveEvent,
|
|
|
|
callback: (payloadData) => {
|
|
|
|
leaveStreams.get(payloadData.name)?.next();
|
|
|
|
}
|
|
|
|
})
|
2021-05-25 13:47:41 +02:00
|
|
|
|
2021-05-28 00:24:08 +02:00
|
|
|
]
|
2021-05-25 13:47:41 +02:00
|
|
|
|
|
|
|
|
2021-05-28 00:24:08 +02:00
|
|
|
onEnterZone(name: string, callback: () => void): void {
|
|
|
|
let subject = enterStreams.get(name);
|
|
|
|
if (subject === undefined) {
|
|
|
|
subject = new Subject<EnterLeaveEvent>();
|
|
|
|
enterStreams.set(name, subject);
|
|
|
|
}
|
|
|
|
subject.subscribe(callback);
|
2021-05-25 13:47:41 +02:00
|
|
|
|
2021-05-28 00:24:08 +02:00
|
|
|
}
|
|
|
|
onLeaveZone(name: string, callback: () => void): void {
|
|
|
|
let subject = leaveStreams.get(name);
|
|
|
|
if (subject === undefined) {
|
|
|
|
subject = new Subject<EnterLeaveEvent>();
|
|
|
|
leaveStreams.set(name, subject);
|
|
|
|
}
|
|
|
|
subject.subscribe(callback);
|
|
|
|
}
|
2021-05-25 13:47:41 +02:00
|
|
|
|
2021-05-28 00:24:08 +02:00
|
|
|
}
|
2021-05-25 13:47:41 +02:00
|
|
|
|
|
|
|
|
2021-06-18 17:22:56 +02:00
|
|
|
export default new WorkadventureRoomCommands();
|