Skip to content

Commit

Permalink
Merge pull request #1830 from nextcloud/backport/1818/stable16
Browse files Browse the repository at this point in the history
[stable16] Disable video by default when joining calls
  • Loading branch information
nickvergessen authored May 16, 2019
2 parents 35a2b6a + a66c6a9 commit fbc39a6
Show file tree
Hide file tree
Showing 9 changed files with 131 additions and 30 deletions.
22 changes: 18 additions & 4 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -627,13 +627,17 @@

delete this._reconnectCallToken;

// Disable video when joining a call in a room with more than 5
// participants.
var participants = this.activeRoom.get('participants');
if (participants && Object.keys(participants).length > 5) {
if (this.activeRoom.get('type') === this.ROOM_TYPE_ONE_TO_ONE) {
this._mediaControlsView.setAudioEnabled(true);
this.setVideoEnabled(false);

return;
}

this._mediaControlsView.setAudioEnabled(false);
this.setVideoEnabled(false);

var participants = this.activeRoom.get('participants');
var numberOfParticipantsAndGuests = (participants? Object.keys(participants).length: 0) +
this.activeRoom.get('numGuests');
if (this.signaling.isNoMcuWarningEnabled() && numberOfParticipantsAndGuests >= 5) {
Expand Down Expand Up @@ -706,6 +710,16 @@
localMediaChannel.trigger('waitingForPermissions');
}

var participants = this.activeRoom.get('participants');
var numberOfParticipantsAndGuests = (participants? Object.keys(participants).length: 0) +
this.activeRoom.get('numGuests');
if (numberOfParticipantsAndGuests >= 5) {
this.signaling.setSendVideoIfAvailable(false);
this.setVideoEnabled(false);
} else {
this.signaling.setSendVideoIfAvailable(true);
}

OCA.SpreedMe.webrtc.startMedia(this.token);
},
startLocalMedia: function(configuration) {
Expand Down
2 changes: 1 addition & 1 deletion js/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@
if (configuration.audio) {
flags |= OCA.SpreedMe.app.FLAG_WITH_AUDIO;
}
if (configuration.video) {
if (configuration.video && self.app.signaling.getSendVideoIfAvailable()) {
flags |= OCA.SpreedMe.app.FLAG_WITH_VIDEO;
}
}
Expand Down
22 changes: 18 additions & 4 deletions js/embedded.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,17 @@

delete this._reconnectCallToken;

// Disable video when joining a call in a room with more than 5
// participants.
var participants = this.activeRoom.get('participants');
if (participants && Object.keys(participants).length > 5) {
if (this.activeRoom.get('type') === this.ROOM_TYPE_ONE_TO_ONE) {
this._mediaControlsView.setAudioEnabled(true);
this.setVideoEnabled(false);

return;
}

this._mediaControlsView.setAudioEnabled(false);
this.setVideoEnabled(false);

var participants = this.activeRoom.get('participants');
var numberOfParticipantsAndGuests = (participants? Object.keys(participants).length: 0) +
this.activeRoom.get('numGuests');
if (this.signaling.isNoMcuWarningEnabled() && numberOfParticipantsAndGuests >= 5) {
Expand Down Expand Up @@ -188,6 +192,16 @@
localMediaChannel.trigger('waitingForPermissions');
}

var participants = this.activeRoom.get('participants');
var numberOfParticipantsAndGuests = (participants? Object.keys(participants).length: 0) +
this.activeRoom.get('numGuests');
if (numberOfParticipantsAndGuests >= 5) {
this.signaling.setSendVideoIfAvailable(false);
this.setVideoEnabled(false);
} else {
this.signaling.setSendVideoIfAvailable(true);
}

OCA.SpreedMe.webrtc.startMedia(this.token);
},
startLocalMedia: function(configuration) {
Expand Down
34 changes: 31 additions & 3 deletions js/signaling.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
this.pendingChatRequests = [];
this._lastChatMessagesFetch = null;
this.chatBatchSize = 100;
this._sendVideoIfAvailable = true;
}

OCA.Talk.Signaling.Base = Base;
Expand Down Expand Up @@ -134,6 +135,10 @@
return this.sessionId;
};

OCA.Talk.Signaling.Base.prototype.getCurrentCallFlags = function() {
return this.currentCallFlags;
};

OCA.Talk.Signaling.Base.prototype.disconnect = function() {
this.sessionId = '';
this.currentCallToken = null;
Expand Down Expand Up @@ -299,6 +304,14 @@
});
};

