Skip to content

Commit

Permalink
Always stop audio streams
Browse files Browse the repository at this point in the history
Signed-off-by: Marco Ambrosini <[email protected]>
  • Loading branch information
marcoambrosini authored and backportbot[bot] committed Jul 1, 2021
1 parent a9e417c commit 6a17914
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/NewMessageForm/AudioRecorder/AudioRecorder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ export default {
await register(await connect())
},
beforeDestroy() {
this.killStreams()
},
methods: {
/**
* Initialize the media stream and start capturing the audio
Expand All @@ -173,6 +177,7 @@ export default {
})
} catch (exception) {
console.debug(exception)
this.killStreams()
if (exception.name === 'NotAllowedError') {
showError(t('spreed', 'Access to the microphone was denied'))
} else {
Expand All @@ -188,7 +193,7 @@ export default {
})
} catch (exception) {
console.debug(exception)
this.audioStream.getTracks().forEach(track => track.stop())
this.killStreams()
this.audioStream = null
showError(t('spreed', 'Error while recording audio'))
return
Expand All @@ -209,6 +214,7 @@ export default {
console.debug(exception)
this.aborted = true
this.stop()
this.killStreams()
this.resetComponentData()
showError(t('spreed', 'Error while recording audio'))
return
Expand Down Expand Up @@ -242,7 +248,7 @@ export default {
* Generate the file
*/
generateFile() {
this.audioStream.getTracks().forEach(track => track.stop())
this.killStreams()
if (!this.aborted) {
this.blob = new Blob(this.chunks, { type: 'audio/wav' })
// Generate file name
Expand Down Expand Up @@ -288,7 +294,15 @@ export default {
time += ' ' + ('0' + today.getHours()).slice(-2) + '-' + ('0' + today.getMinutes()).slice(-2) + '-' + ('0' + today.getSeconds()).slice(-2)
return t('spreed', 'Talk recording from {time} ({conversation})', { time, conversation }) + '.wav'
},
/**
* Stop the audio streams
*/
killStreams() {
this.audioStream?.getTracks().forEach(track => track.stop())
},
},
}
</script>
Expand Down

0 comments on commit 6a17914

Please sign in to comment.