Moving property reading inside startJitsi (startJitsi is called at 2 different places)

This commit is contained in:
David Négrier 2021-02-10 11:08:57 +01:00
parent 5cb9624b0b
commit a5bdf68246
2 changed files with 14 additions and 9 deletions

View File

@ -49,6 +49,10 @@ export class GameMap {
this.lastProperties = newProps;
}
public getCurrentProperties(): Map<string, string|boolean|number> {
return this.lastProperties;
}
private getProperties(key: number): Map<string, string|boolean|number> {
const properties = new Map<string, string|boolean|number>();

View File

@ -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,10 +678,7 @@ 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);
}
@ -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();