diff --git a/contrib/docker/docker-compose.prod.yaml b/contrib/docker/docker-compose.prod.yaml index c726ba84..6b3b8520 100644 --- a/contrib/docker/docker-compose.prod.yaml +++ b/contrib/docker/docker-compose.prod.yaml @@ -37,7 +37,7 @@ services: DEBUG_MODE: "$DEBUG_MODE" JITSI_URL: $JITSI_URL JITSI_PRIVATE_MODE: "$JITSI_PRIVATE_MODE" - API_URL: pusher.${DOMAIN} + PUSHER_URL: //pusher.${DOMAIN} TURN_SERVER: "${TURN_SERVER}" TURN_USER: "${TURN_USER}" TURN_PASSWORD: "${TURN_PASSWORD}" diff --git a/deeployer.libsonnet b/deeployer.libsonnet index 52cea293..07506f11 100644 --- a/deeployer.libsonnet +++ b/deeployer.libsonnet @@ -82,9 +82,9 @@ }, "ports": [80], "env": { - "API_URL": "pusher."+url, - "UPLOADER_URL": "uploader."+url, - "ADMIN_URL": url, + "PUSHER_URL": "//pusher."+url, + "UPLOADER_URL": "//uploader."+url, + "ADMIN_URL": "//"+url, "JITSI_URL": env.JITSI_URL, "SECRET_JITSI_KEY": env.SECRET_JITSI_KEY, "TURN_SERVER": "turn:coturn.workadventu.re:443,turns:coturn.workadventu.re:443", diff --git a/docker-compose.single-domain.yaml b/docker-compose.single-domain.yaml index 3ffecb60..e8842e8b 100644 --- a/docker-compose.single-domain.yaml +++ b/docker-compose.single-domain.yaml @@ -26,7 +26,7 @@ services: JITSI_PRIVATE_MODE: "$JITSI_PRIVATE_MODE" HOST: "0.0.0.0" NODE_ENV: development - API_URL: /pusher + PUSHER_URL: /pusher UPLOADER_URL: /uploader ADMIN_URL: /admin MAPS_URL: /maps diff --git a/docker-compose.yaml b/docker-compose.yaml index 9ea637a3..504c5b23 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -26,9 +26,9 @@ services: JITSI_PRIVATE_MODE: "$JITSI_PRIVATE_MODE" HOST: "0.0.0.0" NODE_ENV: development - API_URL: pusher.workadventure.localhost - UPLOADER_URL: uploader.workadventure.localhost - ADMIN_URL: workadventure.localhost + PUSHER_URL: //pusher.workadventure.localhost + UPLOADER_URL: //uploader.workadventure.localhost + ADMIN_URL: //workadventure.localhost STARTUP_COMMAND_1: ./templater.sh STARTUP_COMMAND_2: yarn install STUN_SERVER: "stun:stun.l.google.com:19302" diff --git a/front/Dockerfile b/front/Dockerfile index 51734535..ef724e0f 100644 --- a/front/Dockerfile +++ b/front/Dockerfile @@ -3,7 +3,7 @@ WORKDIR /var/www/messages COPY --chown=docker:docker messages . RUN yarn install && yarn proto -# we are rebuilding on each deploy to cope with the API_URL environment URL +# we are rebuilding on each deploy to cope with the PUSHER_URL environment URL FROM thecodingmachine/nodejs:14-apache COPY --chown=docker:docker front . diff --git a/front/src/Administration/GlobalMessageManager.ts b/front/src/Administration/GlobalMessageManager.ts index f30329d9..bc9f3cfe 100644 --- a/front/src/Administration/GlobalMessageManager.ts +++ b/front/src/Administration/GlobalMessageManager.ts @@ -1,6 +1,6 @@ import {HtmlUtils} from "./../WebRtc/HtmlUtils"; import {AUDIO_TYPE, MESSAGE_TYPE} from "./ConsoleGlobalMessageManager"; -import {API_URL, UPLOADER_URL} from "../Enum/EnvironmentVariable"; +import {PUSHER_URL, UPLOADER_URL} from "../Enum/EnvironmentVariable"; import {RoomConnection} from "../Connexion/RoomConnection"; import {PlayGlobalMessageInterface} from "../Connexion/ConnexionModels"; diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index aa679b5e..04c93a3e 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -1,5 +1,5 @@ import Axios from "axios"; -import {API_URL, START_ROOM_URL} from "../Enum/EnvironmentVariable"; +import {PUSHER_URL, START_ROOM_URL} from "../Enum/EnvironmentVariable"; import {RoomConnection} from "./RoomConnection"; import {OnConnectInterface, PositionInterface, ViewportInterface} from "./ConnexionModels"; import {GameConnexionTypes, urlManager} from "../Url/UrlManager"; @@ -34,7 +34,7 @@ class ConnectionManager { this.connexionType = connexionType; if(connexionType === GameConnexionTypes.register) { const organizationMemberToken = urlManager.getOrganizationToken(); - const data = await Axios.post(`${API_URL}/register`, {organizationMemberToken}).then(res => res.data); + const data = await Axios.post(`${PUSHER_URL}/register`, {organizationMemberToken}).then(res => res.data); this.localUser = new LocalUser(data.userUuid, data.authToken, data.textures); localUserStore.saveUser(this.localUser); @@ -73,11 +73,11 @@ class ConnectionManager { } private async verifyToken(token: string): Promise { - await Axios.get(`${API_URL}/verify`, {params: {token}}); + await Axios.get(`${PUSHER_URL}/verify`, {params: {token}}); } public async anonymousLogin(isBenchmark: boolean = false): Promise { - const data = await Axios.post(`${API_URL}/anonymLogin`).then(res => res.data); + const data = await Axios.post(`${PUSHER_URL}/anonymLogin`).then(res => res.data); this.localUser = new LocalUser(data.userUuid, data.authToken, []); if (!isBenchmark) { // In benchmark, we don't have a local storage. localUserStore.saveUser(this.localUser); diff --git a/front/src/Connexion/Room.ts b/front/src/Connexion/Room.ts index 782d5edf..05d94440 100644 --- a/front/src/Connexion/Room.ts +++ b/front/src/Connexion/Room.ts @@ -1,5 +1,5 @@ import Axios from "axios"; -import {API_URL} from "../Enum/EnvironmentVariable"; +import {PUSHER_URL} from "../Enum/EnvironmentVariable"; export class Room { public readonly id: string; @@ -67,7 +67,7 @@ export class Room { // We have a private ID, we need to query the map URL from the server. const urlParts = this.parsePrivateUrl(this.id); - Axios.get(`${API_URL}/map`, { + Axios.get(`${PUSHER_URL}/map`, { params: urlParts }).then(({data}) => { console.log('Map ', this.id, ' resolves to URL ', data.mapUrl); diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index 584dae06..0793851d 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -1,4 +1,4 @@ -import {API_URL, UPLOADER_URL} from "../Enum/EnvironmentVariable"; +import {PUSHER_URL, UPLOADER_URL} from "../Enum/EnvironmentVariable"; import Axios from "axios"; import { BatchMessage, @@ -67,7 +67,11 @@ export class RoomConnection implements RoomConnection { * @param roomId The ID of the room in the form "_/[instance]/[map_url]" or "@/[org]/[event]/[map]" */ public constructor(token: string|null, roomId: string, name: string, characterLayers: string[], position: PositionInterface, viewport: ViewportInterface) { - let url = API_URL.replace('http://', 'ws://').replace('https://', 'wss://'); + let url = PUSHER_URL; + if (url.startsWith('//')) { + url = window.location.protocol+url; + } + url = url.replace('http://', 'ws://').replace('https://', 'wss://'); url += '/room'; url += '?roomId='+(roomId ?encodeURIComponent(roomId):''); url += '&token='+(token ?encodeURIComponent(token):''); @@ -381,7 +385,7 @@ export class RoomConnection implements RoomConnection { public onConnectError(callback: (error: Event) => void): void { this.socket.addEventListener('error', callback) } - + public onConnect(callback: (roomConnection: OnConnectInterface) => void): void { //this.socket.addEventListener('open', callback) this.onMessage(EventMessage.CONNECT, callback); diff --git a/front/src/Enum/EnvironmentVariable.ts b/front/src/Enum/EnvironmentVariable.ts index 844bf564..ea2434af 100644 --- a/front/src/Enum/EnvironmentVariable.ts +++ b/front/src/Enum/EnvironmentVariable.ts @@ -1,8 +1,9 @@ const DEBUG_MODE: boolean = process.env.DEBUG_MODE == "true"; 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"); +// For compatibility reasons with older versions, API_URL is the old host name of PUSHER_URL +const PUSHER_URL = process.env.PUSHER_URL || (process.env.API_URL ? '//'+process.env.API_URL : "//pusher.workadventure.localhost"); +const UPLOADER_URL = process.env.UPLOADER_URL || '//uploader.workadventure.localhost'; +const ADMIN_URL = process.env.ADMIN_URL || "//workadventure.localhost"; const STUN_SERVER: string = process.env.STUN_SERVER || "stun:stun.l.google.com:19302"; const TURN_SERVER: string = process.env.TURN_SERVER || ""; const TURN_USER: string = process.env.TURN_USER || ''; @@ -17,7 +18,7 @@ const MAX_EXTRAPOLATION_TIME = 100; // Extrapolate a maximum of 250ms if no new export { DEBUG_MODE, START_ROOM_URL, - API_URL, + PUSHER_URL, UPLOADER_URL, ADMIN_URL, RESOLUTION, diff --git a/front/webpack.config.js b/front/webpack.config.js index aec70d4a..54d5fffc 100644 --- a/front/webpack.config.js +++ b/front/webpack.config.js @@ -70,6 +70,7 @@ module.exports = { }), new webpack.EnvironmentPlugin([ 'API_URL', + 'PUSHER_URL', 'UPLOADER_URL', 'ADMIN_URL', 'DEBUG_MODE', diff --git a/maps/Dockerfile b/maps/Dockerfile index 33ca48b5..7fc6fd19 100644 --- a/maps/Dockerfile +++ b/maps/Dockerfile @@ -1,4 +1,3 @@ -# we are rebuilding on each deploy to cope with the API_URL environment URL FROM thecodingmachine/nodejs:12-apache COPY --chown=docker:docker . .