Skip to content

Commit

Permalink
fix(BrowserStorage): cleanup empty entries in BrowserStorage
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Mar 4, 2024
1 parent c556e13 commit cc426e5
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 59 deletions.
8 changes: 4 additions & 4 deletions src/components/CallView/shared/LocalAudioControlButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,17 @@ export default {
}

if (this.model.attributes.audioEnabled) {
this.model.disableAudio()
this.model.disableAudio(this.token)
} else {
this.model.enableAudio()
this.model.enableAudio(this.token)
}
},

updateDeviceState() {
if (BrowserStorage.getItem('audioDisabled_' + this.token) === 'true') {
this.model.disableAudio()
this.model.disableAudio(this.token)
} else {
this.model.enableAudio()
this.model.enableAudio(this.token)
}
},
},
Expand Down
8 changes: 4 additions & 4 deletions src/components/CallView/shared/LocalVideoControlButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,17 @@ export default {
}

if (this.model.attributes.videoEnabled) {
this.model.disableVideo()
this.model.disableVideo(this.token)
} else {
this.model.enableVideo()
this.model.enableVideo(this.token)
}
},

updateDeviceState() {
if (BrowserStorage.getItem('videoDisabled_' + this.token)) {
this.model.disableVideo()
this.model.disableVideo(this.token)
} else {
this.model.enableVideo()
this.model.enableVideo(this.token)
}
},
},
Expand Down
10 changes: 5 additions & 5 deletions src/components/MediaSettings/MediaSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ export default {
*/
clearBackground() {
if (this.isInCall) {
localMediaModel.disableVirtualBackground()
localMediaModel.disableVirtualBackground(this.token)
} else {
BrowserStorage.removeItem('virtualBackgroundEnabled_' + this.token)
}
Expand All @@ -597,8 +597,8 @@ export default {
*/
blurBackground() {
if (this.isInCall) {
localMediaModel.enableVirtualBackground()
localMediaModel.setVirtualBackgroundBlur(VIRTUAL_BACKGROUND.BLUR_STRENGTH.DEFAULT)
localMediaModel.enableVirtualBackground(this.token)
localMediaModel.setVirtualBackgroundBlur(this.token, VIRTUAL_BACKGROUND.BLUR_STRENGTH.DEFAULT)
} else {
BrowserStorage.setItem('virtualBackgroundEnabled_' + this.token, 'true')
BrowserStorage.setItem('virtualBackgroundType_' + this.token, VIRTUAL_BACKGROUND.BACKGROUND_TYPE.BLUR)
Expand Down Expand Up @@ -626,8 +626,8 @@ export default {
*/
setBackgroundImage(background) {
if (this.isInCall) {
localMediaModel.enableVirtualBackground()
localMediaModel.setVirtualBackgroundImage(background)
localMediaModel.enableVirtualBackground(this.token)
localMediaModel.setVirtualBackgroundImage(this.token, background)
} else {
BrowserStorage.setItem('virtualBackgroundEnabled_' + this.token, 'true')
BrowserStorage.setItem('virtualBackgroundType_' + this.token, VIRTUAL_BACKGROUND.BACKGROUND_TYPE.IMAGE)
Expand Down
12 changes: 6 additions & 6 deletions src/components/TopBar/TopBarMediaControls.vue
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,9 @@ export default {
} else {
this.spacebarKeyDown = false
if (this.audioEnabledBeforeSpacebarKeydown) {
this.model.enableAudio()
this.model.enableAudio(this.token)
} else {
this.model.disableAudio()
this.model.disableAudio(this.token)
}
this.audioEnabledBeforeSpacebarKeydown = undefined
}
Expand All @@ -464,9 +464,9 @@ export default {

toggleVirtualBackground() {
if (this.model.attributes.virtualBackgroundEnabled) {
this.model.disableVirtualBackground()
this.model.disableVirtualBackground(this.token)
} else {
this.model.enableVirtualBackground()
this.model.enableVirtualBackground(this.token)
}
},

Expand Down Expand Up @@ -552,10 +552,10 @@ export default {
this.model.stopSharingScreen()
this.dismissQualityWarningTooltip()
} else if (this.qualityWarningTooltip.action === 'disableVirtualBackground') {
this.model.disableVirtualBackground()
this.model.disableVirtualBackground(this.token)
this.dismissQualityWarningTooltip()
} else if (this.qualityWarningTooltip.action === 'disableVideo') {
this.model.disableVideo()
this.model.disableVideo(this.token)
this.dismissQualityWarningTooltip()
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/components/TopBar/TopBarMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,9 @@ export default {

toggleVirtualBackground() {
if (this.model.attributes.virtualBackgroundEnabled) {
this.model.disableVirtualBackground()
this.model.disableVirtualBackground(this.token)
} else {
this.model.enableVirtualBackground()
this.model.enableVirtualBackground(this.token)
}
},

Expand Down
22 changes: 22 additions & 0 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,26 @@ const migrateDirectLocalStorageToNextcloudBrowserStorage = () => {
BrowserStorage.setItem('localStorageMigrated', 'done')
}

/**
* Clean unrelated to any conversation keys (if token was not defined, when creating entry).
*/
const cleanUnrelatedBrowserStorageKeys = () => {
const storageKeys = [
'audioDisabled_',
'videoDisabled_',
'showMediaSettings_',
'virtualBackgroundEnabled_',
'virtualBackgroundType_',
'virtualBackgroundBlurStrength_',
'virtualBackgroundUrl_',
]

storageKeys.forEach(key => {
if (BrowserStorage.getItem(key) !== null) {
BrowserStorage.removeItem(key)
}
})
}

migrateDirectLocalStorageToNextcloudBrowserStorage()
cleanUnrelatedBrowserStorageKeys()
2 changes: 1 addition & 1 deletion src/stores/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const useSettingsStore = defineStore('settings', {

getters: {
getShowMediaSettings: (state) => (token) => {
if (state.showMediaSettings[token] !== undefined) {
if (!token || state.showMediaSettings[token] !== undefined) {
return state.showMediaSettings[token]
}

Expand Down
26 changes: 13 additions & 13 deletions src/utils/webrtc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,26 +245,26 @@ async function signalingJoinCall(token, flags, silent, recordingConsent) {
const virtualBackgroundUrl = BrowserStorage.getItem('virtualBackgroundUrl_' + token)

if (enableAudio) {
localMediaModel.enableAudio()
localMediaModel.enableAudio(token)
} else {
localMediaModel.disableAudio()
localMediaModel.disableAudio(token)
}
if (enableVideo) {
localMediaModel.enableVideo()
localMediaModel.enableVideo(token)
} else {
localMediaModel.disableVideo()
localMediaModel.disableVideo(token)
}
if (enableVirtualBackground) {
localMediaModel.enableVirtualBackground()
localMediaModel.enableVirtualBackground(token)
} else {
localMediaModel.disableVirtualBackground()
localMediaModel.disableVirtualBackground(token)
}
if (virtualBackgroundType === VIRTUAL_BACKGROUND.BACKGROUND_TYPE.IMAGE) {
localMediaModel.setVirtualBackgroundImage(virtualBackgroundUrl)
localMediaModel.setVirtualBackgroundImage(token, virtualBackgroundUrl)
} else if (virtualBackgroundType === VIRTUAL_BACKGROUND.BACKGROUND_TYPE.VIDEO) {
localMediaModel.setVirtualBackgroundVideo(virtualBackgroundUrl)
} else {
localMediaModel.setVirtualBackgroundBlur(virtualBackgroundBlurStrength)
localMediaModel.setVirtualBackgroundVideo(token, virtualBackgroundUrl)
} else if (virtualBackgroundType === VIRTUAL_BACKGROUND.BACKGROUND_TYPE.BLUR) {
localMediaModel.setVirtualBackgroundBlur(token, virtualBackgroundBlurStrength)
}

const startCallOnceLocalMediaStarted = (configuration) => {
Expand Down Expand Up @@ -388,9 +388,9 @@ async function signalingJoinCallForRecording(token, settings, internalClientAuth

const silent = true

localMediaModel.disableAudio()
localMediaModel.disableVideo()
localMediaModel.disableVirtualBackground()
localMediaModel.disableAudio(token)
localMediaModel.disableVideo(token)
localMediaModel.disableVirtualBackground(token)

const startCallOnceLocalMediaStarted = (configuration) => {
webRtc.off('localMediaStarted', startCallOnceLocalMediaStarted)
Expand Down
48 changes: 24 additions & 24 deletions src/utils/webrtc/models/LocalMediaModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,57 +351,57 @@ LocalMediaModel.prototype = {
this.set('localScreen', null)
},

enableAudio() {
enableAudio(token) {
if (!this._webRtc) {
throw new Error('WebRtc not initialized yet')
}

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

this._webRtc.unmute()
},

disableAudio() {
disableAudio(token) {
if (!this._webRtc) {
throw new Error('WebRtc not initialized yet')
}

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

this._webRtc.mute()
},

enableVideo() {
enableVideo(token) {
if (!this._webRtc) {
throw new Error('WebRtc not initialized yet')
}

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

this._webRtc.resumeVideo()
},

disableVideo() {
disableVideo(token) {
if (!this._webRtc) {
throw new Error('WebRtc not initialized yet')
}

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

this._webRtc.pauseVideo()
},

enableVirtualBackground() {
enableVirtualBackground(token) {
if (!this._webRtc) {
throw new Error('WebRtc not initialized yet')
}

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

this._webRtc.enableVirtualBackground()
},

setVirtualBackgroundBlur(blurStrength) {
setVirtualBackgroundBlur(token, blurStrength) {
if (!this._webRtc) {
throw new Error('WebRtc not initialized yet')
}
Expand All @@ -410,52 +410,52 @@ LocalMediaModel.prototype = {
blurStrength = VIRTUAL_BACKGROUND.BLUR_STRENGTH.DEFAULT
}

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

this._webRtc.setVirtualBackground({
backgroundType: VIRTUAL_BACKGROUND.BACKGROUND_TYPE.BLUR,
blurValue: blurStrength,
})
},

setVirtualBackgroundImage(imageUrl) {
setVirtualBackgroundImage(token, imageUrl) {
if (!this._webRtc) {
throw new Error('WebRtc not initialized yet')
}

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

this._webRtc.setVirtualBackground({
backgroundType: VIRTUAL_BACKGROUND.BACKGROUND_TYPE.IMAGE,
virtualSource: imageUrl,
})
},

setVirtualBackgroundVideo(videoUrl) {
setVirtualBackgroundVideo(token, videoUrl) {
if (!this._webRtc) {
throw new Error('WebRtc not initialized yet')
}

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

this._webRtc.setVirtualBackground({
backgroundType: VIRTUAL_BACKGROUND.BACKGROUND_TYPE.VIDEO,
virtualSource: videoUrl,
})
},

disableVirtualBackground() {
disableVirtualBackground(token) {
if (!this._webRtc) {
throw new Error('WebRtc not initialized yet')
}

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

this._webRtc.disableVirtualBackground()
},
Expand Down

0 comments on commit cc426e5

Please sign in to comment.