From 14b328c733941da18dc9450ed26ce662f9d118cf Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Thu, 7 Jan 2021 12:15:33 +0100 Subject: [PATCH 1/3] Removed hard coded default map You can apply local maps using the maps vhost as previously. But it's also possible to specify external maps by prepending http or https. --- .env.template | 1 + docker-compose.yaml | 1 + front/src/Connexion/ConnectionManager.ts | 10 ++++++---- front/src/Enum/EnvironmentVariable.ts | 2 ++ front/webpack.config.js | 2 +- 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.env.template b/.env.template index d0db42e3..ce3937d3 100644 --- a/.env.template +++ b/.env.template @@ -5,3 +5,4 @@ JITSI_PRIVATE_MODE=false JITSI_ISS= SECRET_JITSI_KEY= ADMIN_API_TOKEN=123 +START_ROOM_URL=/Floor0/floor0.json \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 23fa58a4..36d51c92 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -33,6 +33,7 @@ services: TURN_SERVER: "turn:coturn.workadventu.re:443,turns:coturn.workadventu.re:443" TURN_USER: workadventure TURN_PASSWORD: WorkAdventure123 + START_ROOM_URL: "$START_ROOM_URL" command: yarn run start volumes: - ./front:/usr/src/app diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index 12595f9d..b7788536 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -1,5 +1,5 @@ import Axios from "axios"; -import {API_URL} from "../Enum/EnvironmentVariable"; +import {API_URL, START_ROOM_URL} from "../Enum/EnvironmentVariable"; import {RoomConnection} from "./RoomConnection"; import {OnConnectInterface, PositionInterface, ViewportInterface} from "./ConnexionModels"; import {GameConnexionTypes, urlManager} from "../Url/UrlManager"; @@ -7,8 +7,6 @@ import {localUserStore} from "./LocalUserStore"; import {LocalUser} from "./LocalUser"; import {Room} from "./Room"; -const URL_ROOM_STARTED = 'tcm/workadventure/floor0'; - class ConnectionManager { private localUser!:LocalUser; @@ -50,7 +48,11 @@ class ConnectionManager { } let roomId: string if (connexionType === GameConnexionTypes.empty) { - roomId = urlManager.editUrlForRoom(URL_ROOM_STARTED, null, null); + if (START_ROOM_URL.startsWith('http://') || START_ROOM_URL.startsWith('https://')) { + roomId = '/_/global/' + START_ROOM_URL.replace('http://', '').replace('https://', ''); + } else { + roomId = urlManager.editUrlForRoom(START_ROOM_URL, null, null); + } } else { roomId = window.location.pathname + window.location.hash; } diff --git a/front/src/Enum/EnvironmentVariable.ts b/front/src/Enum/EnvironmentVariable.ts index e5aa5deb..0ee1906f 100644 --- a/front/src/Enum/EnvironmentVariable.ts +++ b/front/src/Enum/EnvironmentVariable.ts @@ -1,4 +1,5 @@ const DEBUG_MODE: boolean = process.env.DEBUG_MODE == "true"; +const START_ROOM_URL : string = process.env.START_ROOM_URL || 'tcm/workadventure/floor0'; const API_URL = (process.env.API_PROTOCOL || (typeof(window) !== 'undefined' ? window.location.protocol : 'http:')) + '//' + (process.env.API_URL || "pusher.workadventure.localhost"); const UPLOADER_URL = (process.env.API_PROTOCOL || (typeof(window) !== 'undefined' ? window.location.protocol : 'http:')) + '//' + (process.env.UPLOADER_URL || 'uploader.workadventure.localhost'); const ADMIN_URL = (process.env.API_PROTOCOL || (typeof(window) !== 'undefined' ? window.location.protocol : 'http:')) + '//' + (process.env.ADMIN_URL || "workadventure.localhost"); @@ -14,6 +15,7 @@ const MAX_EXTRAPOLATION_TIME = 100; // Extrapolate a maximum of 250ms if no new export { DEBUG_MODE, + START_ROOM_URL, API_URL, UPLOADER_URL, ADMIN_URL, diff --git a/front/webpack.config.js b/front/webpack.config.js index 82bb34fa..3b97081c 100644 --- a/front/webpack.config.js +++ b/front/webpack.config.js @@ -45,7 +45,7 @@ module.exports = { new webpack.ProvidePlugin({ Phaser: 'phaser' }), - new webpack.EnvironmentPlugin(['API_URL', 'UPLOADER_URL', 'ADMIN_URL', 'DEBUG_MODE', 'TURN_SERVER', 'TURN_USER', 'TURN_PASSWORD', 'JITSI_URL', 'JITSI_PRIVATE_MODE']) + new webpack.EnvironmentPlugin(['API_URL', 'UPLOADER_URL', 'ADMIN_URL', 'DEBUG_MODE', 'TURN_SERVER', 'TURN_USER', 'TURN_PASSWORD', 'JITSI_URL', 'JITSI_PRIVATE_MODE', 'START_ROOM_URL']) ], }; From d79a18ee815c8f76226f386a50675164a63dfb49 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Fri, 8 Jan 2021 11:41:18 +0100 Subject: [PATCH 2/3] Removed unused URL_ROOM_STARTED variable from pusher and back --- back/src/Enum/EnvironmentVariable.ts | 2 -- pusher/src/Enum/EnvironmentVariable.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/back/src/Enum/EnvironmentVariable.ts b/back/src/Enum/EnvironmentVariable.ts index 00750969..2cbfbf2e 100644 --- a/back/src/Enum/EnvironmentVariable.ts +++ b/back/src/Enum/EnvironmentVariable.ts @@ -1,5 +1,4 @@ const SECRET_KEY = process.env.SECRET_KEY || "THECODINGMACHINE_SECRET_KEY"; -const URL_ROOM_STARTED = "/Floor0/floor0.json"; const MINIMUM_DISTANCE = process.env.MINIMUM_DISTANCE ? Number(process.env.MINIMUM_DISTANCE) : 64; const GROUP_RADIUS = process.env.GROUP_RADIUS ? Number(process.env.GROUP_RADIUS) : 48; const ALLOW_ARTILLERY = process.env.ALLOW_ARTILLERY ? process.env.ALLOW_ARTILLERY == 'true' : false; @@ -16,7 +15,6 @@ export const SOCKET_IDLE_TIMER = parseInt(process.env.SOCKET_IDLE_TIMER as strin export { SECRET_KEY, - URL_ROOM_STARTED, MINIMUM_DISTANCE, ADMIN_API_URL, ADMIN_API_TOKEN, diff --git a/pusher/src/Enum/EnvironmentVariable.ts b/pusher/src/Enum/EnvironmentVariable.ts index 17f80f9c..5b3ec9c4 100644 --- a/pusher/src/Enum/EnvironmentVariable.ts +++ b/pusher/src/Enum/EnvironmentVariable.ts @@ -1,5 +1,4 @@ const SECRET_KEY = process.env.SECRET_KEY || "THECODINGMACHINE_SECRET_KEY"; -const URL_ROOM_STARTED = "/Floor0/floor0.json"; const MINIMUM_DISTANCE = process.env.MINIMUM_DISTANCE ? Number(process.env.MINIMUM_DISTANCE) : 64; const GROUP_RADIUS = process.env.GROUP_RADIUS ? Number(process.env.GROUP_RADIUS) : 48; const ALLOW_ARTILLERY = process.env.ALLOW_ARTILLERY ? process.env.ALLOW_ARTILLERY == 'true' : false; @@ -16,7 +15,6 @@ export const SOCKET_IDLE_TIMER = parseInt(process.env.SOCKET_IDLE_TIMER as strin export { SECRET_KEY, - URL_ROOM_STARTED, MINIMUM_DISTANCE, API_URL, ADMIN_API_URL, From bbf932539693b84c8bd8f5808365783545c1892e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 21 Jan 2021 09:40:11 +0100 Subject: [PATCH 3/3] Simplifying code and making START_ROOM_URL compatible with public (_) and private (@) paths --- .env.template | 2 +- front/src/Connexion/ConnectionManager.ts | 10 +++------- front/src/Enum/EnvironmentVariable.ts | 2 +- front/src/Url/UrlManager.ts | 18 ++---------------- 4 files changed, 7 insertions(+), 25 deletions(-) diff --git a/.env.template b/.env.template index ce3937d3..330f3865 100644 --- a/.env.template +++ b/.env.template @@ -5,4 +5,4 @@ JITSI_PRIVATE_MODE=false JITSI_ISS= SECRET_JITSI_KEY= ADMIN_API_TOKEN=123 -START_ROOM_URL=/Floor0/floor0.json \ No newline at end of file +START_ROOM_URL=/_/global/maps.workadventure.localhost/Floor0/floor0.json diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index b7788536..de8cd234 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -27,9 +27,9 @@ class ConnectionManager { const organizationSlug = data.organizationSlug; const worldSlug = data.worldSlug; const roomSlug = data.roomSlug; - urlManager.editUrlForRoom(roomSlug, organizationSlug, worldSlug); - const room = new Room(window.location.pathname + window.location.hash); + const room = new Room('/@/'+organizationSlug+'/'+worldSlug+'/'+roomSlug + window.location.hash); + urlManager.pushRoomIdToUrl(room); return Promise.resolve(room); } else if (connexionType === GameConnexionTypes.organization || connexionType === GameConnexionTypes.anonymous || connexionType === GameConnexionTypes.empty) { const localUser = localUserStore.getLocalUser(); @@ -48,11 +48,7 @@ class ConnectionManager { } let roomId: string if (connexionType === GameConnexionTypes.empty) { - if (START_ROOM_URL.startsWith('http://') || START_ROOM_URL.startsWith('https://')) { - roomId = '/_/global/' + START_ROOM_URL.replace('http://', '').replace('https://', ''); - } else { - roomId = urlManager.editUrlForRoom(START_ROOM_URL, null, null); - } + roomId = START_ROOM_URL; } else { roomId = window.location.pathname + window.location.hash; } diff --git a/front/src/Enum/EnvironmentVariable.ts b/front/src/Enum/EnvironmentVariable.ts index 0ee1906f..a71506eb 100644 --- a/front/src/Enum/EnvironmentVariable.ts +++ b/front/src/Enum/EnvironmentVariable.ts @@ -1,5 +1,5 @@ const DEBUG_MODE: boolean = process.env.DEBUG_MODE == "true"; -const START_ROOM_URL : string = process.env.START_ROOM_URL || 'tcm/workadventure/floor0'; +const START_ROOM_URL : string = process.env.START_ROOM_URL || '/_/global/maps.workadventure.localhost/Floor0/floor0.json'; const API_URL = (process.env.API_PROTOCOL || (typeof(window) !== 'undefined' ? window.location.protocol : 'http:')) + '//' + (process.env.API_URL || "pusher.workadventure.localhost"); const UPLOADER_URL = (process.env.API_PROTOCOL || (typeof(window) !== 'undefined' ? window.location.protocol : 'http:')) + '//' + (process.env.UPLOADER_URL || 'uploader.workadventure.localhost'); const ADMIN_URL = (process.env.API_PROTOCOL || (typeof(window) !== 'undefined' ? window.location.protocol : 'http:')) + '//' + (process.env.ADMIN_URL || "workadventure.localhost"); diff --git a/front/src/Url/UrlManager.ts b/front/src/Url/UrlManager.ts index 443dcee5..31862899 100644 --- a/front/src/Url/UrlManager.ts +++ b/front/src/Url/UrlManager.ts @@ -32,26 +32,12 @@ class UrlManager { return match ? match [1] : null; } - - //todo: simply use the roomId - //todo: test this with cypress - public editUrlForRoom(roomSlug: string, organizationSlug: string|null, worldSlug: string |null): string { - let newUrl:string; - if (organizationSlug) { - newUrl = '/@/'+organizationSlug+'/'+worldSlug+'/'+roomSlug; - } else { - newUrl = '/@/'+roomSlug; - } - history.pushState({}, 'WorkAdventure', newUrl); - return newUrl; - } - public pushRoomIdToUrl(room:Room): void { - if (window.location.pathname === room.id) return; + if (window.location.pathname === room.id) return; const hash = window.location.hash; history.pushState({}, 'WorkAdventure', room.id+hash); } - + public getStartLayerNameFromUrl(): string|null { const hash = window.location.hash; return hash.length > 1 ? hash.substring(1) : null;