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

feat: replace audioRecorderStore with composable #13608

Merged
merged 1 commit into from
Oct 23, 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
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
Loading