diff --git a/.env.template b/.env.template index 58be4d67..d1ee2885 100644 --- a/.env.template +++ b/.env.template @@ -1,4 +1,6 @@ DEBUG_MODE=false JITSI_URL=meet.jit.si +# If your Jitsi environment has authentication set up, you MUST set JITSI_PRIVATE_MODE to "true" and you MUST pass a SECRET_JITSI_KEY to generate the JWT secret +JITSI_PRIVATE_MODE=false SECRET_JITSI_KEY= ADMIN_API_TOKEN=123 diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index 6656225b..d6cf44af 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -612,7 +612,7 @@ class SocketManager { "aud": "jitsi", "iss": "meetworkadventure", "sub": "coremeet.workadventu.re", - "room": "*" + "room": room }, SECRET_JITSI_KEY, { expiresIn: '1d', algorithm: "HS256", diff --git a/docker-compose.yaml b/docker-compose.yaml index 15485b89..4684d53e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -23,6 +23,7 @@ services: environment: DEBUG_MODE: "$DEBUG_MODE" JITSI_URL: $JITSI_URL + JITSI_PRIVATE_MODE: "$JITSI_PRIVATE_MODE" HOST: "0.0.0.0" NODE_ENV: development API_URL: api.workadventure.localhost diff --git a/front/src/Enum/EnvironmentVariable.ts b/front/src/Enum/EnvironmentVariable.ts index 0479d252..16918e06 100644 --- a/front/src/Enum/EnvironmentVariable.ts +++ b/front/src/Enum/EnvironmentVariable.ts @@ -4,6 +4,7 @@ const TURN_SERVER: string = process.env.TURN_SERVER || "turn:numb.viagenie.ca"; const TURN_USER: string = process.env.TURN_USER || 'g.parant@thecodingmachine.com'; const TURN_PASSWORD: string = process.env.TURN_PASSWORD || 'itcugcOHxle9Acqi$'; const JITSI_URL : string|undefined = (process.env.JITSI_URL === '') ? undefined : process.env.JITSI_URL; +const JITSI_PRIVATE_MODE : boolean = process.env.JITSI_PRIVATE_MODE == "true"; const RESOLUTION = 3; const ZOOM_LEVEL = 1/*3/4*/; const POSITION_DELAY = 200; // Wait 200ms between sending position events @@ -19,5 +20,6 @@ export { TURN_SERVER, TURN_USER, TURN_PASSWORD, - JITSI_URL + JITSI_URL, + JITSI_PRIVATE_MODE } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 698af09a..d450a7ce 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -9,7 +9,14 @@ import { RoomJoinedMessageInterface } from "../../Connexion/ConnexionModels"; import {CurrentGamerInterface, hasMovedEventName, Player} from "../Player/Player"; -import {DEBUG_MODE, JITSI_URL, POSITION_DELAY, RESOLUTION, ZOOM_LEVEL} from "../../Enum/EnvironmentVariable"; +import { + DEBUG_MODE, + JITSI_PRIVATE_MODE, + JITSI_URL, + POSITION_DELAY, + RESOLUTION, + ZOOM_LEVEL +} from "../../Enum/EnvironmentVariable"; import { ITiledMap, ITiledMapLayer, @@ -466,10 +473,14 @@ export class GameScene extends ResizableScene implements CenterListener { if (newValue === undefined) { this.stopJitsi(); } else { - // TODO: get jitsiRoomAdminTag - const adminTag = allProps.get("jitsiRoomAdminTag") as string|undefined; + console.log("JITSI_PRIVATE_MODE", JITSI_PRIVATE_MODE); + if (JITSI_PRIVATE_MODE) { + const adminTag = allProps.get("jitsiRoomAdminTag") as string|undefined; - this.connection.emitQueryJitsiJwtMessage(this.instance + "-" + newValue, adminTag); + this.connection.emitQueryJitsiJwtMessage(this.instance + "-" + newValue, adminTag); + } else { + this.startJitsi(newValue as string); + } } }) @@ -579,6 +590,9 @@ export class GameScene extends ResizableScene implements CenterListener { item.fire(message.event, message.state, message.parameters); })); + /** + * Triggered when we receive the JWT token to connect to Jitsi + */ connection.onStartJitsiRoom((jwt, room) => { this.startJitsi(room, jwt); }); @@ -1178,7 +1192,7 @@ export class GameScene extends ResizableScene implements CenterListener { this.updateCameraOffset(); } - public startJitsi(roomName: string, jwt: string): void { + public startJitsi(roomName: string, jwt?: string): void { CoWebsiteManager.insertCoWebsite((cowebsiteDiv => { const domain = JITSI_URL; const options = { @@ -1195,6 +1209,9 @@ export class GameScene extends ResizableScene implements CenterListener { MOBILE_APP_PROMO: false } }; + if (!options.jwt) { + delete options.jwt; + } this.jitsiApi = new (window as any).JitsiMeetExternalAPI(domain, options); // eslint-disable-line @typescript-eslint/no-explicit-any this.jitsiApi.executeCommand('displayName', gameManager.getPlayerName()); })); diff --git a/front/webpack.config.js b/front/webpack.config.js index cf8112ab..218b7374 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', 'DEBUG_MODE', 'TURN_SERVER', 'TURN_USER', 'TURN_PASSWORD', 'JITSI_URL']) + new webpack.EnvironmentPlugin(['API_URL', 'DEBUG_MODE', 'TURN_SERVER', 'TURN_USER', 'TURN_PASSWORD', 'JITSI_URL', 'JITSI_PRIVATE_MODE']) ], };