Pusher federation

Source: https://gist.github.com/jstsmthrgk/2c82124c9ac2bd453658f52c90b8dd44
This commit is contained in:
PizZaKatZe 2022-01-04 14:43:45 +01:00 committed by Ludwig Behm
parent f1c999ffc1
commit 185d3b58ed
5 changed files with 33 additions and 10 deletions

View file

@ -25,6 +25,7 @@ export enum GameMapProperties {
OPEN_WEBSITE_TRIGGER_MESSAGE = "openWebsiteTriggerMessage",
PLAY_AUDIO = "playAudio",
PLAY_AUDIO_LOOP = "playAudioLoop",
PUSHER_URL = "apiUrl",
READABLE_BY = "readableBy",
SCRIPT = "script",
SCRIPT_DISABLE_MODULE_SUPPORT = "scriptDisableModuleSupport",

View file

@ -187,6 +187,7 @@ export class GameScene extends DirtyScene {
};
private gameMap!: GameMap;
private pusherUrl: string | null = null;
private actionableItems: Map<number, ActionableItem> = new Map<number, ActionableItem>();
public userInputManager!: UserInputManager;
private isReconnecting: boolean | undefined = undefined;
@ -687,6 +688,8 @@ export class GameScene extends DirtyScene {
* Initializes the connection to Pusher.
*/
private connect(): void {
this.pusherUrl = this.getPusherUrl(this.mapFile);
const camera = this.cameraManager.getCamera();
connectionManager
@ -703,7 +706,8 @@ export class GameScene extends DirtyScene {
right: camera.scrollX + camera.width,
bottom: camera.scrollY + camera.height,
},
this.companion
this.companion,
this.pusherUrl
)
.then((onConnect: OnConnectInterface) => {
this.connection = onConnect.connection;
@ -1642,6 +1646,10 @@ ${escapedMessage}
);
}
private getPusherUrl(map: ITiledMap): string {
return (this.getProperties(map, GameMapProperties.PUSHER_URL) as string[])[0];
}
private getProperty(layer: ITiledMapLayer | ITiledMap, name: string): string | boolean | number | undefined {
const properties: ITiledMapProperty[] | undefined = layer.properties;
if (!properties) {