Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/components/CallView/shared/LocalVideo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ export default {
screenshotModeUrl() {
return this.screenshotMode ? placeholderImage(8) : ''
},

localStreamAttachIdentifier() {
return [this.localMediaModel.attributes.localStream, this.localMediaModel.attributes.videoAvailable]
},
},

watch: {
Expand All @@ -269,7 +273,14 @@ export default {
},
},

'localMediaModel.attributes.localStream': function(localStream) {
localStreamAttachIdentifier([localStream, videoAvailable], [oldLocalStream, oldVideoAvailable]) {
// Reattach the stream if it was replaced, or if the video is
// available again after the local track was replaced, to
// prevent rendering the last frame drawn before the change.
if (localStream === oldLocalStream && !(videoAvailable && !oldVideoAvailable)) {
return
}

this._setLocalStream(localStream)
},

Expand Down
13 changes: 12 additions & 1 deletion src/components/CallView/shared/VideoVue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,21 @@ export default {
screenshotModeUrl() {
return this.screenshotMode ? placeholderImage(6) : ''
},

streamAttachTrigger() {
return [this.model.attributes.stream, this.hasVideo]
},
},

watch: {
'model.attributes.stream': function(stream) {
streamAttachTrigger([stream, hasVideo], [oldStream, oldHasVideo]) {
// Reattach the stream if it was replaced, or if the video is
// available again after the remote track was replaced, to
// prevent rendering the last frame received before the change.
if (stream === oldStream && !(hasVideo && !oldHasVideo)) {
return
}

this._setStream(stream)
},

Expand Down
30 changes: 29 additions & 1 deletion src/utils/webrtc/webrtc.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ export function initWebRtc(signaling, _callParticipantCollection, _localCallPart
// is received before the "leave call" request ends.
localUserInCall = false

clearTimeout(updateCallFlagsFromLocalMediaTimeout)

localStateBroadcaster.destroy()
localStateBroadcaster = null
})
Expand Down Expand Up @@ -1422,6 +1424,24 @@ export function initWebRtc(signaling, _callParticipantCollection, _localCallPart
return callFlags
}

let updateCallFlagsFromLocalMediaTimeout = null

/**
* Update the call flags to match the current local tracks.
*/
function updateCallFlagsFromLocalMedia() {
// As update can be deferred, check whether the call may have been left in the meantime
if (!localUserInCall) {
return
}

const callFlags = getCallFlagsFromLocalMedia()

if (signaling.getCurrentCallFlags() !== callFlags) {
signaling.updateCurrentCallFlags(callFlags)
}
}

signaling.on('joinCall', function(token) {
const expectedCallFlags = getCallFlagsFromLocalMedia()

Expand Down Expand Up @@ -1463,6 +1483,8 @@ export function initWebRtc(signaling, _callParticipantCollection, _localCallPart
}

webrtc.on('localTrackReplaced', function(newTrack, oldTrack/* , stream */) {
clearTimeout(updateCallFlagsFromLocalMediaTimeout)

const callFlags = getCallFlagsFromLocalMedia()

// A reconnection is not needed if a device is disabled or if there are
Expand All @@ -1479,7 +1501,13 @@ export function initWebRtc(signaling, _callParticipantCollection, _localCallPart
return
}

if (signaling.getCurrentCallFlags() !== callFlags) {
const removedCallFlags = signaling.getCurrentCallFlags() & ~callFlags
if (removedCallFlags) {
// If a media is no longer sent because of "MediaDevicesManager._stopIncompatibleTracks()"
// (flags change 7->5->7 or 7->3->7 on input device replacement), defer the update
// and give some time for the new track to be set, then check local flags again.
updateCallFlagsFromLocalMediaTimeout = setTimeout(updateCallFlagsFromLocalMedia, 1_000)
} else if (signaling.getCurrentCallFlags() !== callFlags) {
signaling.updateCurrentCallFlags(callFlags)
}
})
Expand Down
Loading