workadventure/front/src/Api/iframe/camera.ts
2022-01-03 11:45:47 +01:00

30 lines
1 KiB
TypeScript

import { IframeApiContribution, sendToWorkadventure } from "./IframeApiContribution";
import { Subject } from "rxjs";
import type { WasCameraUpdatedEvent, WasCameraUpdatedEventCallback } from "../Events/WasCameraUpdatedEvent";
import { apiCallback } from "./registeredCallbacks";
import { isWasCameraUpdatedEvent } from "../Events/WasCameraUpdatedEvent";
const moveStream = new Subject<WasCameraUpdatedEvent>();
export class WorkAdventureCameraCommands extends IframeApiContribution<WorkAdventureCameraCommands> {
callbacks = [
apiCallback({
type: "wasCameraUpdated",
typeChecker: isWasCameraUpdatedEvent,
callback: (payloadData) => {
moveStream.next(payloadData);
},
}),
];
onCameraUpdate(callback: WasCameraUpdatedEventCallback): void {
moveStream.subscribe(callback);
sendToWorkadventure({
type: "onCameraUpdate",
data: null,
});
}
}
export default new WorkAdventureCameraCommands();