Skip to content

Commit

Permalink
Merge pull request #13360 from Souptik2001/feat/13199/auto-play-voice…
Browse files Browse the repository at this point in the history
…-messages
  • Loading branch information
Antreesy authored Sep 25, 2024
2 parents c284b1d + adf1b62 commit 6283abf
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/components/MessagesList/MessagesGroup/Message/Message.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ export default {
component: FilePreview,
props: {
token: this.message.token,
messageId: this.message.id,
nextMessageId: this.nextMessageId,
itemType,
referenceId: this.message.referenceId,
file: this.message.messageParameters[p],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
-->

<template>
<audio class="audio-player"
<audio ref="audioPlayer"
class="audio-player"
controls
:src="fileURL">
:src="fileURL"
@ended="handleEnded">
{{ t('spreed', 'Your browser does not support playing audio files') }}
</audio>
</template>
Expand All @@ -16,6 +18,8 @@ import { t } from '@nextcloud/l10n'
import { encodePath } from '@nextcloud/paths'
import { generateRemoteUrl } from '@nextcloud/router'

import { EventBus } from '../../../../../services/EventBus.js'

export default {
name: 'AudioPlayer',

Expand Down Expand Up @@ -47,6 +51,17 @@ export default {
type: String,
default: '',
},
/**
* Message ID.
*/
messageId: {
type: Number,
default: 0,
},
nextMessageId: {
type: Number,
default: 0,
},
},

computed: {
Expand All @@ -72,8 +87,37 @@ export default {
},
},

mounted() {
EventBus.on('audio-player-ended', this.autoPlay)
},

beforeDestroy() {
EventBus.off('audio-player-ended', this.autoPlay)
},

methods: {
t,

handleEnded() {
if (!this.nextMessageId) {
return
}

EventBus.emit('audio-player-ended', this.nextMessageId)
},

/**
* Autoplay the audio message as soon as previous one was played
*
* @param {number} messageId Message ID to play.
*/
autoPlay(messageId) {
if (messageId !== this.messageId) {
return
}

this.$refs.audioPlayer?.play()
},
},
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ export default {
required: true,
},

messageId: {
type: [String, Number],
default: 0,
},

nextMessageId: {
type: [String, Number],
default: 0,
},

/**
* File object
*/
Expand Down Expand Up @@ -245,6 +255,8 @@ export default {
name: this.file.name,
path: this.file.path,
link: this.file.link,
messageId: Number(this.messageId),
nextMessageId: Number(this.nextMessageId),
}
}
return {
Expand Down

0 comments on commit 6283abf

Please sign in to comment.