workadventure/front/src/Api/iframe/camera.ts

30 lines
978 B
TypeScript
Raw Normal View History

import { IframeApiContribution, sendToWorkadventure } from "./IframeApiContribution";
import { Subject } from "rxjs";
2021-12-30 15:50:52 +01:00
import type { WasCameraUpdatedEvent } from "../Events/WasCameraUpdatedEvent";
import { apiCallback } from "./registeredCallbacks";
2021-11-23 17:39:45 +01:00
import { isWasCameraUpdatedEvent } from "../Events/WasCameraUpdatedEvent";
2021-11-23 17:39:45 +01:00
const moveStream = new Subject<WasCameraUpdatedEvent>();
export class WorkAdventureCameraCommands extends IframeApiContribution<WorkAdventureCameraCommands> {
callbacks = [
apiCallback({
2021-11-23 17:39:45 +01:00
type: "wasCameraUpdated",
typeChecker: isWasCameraUpdatedEvent,
callback: (payloadData) => {
moveStream.next(payloadData);
},
}),
];
2021-12-30 15:50:52 +01:00
onCameraUpdate(): Subject<WasCameraUpdatedEvent> {
sendToWorkadventure({
2021-11-23 17:39:45 +01:00
type: "onCameraUpdate",
data: null,
});
2021-12-30 15:50:52 +01:00
return moveStream;
}
}
export default new WorkAdventureCameraCommands();