Turns off the camera when video is muted on https connection.

This commit is contained in:
hristoterezov 2015-03-23 18:12:24 +02:00
parent 2568b07075
commit 3a0ee11ccd
8 changed files with 574 additions and 524 deletions

View File

@ -19,7 +19,7 @@
<script src="libs/popover.js?v=1"></script><!-- bootstrap tooltip lib -->
<script src="libs/toastr.js?v=1"></script><!-- notifications lib -->
<script src="interface_config.js?v=5"></script>
<script src="libs/app.bundle.js?v=43"></script>
<script src="libs/app.bundle.js?v=44"></script>
<script src="analytics.js?v=1"></script><!-- google analytics plugin -->
<link rel="stylesheet" href="css/font.css?v=6"/>
<link rel="stylesheet" href="css/toastr.css?v=1">

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
var StreamEventTypes = require("../../service/RTC/StreamEventTypes.js");
function LocalStream(stream, type, eventEmitter, videoType)
{
this.stream = stream;
@ -53,11 +54,30 @@ LocalStream.prototype.mute = function()
LocalStream.prototype.setMute = function(mute)
{
if(window.location.protocol != "https:" ||
this.isAudioStream() || this.videoType === "screen")
{
var tracks = this.getTracks();
for (var idx = 0; idx < tracks.length; idx++) {
tracks[idx].enabled = mute;
}
}
else
{
if(mute === false) {
APP.xmpp.removeStream(this.stream);
this.stream.stop();
}
else
{
APP.RTC.rtcUtils.obtainAudioAndVideoPermissions(["video"],
function (stream) {
APP.RTC.changeLocalVideo(stream, false, function () {});
});
}
}
};
LocalStream.prototype.isMuted = function () {
@ -68,6 +88,8 @@ LocalStream.prototype.isMuted = function () {
}
else
{
if(this.stream.ended)
return true;
tracks = this.stream.getVideoTracks();
}
for (var idx = 0; idx < tracks.length; idx++) {
@ -81,6 +103,4 @@ LocalStream.prototype.getId = function () {
return this.stream.getTracks()[0].id;
}
module.exports = LocalStream;

View File

@ -166,10 +166,18 @@ var RTC = {
changeLocalVideo: function (stream, isUsingScreenStream, callback) {
var oldStream = this.localVideo.getOriginalStream();
var type = (isUsingScreenStream? "screen" : "video");
var localCallback = callback;
if(this.localVideo.isMuted() && this.localVideo.videoType !== type)
{
localCallback = function() {
APP.xmpp.setVideoMute(false, APP.UI.setVideoMuteButtonsState);
callback();
};
}
this.localVideo = this.createLocalStream(stream, "video", true, type);
// Stop the stream to trigger onended event for old stream
oldStream.stop();
APP.xmpp.switchStreams(stream, oldStream,callback);
APP.xmpp.switchStreams(stream, oldStream,localCallback);
},
/**
* Checks if video identified by given src is desktop stream.
@ -196,6 +204,25 @@ var RTC = {
isDesktop = (stream.videoType === "screen");
return isDesktop;
},
setVideoMute: function(mute, callback, options) {
if(!this.localVideo)
return;
if (mute == APP.RTC.localVideo.isMuted())
{
APP.xmpp.sendVideoInfoPresence(mute);
if(callback)
callback();
}
else
{
APP.RTC.localVideo.setMute(!mute);
APP.xmpp.setVideoMute(
mute,
callback,
options);
}
}
};

View File

@ -272,13 +272,19 @@ RTCUtils.prototype.getUserMediaWithConstraints = function(
* We ask for audio and video combined stream in order to get permissions and
* not to ask twice.
*/
RTCUtils.prototype.obtainAudioAndVideoPermissions = function() {
RTCUtils.prototype.obtainAudioAndVideoPermissions = function(devices, callback) {
var self = this;
// Get AV
if(!devices)
devices = ['audio', 'video'];
this.getUserMediaWithConstraints(
['audio', 'video'],
devices,
function (stream) {
if(callback)
callback(stream);
else
self.successCallback(stream);
},
function (error) {
@ -357,6 +363,4 @@ RTCUtils.prototype.handleLocalStream = function(stream)
};
module.exports = RTCUtils;

View File

@ -230,21 +230,8 @@ function registerListeners() {
* contrast to an automatic decision taken by the application logic)
*/
function setVideoMute(mute, options) {
APP.xmpp.setVideoMute(
mute,
function (mute) {
var video = $('#video');
var communicativeClass = "icon-camera";
var muteClass = "icon-camera icon-camera-disabled";
if (mute) {
video.removeClass(communicativeClass);
video.addClass(muteClass);
} else {
video.removeClass(muteClass);
video.addClass(communicativeClass);
}
},
APP.RTC.setVideoMute(mute,
UI.setVideoMuteButtonsState,
options);
}
@ -743,5 +730,19 @@ UI.dockToolbar = function (isDock) {
return ToolbarToggler.dockToolbar(isDock);
}
UI.setVideoMuteButtonsState = function (mute) {
var video = $('#video');
var communicativeClass = "icon-camera";
var muteClass = "icon-camera icon-camera-disabled";
if (mute) {
video.removeClass(communicativeClass);
video.addClass(muteClass);
} else {
video.removeClass(muteClass);
video.addClass(communicativeClass);
}
}
module.exports = UI;

View File

@ -1056,26 +1056,6 @@ JingleSession.prototype.notifyMySSRCUpdate = function (old_sdp, new_sdp) {
}
};
/**
* Determines whether the (local) video is mute i.e. all video tracks are
* disabled.
*
* @return <tt>true</tt> if the (local) video is mute i.e. all video tracks are
* disabled; otherwise, <tt>false</tt>
*/
JingleSession.prototype.isVideoMute = function () {
var tracks = APP.RTC.localVideo.getVideoTracks();
var mute = true;
for (var i = 0; i < tracks.length; ++i) {
if (tracks[i].enabled) {
mute = false;
break;
}
}
return mute;
};
/**
* Mutes/unmutes the (local) video i.e. enables/disables all video tracks.
*
@ -1114,12 +1094,6 @@ JingleSession.prototype.setVideoMute = function (mute, callback, options) {
this.modifySources(callback(mute));
};
// SDP-based mute by going recvonly/sendrecv
// FIXME: should probably black out the screen as well
JingleSession.prototype.toggleVideoMute = function (callback) {
this.service.setVideoMute(APP.RTC.localVideo.isMuted(), callback);
};
JingleSession.prototype.hardMuteVideo = function (muted) {
this.pendingop = muted ? 'mute' : 'unmute';
};

View File

@ -202,10 +202,12 @@ var XMPP = {
// FIXME: probably removing streams is not required and close() should
// be enough
if (APP.RTC.localAudio) {
handler.peerconnection.removeStream(APP.RTC.localAudio.getOriginalStream(), onUnload);
handler.peerconnection.removeStream(
APP.RTC.localAudio.getOriginalStream(), onUnload);
}
if (APP.RTC.localVideo) {
handler.peerconnection.removeStream(APP.RTC.localVideo.getOriginalStream(), onUnload);
handler.peerconnection.removeStream(
APP.RTC.localVideo.getOriginalStream(), onUnload);
}
handler.peerconnection.close();
}
@ -251,28 +253,19 @@ var XMPP = {
callback();
}
},
setVideoMute: function (mute, callback, options) {
if(!connection || !APP.RTC.localVideo)
return;
var localCallback = function (mute) {
sendVideoInfoPresence: function (mute) {
connection.emuc.addVideoInfoToPresence(mute);
connection.emuc.sendPresence();
},
setVideoMute: function (mute, callback, options) {
if(!connection)
return;
var self = this;
var localCallback = function (mute) {
self.sendVideoInfoPresence(mute);
return callback(mute);
};
if (mute == APP.RTC.localVideo.isMuted())
{
// Even if no change occurs, the specified callback is to be executed.
// The specified callback may, optionally, return a successCallback
// which is to be executed as well.
var successCallback = localCallback(mute);
if (successCallback) {
successCallback();
}
} else {
APP.RTC.localVideo.setMute(!mute);
if(connection.jingle.activecall)
{
connection.jingle.activecall.setVideoMute(
@ -282,7 +275,6 @@ var XMPP = {
localCallback(mute);
}
}
},
setAudioMute: function (mute, callback) {
if (!(connection && APP.RTC.localAudio)) {
@ -472,8 +464,13 @@ var XMPP = {
},
getSessions: function () {
return connection.jingle.sessions;
},
removeStream: function (stream) {
if(!connection || !connection.jingle.activecall ||
!connection.jingle.activecall.peerconnection)
return;
connection.jingle.activecall.peerconnection.removeStream(stream);
}
};
module.exports = XMPP;