Skip to content

Commit

Permalink
Merge pull request #13610 from nextcloud/backport/13608/stable30
Browse files Browse the repository at this point in the history
  • Loading branch information
Antreesy authored Oct 23, 2024
2 parents a4ecea6 + c2e546e commit d474d44
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 45 deletions.
17 changes: 8 additions & 9 deletions src/components/NewMessage/NewMessageAudioRecorder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import { t } from '@nextcloud/l10n'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import { useAudioEncoder } from '../../composables/useAudioEncoder.ts'
import { mediaDevicesManager } from '../../utils/webrtc/index.js'
export default {
Expand All @@ -75,6 +76,13 @@ export default {
emits: ['recording', 'audio-file'],
setup() {
const encoderReady = useAudioEncoder()
return {
encoderReady,
}
},
data() {
return {
// The audio stream object
Expand Down Expand Up @@ -125,10 +133,6 @@ export default {
return t('spreed', 'Dismiss recording')
},
encoderReady() {
return this.$store.getters.encoderReady
},
canStartRecording() {
if (this.disabled) {
return false
Expand All @@ -139,16 +143,11 @@ export default {
},
watch: {
isRecording(newValue) {
console.debug('isRecording', newValue)
},
},
mounted() {
this.$store.dispatch('initializeAudioEncoder')
},
beforeDestroy() {
this.killStreams()
},
Expand Down
33 changes: 33 additions & 0 deletions src/composables/useAudioEncoder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { register } from 'extendable-media-recorder'
import { connect } from 'extendable-media-recorder-wav-encoder'
import { readonly, ref } from 'vue'
import type { Ref, DeepReadonly } from 'vue'

let requiresInit = true
const encoderReady = ref(false)

/**
* Initialize the audio encoder
*/
async function initAudioEncoder() {
requiresInit = false
await register(await connect())
encoderReady.value = true
}

/**
* Composable to use audio encoder for voice messages feature
* @return {DeepReadonly<Ref<boolean>>} - whether the encoder is ready
*/
export function useAudioEncoder(): DeepReadonly<Ref<boolean>> {
if (requiresInit) {
initAudioEncoder()
}

return readonly(encoderReady)
}
34 changes: 0 additions & 34 deletions src/store/audioRecorderStore.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/store/storeConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*/

import actorStore from './actorStore.js'
import audioRecorderStore from './audioRecorderStore.js'
import conversationsStore from './conversationsStore.js'
import fileUploadStore from './fileUploadStore.js'
import messagesStore from './messagesStore.js'
Expand All @@ -14,7 +13,6 @@ import tokenStore from './tokenStore.js'
export default {
modules: {
actorStore,
audioRecorderStore,
conversationsStore,
fileUploadStore,
messagesStore,
Expand Down

0 comments on commit d474d44

Please sign in to comment.