Skip to content
Merged
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
2 changes: 2 additions & 0 deletions src/components/CallView/CallView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ export default {
const removedModelIds = Object.keys(this.sharedDatas).filter(sharedDataId => models.find(model => model.attributes.peerId === sharedDataId) === undefined)

removedModelIds.forEach(removedModelId => {
this.sharedDatas[removedModelId].remoteVideoBlocker.destroy()

this.$delete(this.sharedDatas, removedModelId)

this.speakingUnwatchers[removedModelId]()
Expand Down
23 changes: 23 additions & 0 deletions src/utils/webrtc/RemoteVideoBlocker.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
* have video permissions). In that case the CallParticipantModel will block the
* video if needed if it becomes available.
*
* Once the CallParticipantModel is no longer used the associated
* RemoteVideoBlocker must be destroyed to ensure that the video will not be
* blocked or unblocked; calling any (modifier) method on the RemoteVideoBlocker
* once destroyed has no effect.
*
* @param {object} callParticipantModel the model to block/unblock the video on.
*/
export default function RemoteVideoBlocker(callParticipantModel) {
Expand All @@ -64,11 +69,21 @@ export default function RemoteVideoBlocker(callParticipantModel) {

RemoteVideoBlocker.prototype = {

destroy() {
this._destroyed = true

clearTimeout(this._blockVideoTimeout)
},

isVideoEnabled() {
return this._enabled
},

setVideoEnabled(enabled) {
if (this._destroyed) {
return
}

this._enabled = enabled

const hadBlockVideoTimeout = this._blockVideoTimeout
Expand All @@ -84,6 +99,10 @@ RemoteVideoBlocker.prototype = {
},

increaseVisibleCounter() {
if (this._destroyed) {
return
}

this._visibleCounter++

clearTimeout(this._blockVideoTimeout)
Expand All @@ -97,6 +116,10 @@ RemoteVideoBlocker.prototype = {
},

decreaseVisibleCounter() {
if (this._destroyed) {
return
}

if (this._visibleCounter <= 0) {
console.error('Visible counter decreased when not visible')

Expand Down
55 changes: 55 additions & 0 deletions src/utils/webrtc/RemoteVideoBlocker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,4 +333,59 @@ describe('RemoteVideoBlocker', () => {
expect(remoteVideoBlocker.isVideoEnabled()).toBe(true)
})
})

describe('destroy', () => {
test('prevents the video from being blocked by default if not shown in some seconds', () => {
jest.advanceTimersByTime(4000)

expect(callParticipantModel.setVideoBlocked).toHaveBeenCalledTimes(0)

remoteVideoBlocker.destroy()

jest.advanceTimersByTime(1000)

expect(callParticipantModel.setVideoBlocked).toHaveBeenCalledTimes(0)
})

test('prevents the video from being blocked or unblocked if enabled or disabled', () => {
remoteVideoBlocker.increaseVisibleCounter()

remoteVideoBlocker.destroy()

remoteVideoBlocker.setVideoEnabled(false)
remoteVideoBlocker.setVideoEnabled(true)

expect(callParticipantModel.setVideoBlocked).toHaveBeenCalledTimes(0)
})

test('prevents the video from being blocked after some seconds if hidden before destroying', () => {
remoteVideoBlocker.increaseVisibleCounter()
remoteVideoBlocker.decreaseVisibleCounter()

jest.advanceTimersByTime(4000)

expect(callParticipantModel.setVideoBlocked).toHaveBeenCalledTimes(0)

remoteVideoBlocker.destroy()

jest.advanceTimersByTime(1000)

expect(callParticipantModel.setVideoBlocked).toHaveBeenCalledTimes(0)
})

test('prevents the video from being blocked after some seconds if hidden after destroying', () => {
remoteVideoBlocker.destroy()

remoteVideoBlocker.increaseVisibleCounter()
remoteVideoBlocker.decreaseVisibleCounter()

jest.advanceTimersByTime(4000)

expect(callParticipantModel.setVideoBlocked).toHaveBeenCalledTimes(0)

jest.advanceTimersByTime(1000)

expect(callParticipantModel.setVideoBlocked).toHaveBeenCalledTimes(0)
})
})
})