OCA.Talk.Signaling.Base.prototype.getSendVideoIfAvailable = function() {
return this._sendVideoIfAvailable;
};

OCA.Talk.Signaling.Base.prototype.setSendVideoIfAvailable = function(sendVideoIfAvailable) {
this._sendVideoIfAvailable = sendVideoIfAvailable;
};

OCA.Talk.Signaling.Base.prototype._joinCallSuccess = function(/* token */) {
// Override in subclasses if necessary.
};
Expand Down Expand Up @@ -515,8 +528,19 @@
}
};

OCA.Talk.Signaling.Internal.prototype.forceReconnect = function(/* newSession */) {
console.error("Forced reconnects are not supported with the internal signaling.");
OCA.Talk.Signaling.Internal.prototype.forceReconnect = function(newSession, flags) {
if (newSession) {
console.log('Forced reconnects with a new session are not supported in the internal signaling; same session as before will be used');
}

if (flags !== undefined) {
this.currentCallFlags = flags;
}

// FIXME Naive reconnection routine; as the same session is kept peers
// must be explicitly ended before the reconnection is forced.
this.leaveCall(this.currentCallToken, true);
this.joinCall(this.currentCallToken);
};

OCA.Talk.Signaling.Internal.prototype._sendMessageWithCallback = function(ev) {
Expand Down Expand Up @@ -830,7 +854,11 @@
OCA.Talk.Signaling.Base.prototype.disconnect.apply(this, arguments);
};

OCA.Talk.Signaling.Standalone.prototype.forceReconnect = function(newSession) {
OCA.Talk.Signaling.Standalone.prototype.forceReconnect = function(newSession, flags) {
if (flags !== undefined) {
this.currentCallFlags = flags;
}

if (!this.connected) {
if (!newSession) {
// Not connected, will do reconnect anyway.
Expand Down
10 changes: 8 additions & 2 deletions js/simplewebrtc/bundled.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ function Peer(options) {
this.sharemyscreen = options.sharemyscreen || false;
this.browserPrefix = options.prefix;
this.stream = options.stream;
this.sendVideoIfAvailable = options.sendVideoIfAvailable === undefined ? true : options.sendVideoIfAvailable;
this.enableDataChannels = options.enableDataChannels === undefined ? this.parent.config.enableDataChannels : options.enableDataChannels;
this.receiveMedia = options.receiveMedia || this.parent.config.receiveMedia;
this.channels = {};
Expand Down Expand Up @@ -673,7 +674,11 @@ function Peer(options) {
}
} else {
this.parent.localStreams.forEach(function (stream) {
self.pc.addStream(stream);
stream.getTracks().forEach(function (track) {
if (track.kind !== 'video' || self.sendVideoIfAvailable) {
self.pc.addTrack(track, stream);
}
});
});
} // proxy events to parent

Expand Down Expand Up @@ -1079,7 +1084,8 @@ function SimpleWebRTC(opts) {
type: message.roomType,
enableDataChannels: self.config.enableDataChannels && message.roomType !== 'screen',
sharemyscreen: message.roomType === 'screen' && !message.broadcaster,
broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionid() : null
broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionid() : null,
sendVideoIfAvailable: self.connection.getSendVideoIfAvailable()
});
self.emit('createdPeer', peer);
}
Expand Down
7 changes: 6 additions & 1 deletion js/simplewebrtc/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function Peer(options) {
this.sharemyscreen = options.sharemyscreen || false;
this.browserPrefix = options.prefix;
this.stream = options.stream;
this.sendVideoIfAvailable = options.sendVideoIfAvailable === undefined ? true : options.sendVideoIfAvailable;
this.enableDataChannels = options.enableDataChannels === undefined ? this.parent.config.enableDataChannels : options.enableDataChannels;
this.receiveMedia = options.receiveMedia || this.parent.config.receiveMedia;
this.channels = {};
Expand Down Expand Up @@ -68,7 +69,11 @@ function Peer(options) {
}
} else {
this.parent.localStreams.forEach(function (stream) {
self.pc.addStream(stream);
stream.getTracks().forEach(function (track) {
if (track.kind !== 'video' || self.sendVideoIfAvailable) {
self.pc.addTrack(track, stream);
}
});
});
}

Expand Down
3 changes: 2 additions & 1 deletion js/simplewebrtc/simplewebrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ function SimpleWebRTC(opts) {
type: message.roomType,
enableDataChannels: self.config.enableDataChannels && message.roomType !== 'screen',
sharemyscreen: message.roomType === 'screen' && !message.broadcaster,
broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionid() : null
broadcaster: message.roomType === 'screen' && !message.broadcaster ? self.connection.getSessionid() : null,
sendVideoIfAvailable: self.connection.getSendVideoIfAvailable()
});
self.emit('createdPeer', peer);
}
Expand Down
10 changes: 9 additions & 1 deletion js/views/mediacontrolsview.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
} else {
this._webrtc.pauseVideo();

this.getUI('videoButton').attr('data-original-title', t('spreed', 'Enable video (v)'))
this.getUI('videoButton').attr('data-original-title', this._getEnableVideoButtonTitle())
.addClass('local-video-disabled video-disabled icon-video-off')
.removeClass('icon-video');
this.getUI('audioButton').addClass('local-video-disabled');
Expand All @@ -195,6 +195,14 @@
return true;
},

