summaryrefslogtreecommitdiffstats
path: root/src/components
diff options
context:
space:
mode:
authorMarco Ambrosini <marcoambrosini@pm.me>2021-05-26 13:52:28 +0100
committerMarco Ambrosini <marcoambrosini@pm.me>2021-06-11 08:24:43 +0100
commitbe7b78d081076e88491aca2e38b17d5c07c2d336 (patch)
tree14bd3985afa7f9c999a45d7c8403d15535b36674 /src/components
parent8395bd8a3e36a3dfd29ce20e3448de4cc9c70c17 (diff)
Warn the user in case of errors
Signed-off-by: Marco Ambrosini <marcoambrosini@pm.me>
Diffstat (limited to 'src/components')
-rw-r--r--src/components/NewMessageForm/AudioRecorder/AudioRecorder.vue70
1 files changed, 50 insertions, 20 deletions
diff --git a/src/components/NewMessageForm/AudioRecorder/AudioRecorder.vue b/src/components/NewMessageForm/AudioRecorder/AudioRecorder.vue
index 800a618b7..75ba26823 100644
--- a/src/components/NewMessageForm/AudioRecorder/AudioRecorder.vue
+++ b/src/components/NewMessageForm/AudioRecorder/AudioRecorder.vue
@@ -77,6 +77,7 @@ import Close from 'vue-material-design-icons/Close'
import Check from 'vue-material-design-icons/Check'
import Tooltip from '@nextcloud/vue/dist/Directives/Tooltip'
import { mediaDevicesManager } from '../../../utils/webrtc/index'
+import { showError } from '@nextcloud/dialogs'
export default {
name: 'AudioRecorder',
@@ -160,36 +161,65 @@ export default {
* Initialize the media stream and start capturing the audio
*/
async start() {
+ // Create new audio stream
try {
- // Create new audio stream
this.audioStream = await mediaDevicesManager.getUserMedia({
audio: true,
})
- // Create a mediarecorder to capture the stream
- this.mediaRecorder = new MediaRecorder(this.audioStream)
- // Add event handler to ondataAvailable
- this.mediaRecorder.ondataavailable = (e) => {
- this.chunks.push(e.data)
+ } catch (exception) {
+ console.debug(exception)
+ if (exception.name === 'NotAllowedError') {
+ showError(t('spreed', 'Access to the microphone was denied'))
+ } else {
+ showError(t('spreed', 'Microphone either not available or disabled in settings'))
}
- // Add event handler to onstop
- this.mediaRecorder.onstop = this.generateFile
+ return
+ }
+
+ // Create a mediarecorder to capture the stream
+ try {
+ this.mediaRecorder = new MediaRecorder(this.audioStream)
+ } catch (exception) {
+ console.debug(exception)
+ this.audioStream.getTracks().forEach(track => track.stop())
+ this.audioStream = null
+ showError(t('spreed', 'Error while recording audio'))
+ return
+ }
+
+ // Add event handler to onstop
+ this.mediaRecorder.onstop = this.generateFile
+
+ // Add event handler to ondataAvailable
+ this.mediaRecorder.ondataavailable = (e) => {
+ this.chunks.push(e.data)
+ }
+
+ try {
// Start the recording
this.mediaRecorder.start()
- // Start the timer
- this.recordTimer = setInterval(() => {
- if (this.recordTime.seconds === 59) {
- this.recordTime.minutes++
- this.recordTime.seconds = 0
- }
- this.recordTime.seconds++
- }, 1000)
- // Forward an event to let the parent NewMessageForm component
- // that there's an undergoing recording operation
- this.$emit('recording', true)
- console.debug(this.mediaRecorder.state)
} catch (exception) {
console.debug(exception)
+ this.aborted = true
+ this.stop()
+ this.resetComponentData()
+ showError(t('spreed', 'Error while recording audio'))
+ return
}
+
+ console.debug(this.mediaRecorder.state)
+
+ // Start the timer
+ this.recordTimer = setInterval(() => {
+ if (this.recordTime.seconds === 59) {
+ this.recordTime.minutes++
+ this.recordTime.seconds = 0
+ }
+ this.recordTime.seconds++
+ }, 1000)
+ // Forward an event to let the parent NewMessageForm component
+ // that there's an undergoing recording operation
+ this.$emit('recording', true)
},
/**