Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: define explicit reactivity for webrtc models #11993

Merged
merged 2 commits into from
Apr 4, 2024
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
8 changes: 4 additions & 4 deletions src/components/CallView/CallView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,15 @@ export default {
setup() {
return {
supportedReactions,
localMediaModel,
localCallParticipantModel,
callParticipantCollection,
}
},

data() {
return {
screens: [],
localMediaModel,
localCallParticipantModel,
sharedDatas: {},
raisedHandUnwatchers: {},
speakingUnwatchers: {},
Expand All @@ -209,7 +210,6 @@ export default {
localSharedData: {
screenVisible: true,
},
callParticipantCollection,
isBackgroundBlurred: true,
showPresenterOverlay: true,
debounceFetchPeers: () => {},
Expand All @@ -222,7 +222,7 @@ export default {
},

callParticipantModels() {
return callParticipantCollection.callParticipantModels.filter(callParticipantModel => !callParticipantModel.attributes.internal)
return callParticipantCollection.callParticipantModels.value.filter(callParticipantModel => !callParticipantModel.attributes.internal)
},

callParticipantModelsWithScreen() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/MediaSettings/MediaSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,12 @@ export default {
initializeDevices,
stopDevices,
virtualBackground,
model: localMediaModel,
}
},

data() {
return {
model: localMediaModel,
modal: false,
tabContent: 'none',
audioOn: undefined,
Expand Down
6 changes: 4 additions & 2 deletions src/components/TopBar/TopBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,16 @@ export default {

setup() {
useGetParticipants()
return {
localCallParticipantModel,
localMediaModel,
}
},

data: () => {
return {
unreadNotificationHandle: null,
showBreakoutRoomsEditor: false,
localCallParticipantModel,
localMediaModel,
}
},

Expand Down
2 changes: 1 addition & 1 deletion src/components/TopBar/TopBarMediaControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export default {
setup() {
return {
isInCall: useIsInCall(),
callAnalyzer,
}
},

Expand All @@ -202,7 +203,6 @@ export default {
screenSharingMenuOpen: false,
boundaryElement: document.querySelector('.main-view'),
mouseover: false,
callAnalyzer,
qualityWarningInGracePeriodTimeout: null,
audioEnabledBeforeSpacebarKeydown: undefined,
spacebarKeyDown: false,
Expand Down
2 changes: 1 addition & 1 deletion src/components/TopBar/TopBarMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export default {

methods: {
forceMuteOthers() {
callParticipantCollection.callParticipantModels.forEach(callParticipantModel => {
callParticipantCollection.callParticipantModels.value.forEach(callParticipantModel => {
callParticipantModel.forceMute()
})
},
Expand Down
6 changes: 3 additions & 3 deletions src/utils/webrtc/SentVideoQualityThrottler.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ SentVideoQualityThrottler.prototype = {
this._callParticipantCollection.on('add', this._handleAddParticipantBound)
this._callParticipantCollection.on('remove', this._handleRemoveParticipantBound)

this._callParticipantCollection.callParticipantModels.forEach(callParticipantModel => {
this._callParticipantCollection.callParticipantModels.value.forEach(callParticipantModel => {
callParticipantModel.on('change:videoAvailable', this._adjustVideoQualityIfNeededBound)
callParticipantModel.on('change:audioAvailable', this._adjustVideoQualityIfNeededBound)
})
Expand All @@ -119,7 +119,7 @@ SentVideoQualityThrottler.prototype = {
this._callParticipantCollection.off('add', this._handleAddParticipantBound)
this._callParticipantCollection.off('remove', this._handleRemoveParticipantBound)

this._callParticipantCollection.callParticipantModels.forEach(callParticipantModel => {
this._callParticipantCollection.callParticipantModels.value.forEach(callParticipantModel => {
callParticipantModel.off('change:videoAvailable', this._adjustVideoQualityIfNeededBound)
callParticipantModel.off('change:audioAvailable', this._adjustVideoQualityIfNeededBound)
})
Expand Down Expand Up @@ -187,7 +187,7 @@ SentVideoQualityThrottler.prototype = {

let availableVideosCount = 0
let availableAudiosCount = 0
this._callParticipantCollection.callParticipantModels.forEach(callParticipantModel => {
this._callParticipantCollection.callParticipantModels.value.forEach(callParticipantModel => {
if (callParticipantModel.get('videoAvailable')) {
availableVideosCount++
}
Expand Down
2 changes: 1 addition & 1 deletion src/utils/webrtc/SpeakingStatusHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class SpeakingStatusHandler {
this.#callParticipantCollection.off('add', this.#handleAddParticipantBound)
this.#callParticipantCollection.off('remove', this.#handleRemoveParticipantBound)

this.#callParticipantCollection.callParticipantModels.forEach(callParticipantModel => {
this.#callParticipantCollection.callParticipantModels.value.forEach(callParticipantModel => {
callParticipantModel.off('change:speaking', this.#handleSpeakingBound)
callParticipantModel.off('change:stoppedSpeaking', this.#handleSpeakingBound)
})
Expand Down
6 changes: 4 additions & 2 deletions src/utils/webrtc/analyzers/CallAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
*/

import { reactive } from 'vue'

import { ParticipantAnalyzer } from './ParticipantAnalyzer.js'
import EmitterMixin from '../../EmitterMixin.js'

Expand Down Expand Up @@ -51,11 +53,11 @@ import EmitterMixin from '../../EmitterMixin.js'
export default function CallAnalyzer(localMediaModel, localCallParticipantModel, callParticipantCollection) {
this._superEmitterMixin()

this.attributes = {
this.attributes = reactive({
senderConnectionQualityAudio: null,
senderConnectionQualityVideo: null,
senderConnectionQualityScreen: null,
}
})

this._localMediaModel = localMediaModel
this._localCallParticipantModel = localCallParticipantModel
Expand Down
15 changes: 9 additions & 6 deletions src/utils/webrtc/models/CallParticipantCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
*/

import { ref } from 'vue'

import CallParticipantModel from './CallParticipantModel.js'
import EmitterMixin from '../../EmitterMixin.js'

Expand All @@ -29,35 +31,36 @@ export default function CallParticipantCollection() {

this._superEmitterMixin()

this.callParticipantModels = []
// FIXME: use reactive instead of ref after migration to vue 3
this.callParticipantModels = ref([])
Comment on lines +34 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Vue warn]: Avoid using Array as root value for reactive() as it cannot be tracked in watch() or watchEffect(). Use ref() instead. This is a Vue-2-only limitation.

As we don't use it in watch or watchEffect, reactive would also work here.

Though, it will show the error in the console...
So, I don't know what is the best way here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, reactive works fine but those errors were annoying, I would keep ref temporarily.


}

CallParticipantCollection.prototype = {

add(options) {
const callParticipantModel = new CallParticipantModel(options)
this.callParticipantModels.push(callParticipantModel)
this.callParticipantModels.value.push(callParticipantModel)

this._trigger('add', [callParticipantModel])

return callParticipantModel
},

get(peerId) {
return this.callParticipantModels.find(function(callParticipantModel) {
return this.callParticipantModels.value.find(function(callParticipantModel) {
return callParticipantModel.attributes.peerId === peerId
})
},

remove(peerId) {
const index = this.callParticipantModels.findIndex(function(callParticipantModel) {
const index = this.callParticipantModels.value.findIndex(function(callParticipantModel) {
return callParticipantModel.attributes.peerId === peerId
})
if (index !== -1) {
const callParticipantModel = this.callParticipantModels[index]
const callParticipantModel = this.callParticipantModels.value[index]

this.callParticipantModels.splice(index, 1)
this.callParticipantModels.value.splice(index, 1)

this._trigger('remove', [callParticipantModel])

Expand Down
6 changes: 4 additions & 2 deletions src/utils/webrtc/models/LocalCallParticipantModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
*/

import { reactive } from 'vue'

import { ConnectionState } from './CallParticipantModel.js'
import store from '../../../store/index.js'
import EmitterMixin from '../../EmitterMixin.js'
Expand All @@ -30,14 +32,14 @@ export default function LocalCallParticipantModel() {

this._superEmitterMixin()

this.attributes = {
this.attributes = reactive({
peerId: null,
peer: null,
screenPeer: null,
guestName: null,
peerNeeded: false,
connectionState: null,
}
})

this._handleForcedMuteBound = this._handleForcedMute.bind(this)
this._handleExtendedIceConnectionStateChangeBound = this._handleExtendedIceConnectionStateChange.bind(this)
Expand Down
6 changes: 4 additions & 2 deletions src/utils/webrtc/models/LocalMediaModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*
*/

import { reactive } from 'vue'

import { VIRTUAL_BACKGROUND } from '../../../constants.js'
import BrowserStorage from '../../../services/BrowserStorage.js'
import store from '../../../store/index.js'
Expand All @@ -31,7 +33,7 @@ export default function LocalMediaModel() {

this._superEmitterMixin()

this.attributes = {
this.attributes = reactive({
localStreamRequestVideoError: null,
localStream: null,
audioAvailable: false,
Expand All @@ -50,7 +52,7 @@ export default function LocalMediaModel() {
localScreen: null,
token: '',
raisedHand: false,
}
})

this._handleLocalStreamRequestedBound = this._handleLocalStreamRequested.bind(this)
this._handleLocalStreamBound = this._handleLocalStream.bind(this)
Expand Down
Loading