Browse Source

Added support to create a working audio or video only peer connection without either video or audio input device.

pull/156/head
Simon Eisenmann 11 years ago
parent
commit
5f5e1e340a
  1. 51
      static/js/directives/settings.js
  2. 57
      static/js/services/constraints.js
  3. 12
      static/js/services/mediasources.js

51
static/js/directives/settings.js

@ -111,28 +111,15 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t @@ -111,28 +111,15 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
};
$scope.checkDefaultMediaSources = function() {
// Check if the stuff exists.
if ($scope.master.settings.microphoneId && !$scope.mediaSources.hasAudioId($scope.master.settings.microphoneId)) {
$scope.master.settings.microphoneId = null;
}
if ($scope.master.settings.cameraId && !$scope.mediaSources.hasVideoId($scope.master.settings.cameraId)) {
$scope.master.settings.cameraId = null;
}
var audio = $scope.mediaSources.audio;
var video = $scope.mediaSources.video;
if (!$scope.master.settings.microphoneId && audio.length > 0) {
$scope.master.settings.microphoneId = audio[0].id;
}
if (!$scope.master.settings.cameraId && video.length > 0) {
$scope.master.settings.cameraId = $scope.mediaSources.video[0].id;
}
//console.log("master sources updates", $scope.master);
$scope.refreshWebrtcSettings();
};
$scope.mediaSources.refresh(function() {
safeApply($scope, $scope.checkDefaultMediaSources);
});
$scope.$watch("layout.settings", function(showSettings, oldValue) {
if (showSettings) {
$scope.desktopNotify.refresh();
@ -151,6 +138,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t @@ -151,6 +138,7 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
$scope.user.settings.cameraId = video[0].id;
}
});
$scope.refreshWebrtcSettings();
});
} else if (!showSettings && oldValue) {
$scope.saveSettings();
@ -174,6 +162,31 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t @@ -174,6 +162,31 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
var settings = $scope.master.settings;
// Assert that selected devices are there.
(function() {
var deferred = constraints.defer();
mediaSources.refresh(function() {
$scope.checkDefaultMediaSources();
// Select microphone device by id.
if (settings.microphoneId) {
constraints.add("audio", "sourceId", settings.microphoneId);
}
// Select camera by device id.
if (settings.cameraId) {
constraints.add("video", "sourceId", settings.cameraId);
}
if (!mediaSources.hasAudio()) {
constraints.disable('audio');
console.info("Disabled audio input as no audio source was found.");
}
if (!mediaSources.hasVideo()) {
constraints.disable('video');
console.info("Disabled video input as no video source was found.");
}
deferred.resolve("complete");
});
})();
// Chrome only constraints.
if ($scope.isChrome) {
@ -205,16 +218,6 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t @@ -205,16 +218,6 @@ define(['jquery', 'underscore', 'text!partials/settings.html'], function($, _, t
constraints.add("audio", "chromeRenderToAssociatedSink", settings.audioRenderToAssociatedSkin && true); // defaults to false in Chrome
}
// Select microphone device by id.
if (settings.microphoneId) {
constraints.add("audio", "sourceId", settings.microphoneId);
}
// Select camera by device id.
if (settings.cameraId) {
constraints.add("video", "sourceId", settings.cameraId);
}
// Experimental video settings.
if (settings.experimental.enabled) {

57
static/js/services/constraints.js

@ -23,10 +23,11 @@ @@ -23,10 +23,11 @@
define(["jquery", "underscore"], function($, _) {
// constraints
return ["webrtc", "$window", function(webrtc, $window) {
return ["webrtc", "$window", "$q", function(webrtc, $window, $q) {
var service = this;
// Constraints implementation holder. Created new all the time.
var Constraints = function(settings) {
this.settings = _.clone(settings, true);
this.pc = [];
@ -34,8 +35,24 @@ @@ -34,8 +35,24 @@
this.video = [];
this.videoMandatory = {};
this.screensharing =[];
this.disabled = {};
// Add a single promise for ourselves.
this.promises = [];
this.defer().resolve();
};
// Helpers to wait on stuff.
Constraints.prototype.defer = function() {
var deferred = $q.defer();
this.promises.push(deferred.promise);
return deferred;
};
Constraints.prototype.wait = function(promise) {
this.promises.push(promise);
return promise;
};
// Add constraints.
Constraints.prototype.add = function(t, k, v, mandatory) {
if (_.isArray(t)) {
_.forEach(t, function(x) {
@ -63,6 +80,7 @@ @@ -63,6 +80,7 @@
}
};
// Set constraints, overwriting existing.
Constraints.prototype.set = function(t, data, mandatory) {
if (mandatory) {
t = t + "Mandatory";
@ -74,19 +92,36 @@ @@ -74,19 +92,36 @@
}
};
// Set disable flag for video/audio.
Constraints.prototype.disable = function(name) {
this.disabled[name] = true;
};
// Define our service helpers
service.e = $({}); // events
// Create as WebRTC data structure.
service.mediaConstraints = function(constraints) {
webrtc.settings.mediaConstraints.audio = {
optional: constraints.audio
};
webrtc.settings.mediaConstraints.video = {
optional: constraints.video,
mandatory: constraints.videoMandatory
};
if (constraints.disabled.audio) {
webrtc.settings.mediaConstraints.audio = false
} else {
webrtc.settings.mediaConstraints.audio = {
optional: constraints.audio
};
}
if (constraints.disabled.video) {
webrtc.settings.mediaConstraints.video = false;
} else {
webrtc.settings.mediaConstraints.video = {
optional: constraints.video,
mandatory: constraints.videoMandatory
};
}
console.log("media constraints", webrtc.settings.mediaConstraints);
webrtc.settings.screensharing.mediaConstraints.video.optional = constraints.screensharing;
};
// Create as WebRTC data structure.
service.pcConstraints = function(constraints) {
webrtc.settings.pcConstraints.optional = constraints.pc;
};
@ -119,8 +154,10 @@ @@ -119,8 +154,10 @@
refresh: function(settings) {
var constraints = new Constraints(settings);
service.e.triggerHandler("refresh", [constraints]);
service.mediaConstraints(constraints);
service.pcConstraints(constraints);
return $q.all(constraints.promises).then(function() {
service.mediaConstraints(constraints);
service.pcConstraints(constraints);
});
},
turn: function(turnData) {
// Set TURN server details.

12
static/js/services/mediasources.js

@ -104,6 +104,18 @@ define(['jquery', 'underscore'], function($, _) { @@ -104,6 +104,18 @@ define(['jquery', 'underscore'], function($, _) {
};
MediaSources.prototype.hasVideo = function() {
return !this.supported || this.video.length > 0;
};
MediaSources.prototype.hasAudio = function() {
return !this.supported || this.audio.length > 0;
};
return new MediaSources();

Loading…
Cancel
Save