workadventure/pusher/src/Model/PusherRoom.ts
David Négrier c9fa9b9a92 Migrating away from the notion of public/private URL in WorkAdventure Github repository
The notion of public/private repositories (with /_/ and /@/ URLs) is specific to the SAAS version of WorkAdventure.
It would be better to avoid leaking the organization/world/room structure of the private SAAS URLs inside the WorkAdventure Github project.

Rather than sending http://admin_host/api/map?organizationSlug=...&worldSlug=...&roomSlug=...., we are now sending /api/map&playUri=...
where playUri is the full URL of the current game.
This allows the backend to act as a complete router.
The front (and the pusher) will be able to completely ignore the specifics of URL building (with /@/ and /_/ URLs, etc...)
Those details will live only in the admin server, which is way cleaner (and way more powerful).
2021-07-15 17:07:47 +02:00

52 lines
1.6 KiB
TypeScript

import { ExSocketInterface } from "_Model/Websocket/ExSocketInterface";
import { PositionDispatcher } from "./PositionDispatcher";
import { ViewportInterface } from "_Model/Websocket/ViewportMessage";
import { arrayIntersect } from "../Services/ArrayHelper";
import { ZoneEventListener } from "_Model/Zone";
export enum GameRoomPolicyTypes {
ANONYMOUS_POLICY = 1,
MEMBERS_ONLY_POLICY,
USE_TAGS_POLICY,
}
export class PusherRoom {
private readonly positionNotifier: PositionDispatcher;
public tags: string[];
public policyType: GameRoomPolicyTypes;
private versionNumber: number = 1;
constructor(public readonly roomUrl: string, private socketListener: ZoneEventListener) {
this.tags = [];
this.policyType = GameRoomPolicyTypes.ANONYMOUS_POLICY;
// A zone is 10 sprites wide.
this.positionNotifier = new PositionDispatcher(this.roomUrl, 320, 320, this.socketListener);
}
public setViewport(socket: ExSocketInterface, viewport: ViewportInterface): void {
this.positionNotifier.setViewport(socket, viewport);
}
public leave(socket: ExSocketInterface) {
this.positionNotifier.removeViewport(socket);
}
public canAccess(userTags: string[]): boolean {
return arrayIntersect(userTags, this.tags);
}
public isEmpty(): boolean {
return this.positionNotifier.isEmpty();
}
public needsUpdate(versionNumber: number): boolean {
if (this.versionNumber < versionNumber) {
this.versionNumber = versionNumber;
return true;
} else {
return false;
}
}
}