Browse Source

Create turnSettings service to correctly prefer cient or server TURN configuration.

pull/242/head
Evan Theurer 11 years ago
parent
commit
d847bb73e3
  1. 19
      static/js/directives/settings.js
  2. 2
      static/js/mediastream/api.js
  3. 4
      static/js/services/constraints.js
  4. 9
      static/js/services/services.js
  5. 76
      static/js/services/turnsettings.js

19
static/js/directives/settings.js

@ -55,7 +55,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
return ["$compile", "mediaStream", function($compile, mediaStream) { 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.layout.settings = false;
$scope.showAdvancedSettings = true; $scope.showAdvancedSettings = true;
@ -70,18 +70,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
$scope.withUsers = mediaStream.config.UsersEnabled; $scope.withUsers = mediaStream.config.UsersEnabled;
$scope.withUsersRegistration = mediaStream.config.UsersAllowRegistration; $scope.withUsersRegistration = mediaStream.config.UsersAllowRegistration;
$scope.withUsersMode = mediaStream.config.UsersMode; $scope.withUsersMode = mediaStream.config.UsersMode;
$scope.withTurnCustomizable = mediaStream.config.TurnURIsClientSideSetable; $scope.withTurnCustomizable = turnSettings.showClientSideTurnOptions();
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();
});
}
_.each(availableLanguages, function(name, code) { _.each(availableLanguages, function(name, code) {
$scope.availableLanguages.push({ $scope.availableLanguages.push({
@ -102,9 +91,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
if (form.$valid && form.$dirty) { if (form.$valid && form.$dirty) {
var user = $scope.user; var user = $scope.user;
$scope.update(user); $scope.update(user);
if ($scope.withTurnCustomizable) { turnSettings.update($scope.user.settings.webrtc.turn);
updateTurnSettings();
}
if ($scope.rememberSettings) { if ($scope.rememberSettings) {
userSettingsData.save(user); userSettingsData.save(user);
localStorage.setItem("mediastream-language", user.settings.language || ""); localStorage.setItem("mediastream-language", user.settings.language || "");

2
static/js/mediastream/api.js

@ -151,7 +151,7 @@ define(['jquery', 'underscore', 'ua-parser'], function($, _, uaparser) {
switch (dataType) { switch (dataType) {
case "Self": case "Self":
//console.log("Self received", data); console.log("Self received", data);
if (data.Token) { if (data.Token) {
this.connector.token = data.Token; this.connector.token = data.Token;
} }

4
static/js/services/constraints.js

@ -143,6 +143,7 @@
iceServers.push(createIceServers(service.stun)); iceServers.push(createIceServers(service.stun));
} }
if (service.turn && service.turn.urls && service.turn.urls.length) { 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)); iceServers.push(createIceServers(service.turn.urls, service.turn.username, service.turn.password));
} }
webrtc.settings.pcConfig.iceServers = iceServers; webrtc.settings.pcConfig.iceServers = iceServers;
@ -185,6 +186,7 @@
// Setters for TURN and STUN data. // Setters for TURN and STUN data.
turn: function(turnData) { turn: function(turnData) {
service.turn = turnData; service.turn = turnData;
console.log("turnData", service.turn);
}, },
stun: function(stunData) { stun: function(stunData) {
service.stun = stunData; service.stun = stunData;
@ -211,4 +213,4 @@
}]; }];
}); });

9
static/js/services/services.js

@ -70,7 +70,8 @@ define([
'services/mediadevices', 'services/mediadevices',
'services/sandbox', 'services/sandbox',
'services/dummystream', 'services/dummystream',
'services/usermedia'], function(_, 'services/usermedia',
'services/turnsettings'], function(_,
desktopNotify, desktopNotify,
playSound, playSound,
safeApply, safeApply,
@ -118,7 +119,8 @@ modules,
mediaDevices, mediaDevices,
sandbox, sandbox,
dummyStream, dummyStream,
userMedia) { userMedia,
turnSettings) {
var services = { var services = {
desktopNotify: desktopNotify, desktopNotify: desktopNotify,
@ -168,7 +170,8 @@ userMedia) {
mediaDevices: mediaDevices, mediaDevices: mediaDevices,
sandbox: sandbox, sandbox: sandbox,
dummyStream: dummyStream, dummyStream: dummyStream,
userMedia: userMedia userMedia: userMedia,
turnSettings: turnSettings
}; };
var initialize = function(angModule) { var initialize = function(angModule) {

76
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 <http://www.gnu.org/licenses/>.
*
*/
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
};
}];
});
Loading…
Cancel
Save