From 069d7a2338ea36c004493cdb15e7d82f11ebe7ff Mon Sep 17 00:00:00 2001 From: Shekar Siri Date: Sun, 21 Nov 2021 22:41:37 +0530 Subject: [PATCH] change(ui) - peerjs iceserver env config --- .../managers/AssistManager.ts | 14 ++++++++--- frontend/app/utils.js | 25 ++++++++++++++++++- frontend/env.js | 1 + 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/frontend/app/player/MessageDistributor/managers/AssistManager.ts b/frontend/app/player/MessageDistributor/managers/AssistManager.ts index 1169fbace..074b6841f 100644 --- a/frontend/app/player/MessageDistributor/managers/AssistManager.ts +++ b/frontend/app/player/MessageDistributor/managers/AssistManager.ts @@ -6,8 +6,8 @@ import type { Message } from '../messages' import { ID_TP_MAP } from '../messages'; import store from 'App/store'; import type { LocalStream } from './LocalStream'; - import { update, getState } from '../../store'; +import { iceServerConfigFromString } from 'App/utils' export enum CallingState { @@ -149,12 +149,20 @@ export default class AssistManager { this.setStatus(ConnectionStatus.Connecting) import('peerjs').then(({ default: Peer }) => { // @ts-ignore - const peer = new Peer({ + const iceServers = iceServerConfigFromString(window.ENV.ICE_SERVERS); + const _config = { // @ts-ignore host: new URL(window.ENV.API_EDP).host, path: '/assist', port: location.protocol === 'https:' ? 443 : 80, - }); + sdpSemantics: 'unified-plan' + } + + if (iceServers) { + _config['config'] = iceServers; + } + + const peer = new Peer(_config); this.peer = peer; peer.on('error', e => { if (e.type !== 'peer-unavailable') { diff --git a/frontend/app/utils.js b/frontend/app/utils.js index 45a8c3356..55cace98b 100644 --- a/frontend/app/utils.js +++ b/frontend/app/utils.js @@ -203,4 +203,27 @@ export const colorScale = (values, colors) => { .range([colors[0], colors[colors.length - 1]]); } -export const truncate = (input, max = 10) => input.length > max ? `${input.substring(0, max)}...` : input; \ No newline at end of file +export const truncate = (input, max = 10) => input.length > max ? `${input.substring(0, max)}...` : input; + +export const iceServerConfigFromString = (str) => { + if (!str || typeof str !== 'string'|| str.length === 0) { + return null; + } + + return str.split("|").map(function(c) { + let server = null + const arr = c.split(",") + + if (!!arr[0] !== "") { + server = {} + server.urls = arr[0] + if (!!arr[1]) { + server.username = arr[1] + if (!!arr[2]) { + server.password = arr[2] + } + } + return server + } + }) +} \ No newline at end of file diff --git a/frontend/env.js b/frontend/env.js index 7b73b52ab..9218bcd70 100644 --- a/frontend/env.js +++ b/frontend/env.js @@ -20,6 +20,7 @@ const oss = { MINIO_USE_SSL: process.env.MINIO_USE_SSL, MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY, MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY, + ICE_SERVERS: process.env.ICE_SERVERS, TRACKER_VERSION: '3.4.7', // trackerInfo.version, }