Skip to content

Commit

Permalink
fix(BrowserStorage): don't create empty storage entries
Browse files Browse the repository at this point in the history
- chore: clean up empty storage entries on initializing

Signed-off-by: Maksim Sukharev <antreesy.web@gmail.com>
  • Loading branch information
Antreesy committed Mar 4, 2024
1 parent 626af9c commit 285a229
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
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()
4 changes: 3 additions & 1 deletion src/stores/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export const useSettingsStore = defineStore('settings', {

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

Expand Down
4 changes: 3 additions & 1 deletion src/utils/webrtc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ async function signalingJoinCall(token, flags, silent, recordingConsent) {
const virtualBackgroundBlurStrength = BrowserStorage.getItem('virtualBackgroundBlurStrength_' + token)
const virtualBackgroundUrl = BrowserStorage.getItem('virtualBackgroundUrl_' + token)

localMediaModel.set('token', token)

if (enableAudio) {
localMediaModel.enableAudio()
} else {
Expand All @@ -263,7 +265,7 @@ async function signalingJoinCall(token, flags, silent, recordingConsent) {
localMediaModel.setVirtualBackgroundImage(virtualBackgroundUrl)
} else if (virtualBackgroundType === VIRTUAL_BACKGROUND.BACKGROUND_TYPE.VIDEO) {
localMediaModel.setVirtualBackgroundVideo(virtualBackgroundUrl)
} else {
} else if (virtualBackgroundType === VIRTUAL_BACKGROUND.BACKGROUND_TYPE.BLUR) {
localMediaModel.setVirtualBackgroundBlur(virtualBackgroundBlurStrength)
}

Expand Down

0 comments on commit 285a229

Please sign in to comment.