Adds the camera to available APIs with retrieving of the worldView

This commit is contained in:
Benedicte Quimbert 2021-11-23 16:51:39 +01:00
parent 99dfd77600
commit 5b6a8ca4d7
9 changed files with 86 additions and 7 deletions

View file

@ -13,7 +13,7 @@ export class EmbeddedWebsite {
private _allowApi: boolean;
private _position: Rectangle;
private readonly origin: "map" | "player" | undefined;
private _scale: number | undefined;
private _scale: number;
constructor(private config: CreateEmbeddedWebsiteEvent) {
this.name = config.name;
@ -23,7 +23,7 @@ export class EmbeddedWebsite {
this._allowApi = config.allowApi ?? false;
this._position = config.position;
this.origin = config.origin;
this._scale = config.scale;
this._scale = config.scale ?? 1;
}
public get url() {
@ -116,7 +116,7 @@ export class EmbeddedWebsite {
});
}
public get scale() {
public get scale(): number {
return this._scale;
}

View file

@ -0,0 +1,29 @@
import { IframeApiContribution, sendToWorkadventure } from "./IframeApiContribution";
import { Subject } from "rxjs";
import type { HasCameraMovedEvent, HasCameraMovedEventCallback } from "../Events/HasCameraMovedEvent";
import { apiCallback } from "./registeredCallbacks";
import { isHasCameraMovedEvent } from "../Events/HasCameraMovedEvent";
const moveStream = new Subject<HasCameraMovedEvent>();
export class WorkAdventureCameraCommands extends IframeApiContribution<WorkAdventureCameraCommands> {
callbacks = [
apiCallback({
type: "hasCameraMoved",
typeChecker: isHasCameraMovedEvent,
callback: (payloadData) => {
moveStream.next(payloadData);
},
}),
];
onCameraMove(callback: HasCameraMovedEventCallback): void {
moveStream.subscribe(callback);
sendToWorkadventure({
type: "onCameraMove",
data: null,
});
}
}
export default new WorkAdventureCameraCommands();