Browse Source

Use constraints service for TURN and STUN data.

pull/190/head
Simon Eisenmann 10 years ago
parent
commit
9fd3826897
  1. 47
      static/js/controllers/mediastreamcontroller.js
  2. 27
      static/js/services/constraints.js

47
static/js/controllers/mediastreamcontroller.js

@ -97,12 +97,14 @@ define(['jquery', 'underscore', 'angular', 'bigscreen', 'moment', 'sjcl', 'moder @@ -97,12 +97,14 @@ define(['jquery', 'underscore', 'angular', 'bigscreen', 'moment', 'sjcl', 'moder
var displayName = safeDisplayName;
// Init STUN and TURN servers.
$scope.stun = mediaStream.config.StunURIs || [];
if (!$scope.stun.length) {
$scope.stun.push("stun:stun.l.google.com:19302")
// Init STUN.
(function() {
var stun = mediaStream.config.StunURIs || [];
if (!stun.length) {
stun.push("stun:stun.l.google.com:19302");
}
$scope.turn = {}; // TURN servers are set on received.self.
constraints.stun(stun);
})();
// Add browser details for easy access.
$scope.isChrome = $window.webrtcDetectedBrowser === "chrome";
@ -201,34 +203,8 @@ define(['jquery', 'underscore', 'angular', 'bigscreen', 'moment', 'sjcl', 'moder @@ -201,34 +203,8 @@ define(['jquery', 'underscore', 'angular', 'bigscreen', 'moment', 'sjcl', 'moder
};
$scope.refreshWebrtcSettings = function() {
if (!$window.webrtcDetectedBrowser) {
console.warn("This is not a WebRTC capable browser.");
return;
}
var settings = $scope.master.settings;
// Create iceServers from scope.
var iceServers = [];
var iceServer;
if ($scope.stun.length) {
iceServer = $window.createIceServers($scope.stun);
if (iceServer.length) {
iceServers.push.apply(iceServers, iceServer);
}
}
if ($scope.turn.urls && $scope.turn.urls.length) {
iceServer = $window.createIceServers($scope.turn.urls, $scope.turn.username, $scope.turn.password);
if (iceServer.length) {
iceServers.push.apply(iceServers, iceServer);
}
}
mediaStream.webrtc.settings.pcConfig.iceServers = iceServers;
// Refresh constraints.
constraints.refresh($scope.master.settings);
};
$scope.refreshWebrtcSettings(); // Call once for bootstrap.
@ -341,10 +317,13 @@ define(['jquery', 'underscore', 'angular', 'bigscreen', 'moment', 'sjcl', 'moder @@ -341,10 +317,13 @@ define(['jquery', 'underscore', 'angular', 'bigscreen', 'moment', 'sjcl', 'moder
scope.id = scope.myid = data.Id;
scope.userid = scope.myuserid = data.Userid ? data.Userid : null;
scope.suserid = data.Suserid ? data.Suserid : null;
scope.turn = data.Turn;
scope.stun = data.Stun;
scope.refreshWebrtcSettings();
});
// Set TURN and STUN data and refresh webrtc settings.
constraints.turn(data.Turn);
constraints.stun(data.Stun);
$scope.refreshWebrtcSettings();
if (data.Version !== mediaStream.version) {
console.info("Server was upgraded. Reload required.");
if (!reloadDialog) {

27
static/js/services/constraints.js

@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
*/
"use strict";
define(["jquery", "underscore"], function($, _) {
define(["jquery", "underscore", "webrtc.adapter"], function($, _) {
// constraints
return ["webrtc", "$window", "$q", function(webrtc, $window, $q) {
@ -99,6 +99,8 @@ @@ -99,6 +99,8 @@
// Define our service helpers
service.e = $({}); // events
service.stun = [];
service.turn = {};
// Create as WebRTC data structure.
service.mediaConstraints = function(constraints) {
@ -125,6 +127,26 @@ @@ -125,6 +127,26 @@
webrtc.settings.pcConstraints.optional = constraints.pc;
};
service.iceServers = function(constraints) {
var iceServers = [];
var iceServer;
if (service.stun && service.stun.length) {
iceServer = $window.createIceServers(service.stun);
if (iceServer.length) {
iceServers.push.apply(iceServers, iceServer)
}
}
if (service.turn && service.turn.urls && service.turn.urls.length) {
iceServer = $window.createIceServers(service.turn.urls, service.turn.username, service.turn.password);
if (iceServer.length) {
iceServers.push.apply(iceServers, iceServer)
}
}
webrtc.settings.pcConfig.iceServers = iceServers;
};
// Some default constraints.
service.e.on("refresh", function(event, constraints) {
@ -156,10 +178,11 @@ @@ -156,10 +178,11 @@
return $q.all(constraints.promises).then(function() {
service.mediaConstraints(constraints);
service.pcConstraints(constraints);
service.iceServers(constraints);
});
},
// Setters for TURN and STUN data.
turn: function(turnData) {
// Set TURN server details.
service.turn = turnData;
},
stun: function(stunData) {

Loading…
Cancel
Save