From f431e769cc65f484241c036012939c1b7c8bd4a7 Mon Sep 17 00:00:00 2001 From: psy Date: Thu, 14 Jan 2021 11:45:14 +0100 Subject: [PATCH 1/7] add remote files and streams to playAudio --- front/src/Phaser/Game/GameScene.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index d25c2893..a6ec1662 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -599,7 +599,17 @@ export class GameScene extends ResizableScene implements CenterListener { audioManager.unloadAudio(); } else { const mapDirUrl = this.MapUrlFile.substr(0, this.MapUrlFile.lastIndexOf('/')); - const realAudioPath = mapDirUrl + '/' + url; + const audioPath = url as string; + let realAudioPath = ''; + + if (audioPath.indexOf('://') > 0) { + // remote file or stream + realAudioPath = audioPath; + } else { + // local file, include it relative to map directory + realAudioPath = mapDirUrl + '/' + url; + } + audioManager.loadAudio(realAudioPath); if (loop) { From 8d67947bc19db6a34a8552093e612b490bdcc6d9 Mon Sep 17 00:00:00 2001 From: psy Date: Thu, 14 Jan 2021 11:48:06 +0100 Subject: [PATCH 2/7] move map url to else case --- front/src/Phaser/Game/GameScene.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index a6ec1662..021a7c8b 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -598,7 +598,6 @@ export class GameScene extends ResizableScene implements CenterListener { if (url === undefined) { audioManager.unloadAudio(); } else { - const mapDirUrl = this.MapUrlFile.substr(0, this.MapUrlFile.lastIndexOf('/')); const audioPath = url as string; let realAudioPath = ''; @@ -607,9 +606,10 @@ export class GameScene extends ResizableScene implements CenterListener { realAudioPath = audioPath; } else { // local file, include it relative to map directory + const mapDirUrl = this.MapUrlFile.substr(0, this.MapUrlFile.lastIndexOf('/')); realAudioPath = mapDirUrl + '/' + url; } - + audioManager.loadAudio(realAudioPath); if (loop) { From 4ad7f4d5a37cd4c6043f017c579e140db0beb3e3 Mon Sep 17 00:00:00 2001 From: kharhamel Date: Fri, 22 Jan 2021 15:01:10 +0100 Subject: [PATCH 3/7] changed the color of the chat links and unit test --- front/src/WebRtc/DiscussionManager.ts | 11 +---------- front/src/WebRtc/HtmlUtils.ts | 7 +++++++ front/tests/Phaser/Game/HtmlUtilsTest.ts | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 front/tests/Phaser/Game/HtmlUtilsTest.ts diff --git a/front/src/WebRtc/DiscussionManager.ts b/front/src/WebRtc/DiscussionManager.ts index a2da32b2..7653bc7a 100644 --- a/front/src/WebRtc/DiscussionManager.ts +++ b/front/src/WebRtc/DiscussionManager.ts @@ -151,15 +151,6 @@ export class DiscussionManager { this.nbpParticipants.innerText = `PARTICIPANTS (${nb})`; } - private urlify(text: string) { - const urlRegex = /(https?:\/\/[^\s]+)/g; - return text.replace(urlRegex, (url: string) => { - return '' + url + ''; - }) - // or alternatively - // return text.replace(urlRegex, '$1') - } - public addMessage(name: string, message: string, isMe: boolean = false) { const divMessage: HTMLDivElement = document.createElement('div'); divMessage.classList.add('message'); @@ -179,7 +170,7 @@ export class DiscussionManager { divMessage.appendChild(pMessage); const userMessage: HTMLParagraphElement = document.createElement('p'); - userMessage.innerHTML = this.urlify(message); + userMessage.innerHTML = HtmlUtils.urlify(message); userMessage.classList.add('body'); divMessage.appendChild(userMessage); this.divMessages?.appendChild(divMessage); diff --git a/front/src/WebRtc/HtmlUtils.ts b/front/src/WebRtc/HtmlUtils.ts index b7cb2124..81f069b3 100644 --- a/front/src/WebRtc/HtmlUtils.ts +++ b/front/src/WebRtc/HtmlUtils.ts @@ -17,4 +17,11 @@ export class HtmlUtils { elem.remove(); return elem as T; } + + public static urlify(text: string): string { + const urlRegex = /(https?:\/\/[^\s]+)/g; + return text.replace(urlRegex, (url: string) => { + return '' + url + ''; + }) + } } diff --git a/front/tests/Phaser/Game/HtmlUtilsTest.ts b/front/tests/Phaser/Game/HtmlUtilsTest.ts new file mode 100644 index 00000000..8ef1d476 --- /dev/null +++ b/front/tests/Phaser/Game/HtmlUtilsTest.ts @@ -0,0 +1,14 @@ +import "jasmine"; +import {HtmlUtils} from "../../../src/WebRtc/HtmlUtils"; + +describe("urlify()", () => { + it("should transform an url into a link", () => { + const text = HtmlUtils.urlify('https://google.com'); + expect(text).toEqual('https://google.com'); + }); + + it("should not transform a normal text into a link", () => { + const text = HtmlUtils.urlify('hello'); + expect(text).toEqual('hello'); + }); +}); \ No newline at end of file From 39b433eef5ca8933ed3f0f976e26c3d0d03d5cf3 Mon Sep 17 00:00:00 2001 From: TabascoEye Date: Sat, 23 Jan 2021 01:16:13 +0100 Subject: [PATCH 4/7] Update GameScene.ts stop all the map specific stuff (Jitsi, coWebsite, Audio) when leaving the scene Fixes #633 --- front/src/Phaser/Game/GameScene.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index c2cb0950..55f89321 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -698,6 +698,10 @@ export class GameScene extends ResizableScene implements CenterListener { } public cleanupClosingScene(): void { + // stop playing audio, close any open website, stop any open Jitsi + coWebsiteManager.closeCoWebsite(); + this.stopJitsi(); + this.playAudio(undefined); // We are completely destroying the current scene to avoid using a half-backed instance when coming back to the same map. if(this.connection) { this.connection.closeConnection(); From 8609cda0d0109a34e245766129a60d08158aaea2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 25 Jan 2021 11:18:48 +0100 Subject: [PATCH 5/7] Add a parameter to allow changing phaser renderer Recently, some Macs have been crashing running WorkAdventure. Hard to say if this is related to Phaser 3.50 upgrade or to the new MacOS version. It happens mostly on Mac Air and might be related to WebGL rendering. This commit allows to switch to CANVAS renderer by adding `?phaserMode=canvas` in the URL --- front/src/index.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/front/src/index.ts b/front/src/index.ts index acf66cf8..e2b636d1 100644 --- a/front/src/index.ts +++ b/front/src/index.ts @@ -53,8 +53,28 @@ const fps : Phaser.Types.Core.FPSConfig = { smoothStep: false } +// the ?phaserMode=canvas parameter can be used to force Canvas usage +let params = new URLSearchParams(document.location.search.substring(1)); +let phaserMode = params.get("phaserMode"); +let mode: number; +switch (phaserMode) { + case 'auto': + case null: + mode = Phaser.AUTO; + break; + case 'canvas': + mode = Phaser.CANVAS; + break; + case 'webgl': + mode = Phaser.WEBGL; + break; + default: + throw new Error('phaserMode parameter must be one of "auto", "canvas" or "webgl"'); +} + + const config: GameConfig = { - type: Phaser.AUTO, + type: mode, title: "WorkAdventure", width: width / RESOLUTION, height: height / RESOLUTION, From c2c8680dae43b5c0c05366b5e2317d720fcc5e6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 25 Jan 2021 12:02:00 +0100 Subject: [PATCH 6/7] Fix linting --- front/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/front/src/index.ts b/front/src/index.ts index e2b636d1..b9a00731 100644 --- a/front/src/index.ts +++ b/front/src/index.ts @@ -54,8 +54,8 @@ const fps : Phaser.Types.Core.FPSConfig = { } // the ?phaserMode=canvas parameter can be used to force Canvas usage -let params = new URLSearchParams(document.location.search.substring(1)); -let phaserMode = params.get("phaserMode"); +const params = new URLSearchParams(document.location.search.substring(1)); +const phaserMode = params.get("phaserMode"); let mode: number; switch (phaserMode) { case 'auto': From ab0fe63cb2a546ce561f4b23b71e82718f79a995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Mon, 25 Jan 2021 22:42:44 +0100 Subject: [PATCH 7/7] Adding start room url to develop env --- deeployer.libsonnet | 1 + 1 file changed, 1 insertion(+) diff --git a/deeployer.libsonnet b/deeployer.libsonnet index 89571945..1ad58891 100644 --- a/deeployer.libsonnet +++ b/deeployer.libsonnet @@ -79,6 +79,7 @@ "TURN_USER": "workadventure", "TURN_PASSWORD": "WorkAdventure123", "JITSI_PRIVATE_MODE": if env.SECRET_JITSI_KEY != '' then "true" else "false", + "START_ROOM_URL": "/_/global/maps."+url+"/Floor0/floor0.json" //"GA_TRACKING_ID": "UA-10196481-11" } },