Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2022-03-31 09:42:16 +0300
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2022-03-31 18:09:57 +0300
commit82236e61f8e3bad4e3251a30030cfd3d454f15ee (patch)
tree72d06f7eeb620ea864c37855bc45297efce0d74b /src
parent41c9186ac6b8b0c81ed0348cdc8ce7aadd8f8c13 (diff)
Fix forced reconnections when replacing tracks
When tracks are replaced the forced reconnections were based on whether the call was started with local media active or not. However, in some cases a forced reconnection was needed even if the call was started with local media active. For example, if after joining a call the user removed the audio and video devices and then added them again, as if another participant joined the call in the meantime that participant would not try to establish a connection after the devices were selected again, as currently the clients only establish a connection if another participant has media when the list of participants in the call change. Besides that, when the flags are updated now the flags are based only in the current tracks rather than on the previous flags, as if the flags were updated again before the previous request finished the second update would be based on the original flags. Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/utils/webrtc/webrtc.js64
1 files changed, 29 insertions, 35 deletions
diff --git a/src/utils/webrtc/webrtc.js b/src/utils/webrtc/webrtc.js
index 8f499abd0..4da540f1e 100644
--- a/src/utils/webrtc/webrtc.js
+++ b/src/utils/webrtc/webrtc.js
@@ -1422,49 +1422,43 @@ export default function initWebRtc(signaling, _callParticipantCollection, _local
signaling.updateCurrentCallFlags(expectedCallFlags)
})
- webrtc.on('localTrackReplaced', function(newTrack, oldTrack/*, stream */) {
- // Device disabled, just update the call flags.
- if (!newTrack) {
- if (oldTrack && oldTrack.kind === 'audio') {
- signaling.updateCurrentCallFlags(signaling.getCurrentCallFlags() & ~PARTICIPANT.CALL_FLAG.WITH_AUDIO)
- } else if (oldTrack && oldTrack.kind === 'video') {
- signaling.updateCurrentCallFlags(signaling.getCurrentCallFlags() & ~PARTICIPANT.CALL_FLAG.WITH_VIDEO)
- }
-
- return
+ /**
+ * Return whether there are sender peers, either already created or about to
+ * be created (if there is a pending connection).
+ *
+ * If the MCU is used then there will be a single sender peer (the own
+ * peer). Otherwise every peer is both a sender and a receiver peer.
+ *
+ * @return {boolean} true if there are sender peers, false otherwise.
+ */
+ function hasSenderPeers() {
+ if (signaling.hasFeature('mcu')) {
+ return !!ownPeer
}
- // If the call was started with media the connections will be already
- // established. The flags need to be updated if a device was enabled
- // (but not if it was switched to another one).
- if (startedWithMedia) {
- if (newTrack.kind === 'audio' && !oldTrack) {
- signaling.updateCurrentCallFlags(signaling.getCurrentCallFlags() | PARTICIPANT.CALL_FLAG.WITH_AUDIO)
- } else if (newTrack.kind === 'video' && !oldTrack) {
- signaling.updateCurrentCallFlags(signaling.getCurrentCallFlags() | PARTICIPANT.CALL_FLAG.WITH_VIDEO)
- }
+ return webrtc.webrtc.getPeers(null, 'video').length > 0 || Object.keys(delayedConnectionToPeer).length > 0
+ }
- return
- }
+ webrtc.on('localTrackReplaced', function(newTrack, oldTrack/*, stream */) {
+ const callFlags = getCallFlagsFromLocalMedia()
+
+ // A reconnection is not needed if a device is disabled or if there are
+ // no other participants in the call. Even if there are other
+ // participants a reconnection is not needed if there are already sender
+ // peers (as "negotiationneeded" will be automatically triggered by them
+ // if needed, which will cause the reconnection). Only if there are no
+ // sender peers or there are, but the previous call flags were just "in
+ // call", a reconnection is needed to ensure that the other participants
+ // will try to connect with the local one.
+ if (newTrack && previousUsersInRoom.length > 0 && (!hasSenderPeers() || signaling.getCurrentCallFlags() === PARTICIPANT.CALL_FLAG.IN_CALL)) {
+ forceReconnect(signaling, callFlags)
- // If the call has not started with media yet the connections will be
- // established once started, as well as the flags.
- if (startedWithMedia === undefined) {
return
}
- // If the call was originally started without media the participant
- // needs to reconnect to establish the sender connections.
- startedWithMedia = true
-
- let flags = signaling.getCurrentCallFlags()
- if (newTrack.kind === 'audio') {
- flags |= PARTICIPANT.CALL_FLAG.WITH_AUDIO
- } else if (newTrack.kind === 'video') {
- flags |= PARTICIPANT.CALL_FLAG.WITH_VIDEO
+ if (signaling.getCurrentCallFlags() !== callFlags) {
+ signaling.updateCurrentCallFlags(callFlags)
}
-
- forceReconnect(signaling, flags)
})
webrtc.on('localMediaStarted', function(/* configuration */) {