Skip to content

Commit

Permalink
fix(call): Fix incorrectly selected media when actually joining a call
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed May 10, 2023
1 parent 69141db commit c1583c3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
13 changes: 7 additions & 6 deletions src/utils/webrtc/index.js
Expand Up @@ -23,6 +23,7 @@ import Axios from '@nextcloud/axios'
import { getCapabilities } from '@nextcloud/capabilities'

import { PARTICIPANT, PRIVACY, VIRTUAL_BACKGROUND } from '../../constants.js'
import BrowserStorage from '../../services/BrowserStorage.js'
import { fetchSignalingSettings } from '../../services/signalingService.js'
import store from '../../store/index.js'
import CancelableRequest from '../cancelableRequest.js'
Expand Down Expand Up @@ -227,12 +228,12 @@ async function signalingJoinCall(token, flags, silent) {

// The previous state might be wiped after the media is started, so
// it should be saved now.
const enableAudio = !localStorage.getItem('audioDisabled_' + token)
const enableVideo = !localStorage.getItem('videoDisabled_' + token)
const enableVirtualBackground = !!localStorage.getItem('virtualBackgroundEnabled_' + token)
const virtualBackgroundType = localStorage.getItem('virtualBackgroundType_' + token)
const virtualBackgroundBlurStrength = localStorage.getItem('virtualBackgroundBlurStrength_' + token)
const virtualBackgroundUrl = localStorage.getItem('virtualBackgroundUrl_' + token)
const enableAudio = !BrowserStorage.getItem('audioDisabled_' + token)
const enableVideo = !BrowserStorage.getItem('videoDisabled_' + token)
const enableVirtualBackground = !!BrowserStorage.getItem('virtualBackgroundEnabled_' + token)
const virtualBackgroundType = BrowserStorage.getItem('virtualBackgroundType_' + token)
const virtualBackgroundBlurStrength = BrowserStorage.getItem('virtualBackgroundBlurStrength_' + token)
const virtualBackgroundUrl = BrowserStorage.getItem('virtualBackgroundUrl_' + token)

if (enableAudio) {
localMediaModel.enableAudio()
Expand Down
31 changes: 16 additions & 15 deletions src/utils/webrtc/models/LocalMediaModel.js
Expand Up @@ -20,6 +20,7 @@
*/

import { VIRTUAL_BACKGROUND } from '../../../constants.js'
import BrowserStorage from '../../../services/BrowserStorage.js'
import store from '../../../store/index.js'
import EmitterMixin from '../../EmitterMixin.js'

Expand Down Expand Up @@ -353,7 +354,7 @@ LocalMediaModel.prototype = {
throw new Error('WebRtc not initialized yet')
}

localStorage.removeItem('audioDisabled_' + this.get('token'))
BrowserStorage.removeItem('audioDisabled_' + this.get('token'))

this._webRtc.unmute()
},
Expand All @@ -363,7 +364,7 @@ LocalMediaModel.prototype = {
throw new Error('WebRtc not initialized yet')
}

localStorage.setItem('audioDisabled_' + this.get('token'), 'true')
BrowserStorage.setItem('audioDisabled_' + this.get('token'), 'true')

this._webRtc.mute()
},
Expand All @@ -373,7 +374,7 @@ LocalMediaModel.prototype = {
throw new Error('WebRtc not initialized yet')
}

localStorage.removeItem('videoDisabled_' + this.get('token'))
BrowserStorage.removeItem('videoDisabled_' + this.get('token'))

this._webRtc.resumeVideo()
},
Expand All @@ -383,7 +384,7 @@ LocalMediaModel.prototype = {
throw new Error('WebRtc not initialized yet')
}

localStorage.setItem('videoDisabled_' + this.get('token'), 'true')
BrowserStorage.setItem('videoDisabled_' + this.get('token'), 'true')

this._webRtc.pauseVideo()
},
Expand All @@ -393,7 +394,7 @@ LocalMediaModel.prototype = {
throw new Error('WebRtc not initialized yet')
}

localStorage.setItem('virtualBackgroundEnabled_' + this.get('token'), 'true')
BrowserStorage.setItem('virtualBackgroundEnabled_' + this.get('token'), 'true')

this._webRtc.enableVirtualBackground()
},
Expand All @@ -407,9 +408,9 @@ LocalMediaModel.prototype = {
blurStrength = VIRTUAL_BACKGROUND.BLUR_STRENGTH.DEFAULT
}

localStorage.setItem('virtualBackgroundType_' + this.get('token'), VIRTUAL_BACKGROUND.BACKGROUND_TYPE.BLUR)
localStorage.setItem('virtualBackgroundBlurStrength_' + this.get('token'), blurStrength)
localStorage.removeItem('virtualBackgroundUrl_' + this.get('token'))
BrowserStorage.setItem('virtualBackgroundType_' + this.get('token'), VIRTUAL_BACKGROUND.BACKGROUND_TYPE.BLUR)
BrowserStorage.setItem('virtualBackgroundBlurStrength_' + this.get('token'), blurStrength)
BrowserStorage.removeItem('virtualBackgroundUrl_' + this.get('token'))

this._webRtc.setVirtualBackground({
backgroundType: VIRTUAL_BACKGROUND.BACKGROUND_TYPE.BLUR,
Expand All @@ -422,9 +423,9 @@ LocalMediaModel.prototype = {
throw new Error('WebRtc not initialized yet')
}

localStorage.setItem('virtualBackgroundType_' + this.get('token'), VIRTUAL_BACKGROUND.BACKGROUND_TYPE.IMAGE)
localStorage.setItem('virtualBackgroundUrl_' + this.get('token'), imageUrl)
localStorage.removeItem('virtualBackgroundBlurStrength_' + this.get('token'))
BrowserStorage.setItem('virtualBackgroundType_' + this.get('token'), VIRTUAL_BACKGROUND.BACKGROUND_TYPE.IMAGE)
BrowserStorage.setItem('virtualBackgroundUrl_' + this.get('token'), imageUrl)
BrowserStorage.removeItem('virtualBackgroundBlurStrength_' + this.get('token'))

this._webRtc.setVirtualBackground({
backgroundType: VIRTUAL_BACKGROUND.BACKGROUND_TYPE.IMAGE,
Expand All @@ -437,9 +438,9 @@ LocalMediaModel.prototype = {
throw new Error('WebRtc not initialized yet')
}

localStorage.setItem('virtualBackgroundType_' + this.get('token'), VIRTUAL_BACKGROUND.BACKGROUND_TYPE.VIDEO)
localStorage.setItem('virtualBackgroundUrl_' + this.get('token'), videoUrl)
localStorage.removeItem('virtualBackgroundBlurStrength_' + this.get('token'))
BrowserStorage.setItem('virtualBackgroundType_' + this.get('token'), VIRTUAL_BACKGROUND.BACKGROUND_TYPE.VIDEO)
BrowserStorage.setItem('virtualBackgroundUrl_' + this.get('token'), videoUrl)
BrowserStorage.removeItem('virtualBackgroundBlurStrength_' + this.get('token'))

this._webRtc.setVirtualBackground({
backgroundType: VIRTUAL_BACKGROUND.BACKGROUND_TYPE.VIDEO,
Expand All @@ -452,7 +453,7 @@ LocalMediaModel.prototype = {
throw new Error('WebRtc not initialized yet')
}

localStorage.removeItem('virtualBackgroundEnabled_' + this.get('token'))
BrowserStorage.removeItem('virtualBackgroundEnabled_' + this.get('token'))

this._webRtc.disableVirtualBackground()
},
Expand Down

0 comments on commit c1583c3

Please sign in to comment.