From a5bdf68246d532ecad3bc446ae5c40e4c3f08ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Wed, 10 Feb 2021 11:08:57 +0100 Subject: [PATCH] Moving property reading inside startJitsi (startJitsi is called at 2 different places) --- front/src/Phaser/Game/GameMap.ts | 4 ++++ front/src/Phaser/Game/GameScene.ts | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/front/src/Phaser/Game/GameMap.ts b/front/src/Phaser/Game/GameMap.ts index 9f3157a0..12da0514 100644 --- a/front/src/Phaser/Game/GameMap.ts +++ b/front/src/Phaser/Game/GameMap.ts @@ -49,6 +49,10 @@ export class GameMap { this.lastProperties = newProps; } + public getCurrentProperties(): Map { + return this.lastProperties; + } + private getProperties(key: number): Map { const properties = new Map(); diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 000fffaf..29e6a0e3 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -631,11 +631,11 @@ export class GameScene extends ResizableScene implements CenterListener { } } - private safeParseJSONstring(jsonString: string|undefined) { + private safeParseJSONstring(jsonString: string|undefined, propertyName: string) { try { return jsonString ? JSON.parse(jsonString) : {}; } catch(e) { - console.warn(jsonString, e); + console.warn('Invalid JSON found in property "' + propertyName + '" of the map:' + jsonString, e); return {} } } @@ -678,14 +678,11 @@ export class GameScene extends ResizableScene implements CenterListener { this.connection.emitQueryJitsiJwtMessage(this.instance.replace('/', '-') + "-" + newValue, adminTag); } else { - const jitsiConfig = this.safeParseJSONstring(allProps.get("jitsiConfig") as string|undefined); - const jitsiInterfaceConfig = this.safeParseJSONstring(allProps.get("jitsiInterfaceConfig") as string|undefined); - - this.startJitsi(newValue as string, undefined, jitsiConfig, jitsiInterfaceConfig); + this.startJitsi(newValue as string, undefined); } layoutManager.removeActionButton('jitsiRoom', this.userInputManager); } - + const jitsiTriggerValue = allProps.get(TRIGGER_JITSI_PROPERTIES); if(jitsiTriggerValue && jitsiTriggerValue === ON_ACTION_TRIGGER_BUTTON) { layoutManager.addActionButton('jitsiRoom', 'Click on SPACE to enter in jitsi meet room', () => { @@ -1240,8 +1237,12 @@ export class GameScene extends ResizableScene implements CenterListener { this.updateCameraOffset(); } - public startJitsi(roomName: string, jwt?: string, config: object = {}, interfaceConfig: object = {}): void { - jitsiFactory.start(roomName, this.playerName, jwt, config, interfaceConfig); + public startJitsi(roomName: string, jwt?: string): void { + const allProps = this.gameMap.getCurrentProperties(); + const jitsiConfig = this.safeParseJSONstring(allProps.get("jitsiConfig") as string|undefined, 'jitsiConfig'); + const jitsiInterfaceConfig = this.safeParseJSONstring(allProps.get("jitsiInterfaceConfig") as string|undefined, 'jitsiInterfaceConfig'); + + jitsiFactory.start(roomName, this.playerName, jwt, jitsiConfig, jitsiInterfaceConfig); this.connection.setSilent(true); mediaManager.hideGameOverlay();