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

fix: migrate sounds store to Pinia 🍍 #13356

Merged
merged 2 commits into from
Sep 25, 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
13 changes: 9 additions & 4 deletions src/Recording.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
<script>
import CallView from './components/CallView/CallView.vue'

import {
signalingKill,
} from './utils/webrtc/index.js'
import { useSoundsStore } from './stores/sounds.js'
import { signalingKill } from './utils/webrtc/index.js'

export default {
name: 'Recording',
Expand All @@ -22,6 +21,12 @@ export default {
CallView,
},

setup() {
return {
soundsStore: useSoundsStore()
}
},

computed: {
/**
* The current conversation token
Expand All @@ -37,7 +42,7 @@ export default {
if (this.$route.name === 'recording') {
await this.$store.dispatch('updateToken', this.$route.params.token)

await this.$store.dispatch('setPlaySounds', false)
await this.soundsStore.setShouldPlaySounds(false)
}

// This should not be strictly needed, as the recording server is
Expand Down
23 changes: 18 additions & 5 deletions src/components/MediaSettings/MediaDevicesSpeakerTest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { t } from '@nextcloud/l10n'

import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'

import { useSoundsStore } from '../../stores/sounds.js'

export default {

name: 'MediaDevicesSpeakerTest',
Expand All @@ -34,6 +36,12 @@ export default {
VolumeHighIcon,
},

setup() {
return {
soundsStore: useSoundsStore()
}
},

data() {
return {
isPlayingTestSound: false,
Expand Down Expand Up @@ -61,17 +69,22 @@ export default {

methods: {
t,

playTestSound() {
if (this.isPlayingTestSound) {
this.$store.dispatch('pauseWaitAudio')
this.soundsStore.pauseAudio('wait')
return
}
this.isPlayingTestSound = true
this.$store.dispatch('playWaitAudio').then((response) => {
response.addEventListener('ended', () => {
try {
this.soundsStore.playAudio('wait')
this.soundsStore.audioObjects.wait.addEventListener('ended', () => {
this.isPlayingTestSound = false
})
})
}, { once: true })
} catch (error) {
console.error(error)
this.isPlayingTestSound = false
}
},
},
}
Expand Down
11 changes: 7 additions & 4 deletions src/components/SettingsDialog/SettingsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
:name="t('spreed', 'Sounds')"
class="app-settings-section">
<NcCheckboxRadioSwitch id="play_sounds"
:checked="playSounds"
:checked="shouldPlaySounds"
:disabled="playSoundsLoading"
type="switch"
class="checkbox"
Expand Down Expand Up @@ -197,6 +197,7 @@ import BrowserStorage from '../../services/BrowserStorage.js'
import { getTalkConfig } from '../../services/CapabilitiesManager.ts'
import { useCustomSettings } from '../../services/SettingsAPI.ts'
import { useSettingsStore } from '../../stores/settings.js'
import { useSoundsStore } from '../../stores/sounds.js'

const isBackgroundBlurred = loadState('spreed', 'force_enable_blur_filter', '')
const supportTypingStatus = getTalkConfig('local', 'chat', 'typing-privacy') !== undefined
Expand All @@ -215,10 +216,12 @@ export default {

setup() {
const settingsStore = useSettingsStore()
const soundsStore = useSoundsStore()
const { customSettingsSections } = useCustomSettings()

return {
settingsStore,
soundsStore,
supportTypingStatus,
isBackgroundBlurred,
customSettingsSections,
Expand All @@ -236,8 +239,8 @@ export default {
},

computed: {
playSounds() {
return this.$store.getters.playSounds
shouldPlaySounds() {
return this.soundsStore.shouldPlaySounds
},

attachmentFolder() {
Expand Down Expand Up @@ -348,7 +351,7 @@ export default {
this.playSoundsLoading = true
try {
try {
await this.$store.dispatch('setPlaySounds', !this.playSounds)
await this.soundsStore.setShouldPlaySounds(!this.shouldPlaySounds)
} catch (e) {
showError(t('spreed', 'Failed to save sounds setting'))
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/TopBar/CallButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ import { hasTalkFeature } from '../../services/CapabilitiesManager.ts'
import { EventBus } from '../../services/EventBus.js'
import { useBreakoutRoomsStore } from '../../stores/breakoutRooms.ts'
import { useSettingsStore } from '../../stores/settings.js'
import { useSoundsStore } from '../../stores/sounds.js'
import { useTalkHashStore } from '../../stores/talkHash.js'
import { blockCalls, unsupportedWarning } from '../../utils/browserCheck.js'

Expand Down Expand Up @@ -197,6 +198,7 @@ export default {
breakoutRoomsStore: useBreakoutRoomsStore(),
talkHashStore: useTalkHashStore(),
settingsStore: useSettingsStore(),
soundsStore: useSoundsStore(),
isMobile: useIsMobile(),
}
},
Expand Down Expand Up @@ -436,7 +438,7 @@ export default {

handleClick() {
// Create audio objects as a result of a user interaction to allow playing sounds in Safari
this.$store.dispatch('createAudioObjects')
this.soundsStore.initAudioObjects()

if (this.isMediaSettings || this.isPhoneRoom) {
emit('talk:media-settings:hide')
Expand Down
11 changes: 5 additions & 6 deletions src/services/settingsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ const setSIPSettings = async function(sipGroups, sharedSecret, dialInInfo) {
})
}

const setPlaySounds = async function(isGuest, enabled) {
const savableValue = enabled ? 'yes' : 'no'
if (!isGuest) {
return axios.post(generateOcsUrl('apps/spreed/api/v1/settings/user'), {
const setPlaySounds = async function(hasUserAccount, value) {
if (hasUserAccount) {
await axios.post(generateOcsUrl('apps/spreed/api/v1/settings/user'), {
key: 'play_sounds',
value: savableValue,
value,
})
} else {
BrowserStorage.setItem('play_sounds', savableValue)
BrowserStorage.setItem('play_sounds', value)
}
}

Expand Down
Loading
Loading