From ed116cf2a300c0c2f046d936b14a58b9b3c4ccc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 28 Aug 2020 13:52:25 +0200 Subject: [PATCH 1/4] Switching on our very own turn server --- deeployer.libsonnet | 5 ++++- docker-compose.yaml | 3 +++ front/src/Enum/EnvironmentVariable.ts | 6 ++++++ front/src/WebRtc/ScreenSharingPeer.ts | 7 ++++--- front/src/WebRtc/VideoPeer.ts | 7 ++++--- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/deeployer.libsonnet b/deeployer.libsonnet index 528342ed..620e9484 100644 --- a/deeployer.libsonnet +++ b/deeployer.libsonnet @@ -26,7 +26,10 @@ "ports": [80], "env": { "API_URL": "api."+url, - "JITSI_URL": "meet.jit.si" + "JITSI_URL": "meet.jit.si", + "TURN_SERVER": "coturn.workadventu.re:443", + "TURN_USER": "workadventure", + "TURN_PASSWORD": "WorkAdventure123" } }, "website": { diff --git a/docker-compose.yaml b/docker-compose.yaml index d944e0f8..e731bbed 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -27,6 +27,9 @@ services: NODE_ENV: development API_URL: api.workadventure.localhost STARTUP_COMMAND_1: yarn install + TURN_SERVER: "turn:coturn.workadventu.re:443,turns:coturn.workadventu.re:443" + TURN_USER: workadventure + TURN_PASSWORD: WorkAdventure123 command: yarn run start volumes: - ./front:/usr/src/app diff --git a/front/src/Enum/EnvironmentVariable.ts b/front/src/Enum/EnvironmentVariable.ts index 97a3f91b..59c8b50f 100644 --- a/front/src/Enum/EnvironmentVariable.ts +++ b/front/src/Enum/EnvironmentVariable.ts @@ -1,5 +1,8 @@ const DEBUG_MODE: boolean = process.env.DEBUG_MODE == "true"; const API_URL = (typeof(window) !== 'undefined' ? window.location.protocol : 'http:') + '//' + (process.env.API_URL || "api.workadventure.localhost"); +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 RESOLUTION = 3; const ZOOM_LEVEL = 1/*3/4*/; @@ -13,5 +16,8 @@ export { ZOOM_LEVEL, POSITION_DELAY, MAX_EXTRAPOLATION_TIME, + TURN_SERVER, + TURN_USER, + TURN_PASSWORD, JITSI_URL } diff --git a/front/src/WebRtc/ScreenSharingPeer.ts b/front/src/WebRtc/ScreenSharingPeer.ts index 3f43a70f..3774c612 100644 --- a/front/src/WebRtc/ScreenSharingPeer.ts +++ b/front/src/WebRtc/ScreenSharingPeer.ts @@ -1,6 +1,7 @@ import * as SimplePeerNamespace from "simple-peer"; import {mediaManager} from "./MediaManager"; import {Connection} from "../Connection"; +import {TURN_SERVER, TURN_USER, TURN_PASSWORD} from "../Enum/EnvironmentVariable"; const Peer: SimplePeerNamespace.SimplePeer = require('simple-peer'); @@ -23,9 +24,9 @@ export class ScreenSharingPeer extends Peer { urls: 'stun:stun.l.google.com:19302' }, { - urls: 'turn:numb.viagenie.ca', - username: 'g.parant@thecodingmachine.com', - credential: 'itcugcOHxle9Acqi$' + urls: TURN_SERVER, + username: TURN_USER, + credential: TURN_PASSWORD }, ] } diff --git a/front/src/WebRtc/VideoPeer.ts b/front/src/WebRtc/VideoPeer.ts index 3ffe33e7..0124eee5 100644 --- a/front/src/WebRtc/VideoPeer.ts +++ b/front/src/WebRtc/VideoPeer.ts @@ -1,6 +1,7 @@ import * as SimplePeerNamespace from "simple-peer"; import {mediaManager} from "./MediaManager"; import {Connection} from "../Connection"; +import {TURN_PASSWORD, TURN_SERVER, TURN_USER} from "../Enum/EnvironmentVariable"; const Peer: SimplePeerNamespace.SimplePeer = require('simple-peer'); @@ -18,9 +19,9 @@ export class VideoPeer extends Peer { urls: 'stun:stun.l.google.com:19302' }, { - urls: 'turn:numb.viagenie.ca', - username: 'g.parant@thecodingmachine.com', - credential: 'itcugcOHxle9Acqi$' + urls: TURN_SERVER, + username: TURN_USER, + credential: TURN_PASSWORD }, ] } From 3875c0afe83dbb1f3ed323c9280a0f4a984a0168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 28 Aug 2020 16:18:26 +0200 Subject: [PATCH 2/4] Fixing environment variable passing in Webpack --- front/webpack.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/webpack.config.js b/front/webpack.config.js index 7ffbcfcc..3083fd25 100644 --- a/front/webpack.config.js +++ b/front/webpack.config.js @@ -42,7 +42,7 @@ module.exports = { new webpack.ProvidePlugin({ Phaser: 'phaser' }), - new webpack.EnvironmentPlugin(['API_URL', 'DEBUG_MODE', 'JITSI_URL']) + new webpack.EnvironmentPlugin(['API_URL', 'DEBUG_MODE', 'TURN_SERVER', 'TURN_USER', 'TURN_PASSWORD', 'JITSI_URL']) ], }; From 8655aef6298d34f1895f6555b063ceabd0120051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 28 Aug 2020 16:29:21 +0200 Subject: [PATCH 3/4] Fixing URL passing in WebRtc setup --- front/src/WebRtc/ScreenSharingPeer.ts | 2 +- front/src/WebRtc/VideoPeer.ts | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/front/src/WebRtc/ScreenSharingPeer.ts b/front/src/WebRtc/ScreenSharingPeer.ts index 3774c612..8857274e 100644 --- a/front/src/WebRtc/ScreenSharingPeer.ts +++ b/front/src/WebRtc/ScreenSharingPeer.ts @@ -24,7 +24,7 @@ export class ScreenSharingPeer extends Peer { urls: 'stun:stun.l.google.com:19302' }, { - urls: TURN_SERVER, + urls: TURN_SERVER.split(','), username: TURN_USER, credential: TURN_PASSWORD }, diff --git a/front/src/WebRtc/VideoPeer.ts b/front/src/WebRtc/VideoPeer.ts index 0124eee5..33422433 100644 --- a/front/src/WebRtc/VideoPeer.ts +++ b/front/src/WebRtc/VideoPeer.ts @@ -19,7 +19,7 @@ export class VideoPeer extends Peer { urls: 'stun:stun.l.google.com:19302' }, { - urls: TURN_SERVER, + urls: TURN_SERVER.split(','), username: TURN_USER, credential: TURN_PASSWORD }, @@ -27,6 +27,23 @@ export class VideoPeer extends Peer { } }); + console.log('PEER SETUP ', { + initiator: initiator ? initiator : false, + reconnectTimer: 10000, + config: { + iceServers: [ + { + urls: 'stun:stun.l.google.com:19302' + }, + { + urls: TURN_SERVER, + username: TURN_USER, + credential: TURN_PASSWORD + }, + ] + } + }) + //start listen signal for the peer connection this.on('signal', (data: unknown) => { this.sendWebrtcSignal(data); From b6590e21dd310f48fc840d99b15cecbf5addeca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 28 Aug 2020 17:30:33 +0200 Subject: [PATCH 4/4] Fixing coturn URLS --- deeployer.libsonnet | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeployer.libsonnet b/deeployer.libsonnet index 620e9484..d6cd232b 100644 --- a/deeployer.libsonnet +++ b/deeployer.libsonnet @@ -27,7 +27,7 @@ "env": { "API_URL": "api."+url, "JITSI_URL": "meet.jit.si", - "TURN_SERVER": "coturn.workadventu.re:443", + "TURN_SERVER": "turn:coturn.workadventu.re:443,turns:coturn.workadventu.re:443", "TURN_USER": "workadventure", "TURN_PASSWORD": "WorkAdventure123" }