diff --git a/static/js/directives/settings.js b/static/js/directives/settings.js index 075a5c38..4cbfe48b 100644 --- a/static/js/directives/settings.js +++ b/static/js/directives/settings.js @@ -55,7 +55,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t return ["$compile", "mediaStream", function($compile, mediaStream) { - var controller = ['$scope', 'desktopNotify', 'mediaSources', 'safeApply', 'availableLanguages', 'translation', 'localStorage', 'userSettingsData', 'constraints', 'appData', '$timeout', function($scope, desktopNotify, mediaSources, safeApply, availableLanguages, translation, localStorage, userSettingsData, constraints, appData, $timeout) { + var controller = ['$scope', 'desktopNotify', 'mediaSources', 'safeApply', 'availableLanguages', 'translation', 'localStorage', 'userSettingsData', 'constraints', 'appData', '$timeout', 'turnSettings', function($scope, desktopNotify, mediaSources, safeApply, availableLanguages, translation, localStorage, userSettingsData, constraints, appData, $timeout, turnSettings) { $scope.layout.settings = false; $scope.showAdvancedSettings = true; @@ -70,18 +70,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t $scope.withUsers = mediaStream.config.UsersEnabled; $scope.withUsersRegistration = mediaStream.config.UsersAllowRegistration; $scope.withUsersMode = mediaStream.config.UsersMode; - $scope.withTurnCustomizable = mediaStream.config.TurnURIsClientSideSetable; - - var updateTurnSettings = function() { - constraints.turn($scope.user.settings.webrtc.turn); - }; - - if ($scope.withTurnCustomizable && $scope.user.settings.webrtc.turn.urls) { - // Overwrite server Turn settings - appData.e.one("userSettingsLoaded", function() { - updateTurnSettings(); - }); - } + $scope.withTurnCustomizable = turnSettings.showClientSideTurnOptions(); _.each(availableLanguages, function(name, code) { $scope.availableLanguages.push({ @@ -102,9 +91,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t if (form.$valid && form.$dirty) { var user = $scope.user; $scope.update(user); - if ($scope.withTurnCustomizable) { - updateTurnSettings(); - } + turnSettings.update($scope.user.settings.webrtc.turn); if ($scope.rememberSettings) { userSettingsData.save(user); localStorage.setItem("mediastream-language", user.settings.language || ""); diff --git a/static/js/mediastream/api.js b/static/js/mediastream/api.js index 058b523c..4cb09f02 100644 --- a/static/js/mediastream/api.js +++ b/static/js/mediastream/api.js @@ -151,7 +151,7 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) { switch (dataType) { case "Self": - //console.log("Self received", data); + console.log("Self received", data); if (data.Token) { this.connector.token = data.Token; } diff --git a/static/js/services/constraints.js b/static/js/services/constraints.js index eefb8c5a..6dbf409d 100644 --- a/static/js/services/constraints.js +++ b/static/js/services/constraints.js @@ -143,6 +143,7 @@ iceServers.push(createIceServers(service.stun)); } if (service.turn && service.turn.urls && service.turn.urls.length) { + console.log('iceServers', service.turn); iceServers.push(createIceServers(service.turn.urls, service.turn.username, service.turn.password)); } webrtc.settings.pcConfig.iceServers = iceServers; @@ -185,6 +186,7 @@ // Setters for TURN and STUN data. turn: function(turnData) { service.turn = turnData; + console.log("turnData", service.turn); }, stun: function(stunData) { service.stun = stunData; @@ -211,4 +213,4 @@ }]; - }); \ No newline at end of file + }); diff --git a/static/js/services/services.js b/static/js/services/services.js index 4fa9919a..35a1abe3 100644 --- a/static/js/services/services.js +++ b/static/js/services/services.js @@ -70,7 +70,8 @@ define([ 'services/mediadevices', 'services/sandbox', 'services/dummystream', - 'services/usermedia'], function(_, + 'services/usermedia', + 'services/turnsettings'], function(_, desktopNotify, playSound, safeApply, @@ -118,7 +119,8 @@ modules, mediaDevices, sandbox, dummyStream, -userMedia) { +userMedia, +turnSettings) { var services = { desktopNotify: desktopNotify, @@ -168,7 +170,8 @@ userMedia) { mediaDevices: mediaDevices, sandbox: sandbox, dummyStream: dummyStream, - userMedia: userMedia + userMedia: userMedia, + turnSettings: turnSettings }; var initialize = function(angModule) { diff --git a/static/js/services/turnsettings.js b/static/js/services/turnsettings.js new file mode 100644 index 00000000..a2466b27 --- /dev/null +++ b/static/js/services/turnsettings.js @@ -0,0 +1,76 @@ +/* + * Spreed WebRTC. + * Copyright (C) 2013-2015 struktur AG + * + * This file is part of Spreed WebRTC. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +define(["angular"], function(angular) { + "use strict"; + + /** + * turnSettings + * Service to correctly sync client and server side TURN settings to contraints.js + * See contraints.js for actual TURN configuration in use for a connection + */ + return ['mediaStream', 'appData', 'constraints', function(mediaStream, appData, constraints) { + + var preferClientSideTurnSettings = mediaStream.config.TurnURIsClientSideSetable; + var turnConfigServer = null; + + /** + * @param Object config Turn configuration object + * @param Array config.urls + * @param String config.username + * @param String config.password + */ + var updateTurnSettings = function(config) { + if (!preferClientSideTurnSettings) { + return; + } + if (config.urls.length) { + constraints.turn(config); + // Apply original server side TURN settings when user removes client side TURN settings + } else if (turnConfigServer && turnConfigServer.urls.length) { + constraints.turn(turnConfigServer); + } + }; + + if (preferClientSideTurnSettings) { + // Overwrite server Turn settings when loading app + appData.e.one("userSettingsLoaded", function(event, loadedUser, user) { + if (user) { + updateTurnSettings(user.settings.webrtc.turn); + } + }); + // Set server side TURN settings + mediaStream.api.e.on("received.self", function(event, data) { + if (data.Turn && data.Turn.urls.length) { + turnConfigServer = data.Turn; + } + }); + } + + return { + showClientSideTurnOptions: function() { + return preferClientSideTurnSettings; + }, + update: updateTurnSettings + }; + + }]; +});