_getEnableVideoButtonTitle: function() {
if (!this._app.signaling || this._app.signaling.getSendVideoIfAvailable()) {
return t('spreed', 'Enable video (v)');
}

return t('spreed', 'Enable video (v) - Your connection will be briefly interrupted when enabling the video for the first time');
},

/**
* Sets the video as available or not available.
*
Expand Down
51 changes: 38 additions & 13 deletions js/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ var spreedPeerConnectionTable = [];
receiveMedia: {
offerToReceiveAudio: 0,
offerToReceiveVideo: 0
}
},
sendVideoIfAvailable: signaling.getSendVideoIfAvailable()
});
webrtc.emit('createdPeer', ownPeer);
ownPeer.start();
Expand Down Expand Up @@ -184,7 +185,8 @@ var spreedPeerConnectionTable = [];
receiveMedia: {
offerToReceiveAudio: 1,
offerToReceiveVideo: 1
}
},
sendVideoIfAvailable: signaling.getSendVideoIfAvailable()
});
webrtc.emit('createdPeer', peer);
peer.start();
Expand Down Expand Up @@ -934,16 +936,7 @@ var spreedPeerConnectionTable = [];
app.disableScreensharingButton();
});

OCA.SpreedMe.webrtc.webrtc.on('iceFailed', function (/* peer */) {
var signaling = OCA.SpreedMe.app.signaling;
if (!signaling.hasFeature("mcu")) {
// ICE restarts will be handled by "iceConnectionStateChange"
// above.
return;
}

// For now assume the connection to the MCU is interrupted on ICE
// failures and force a reconnection of all streams.
var forceReconnect = function(signaling, flags) {
if (ownPeer) {
OCA.SpreedMe.webrtc.removePeers(ownPeer.id);
OCA.SpreedMe.speakers.remove(ownPeer.id, true);
Expand All @@ -952,13 +945,45 @@ var spreedPeerConnectionTable = [];
ownPeer.end();
ownPeer = null;
}

usersChanged(signaling, [], previousUsersInRoom);
usersInCallMapping = {};
previousUsersInRoom = [];

// Reconnects with a new session id will trigger "usersChanged"
// with the users in the room and that will re-establish the
// peerconnection streams.
signaling.forceReconnect(true);
// If flags are undefined the current call flags are used.
signaling.forceReconnect(true, flags);
};

OCA.SpreedMe.webrtc.webrtc.on('videoOn', function () {
var signaling = OCA.SpreedMe.app.signaling;
if (signaling.getSendVideoIfAvailable()) {
return;
}

// When enabling the local video if the video is not being sent a
// reconnection is forced to start sending it.
signaling.setSendVideoIfAvailable(true);

var flags = signaling.getCurrentCallFlags();
flags |= OCA.SpreedMe.app.FLAG_WITH_VIDEO;

forceReconnect(signaling, flags);
});

OCA.SpreedMe.webrtc.webrtc.on('iceFailed', function (/* peer */) {
var signaling = OCA.SpreedMe.app.signaling;
if (!signaling.hasFeature("mcu")) {
// ICE restarts will be handled by "iceConnectionStateChange"
// above.
return;
}

// For now assume the connection to the MCU is interrupted on ICE
// failures and force a reconnection of all streams.
forceReconnect(signaling);
});

OCA.SpreedMe.webrtc.on('localMediaStarted', function (configuration) {
Expand Down

0 comments on commit fbc39a6

Please sign in to comment.