Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 0bb0c81

Browse files
authored
Merge pull request #6434 from matrix-org/travis/voice-messages/upload-failed
Handle upload errors in voice messages
2 parents 98472b4 + 079e75a commit 0bb0c81

File tree

3 files changed

+55
-37
lines changed

3 files changed

+55
-37
lines changed

src/components/views/rooms/VoiceRecordComposerTile.tsx

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -68,37 +68,49 @@ export default class VoiceRecordComposerTile extends React.PureComponent<IProps,
6868
}
6969

7070
await this.state.recorder.stop();
71-
const upload = await this.state.recorder.upload(this.props.room.roomId);
72-
MatrixClientPeg.get().sendMessage(this.props.room.roomId, {
73-
"body": "Voice message",
74-
//"msgtype": "org.matrix.msc2516.voice",
75-
"msgtype": MsgType.Audio,
76-
"url": upload.mxc,
77-
"file": upload.encrypted,
78-
"info": {
79-
duration: Math.round(this.state.recorder.durationSeconds * 1000),
80-
mimetype: this.state.recorder.contentType,
81-
size: this.state.recorder.contentLength,
82-
},
83-
84-
// MSC1767 + Ideals of MSC2516 as MSC3245
85-
// https://github.com/matrix-org/matrix-doc/pull/3245
86-
"org.matrix.msc1767.text": "Voice message",
87-
"org.matrix.msc1767.file": {
88-
url: upload.mxc,
89-
file: upload.encrypted,
90-
name: "Voice message.ogg",
91-
mimetype: this.state.recorder.contentType,
92-
size: this.state.recorder.contentLength,
93-
},
94-
"org.matrix.msc1767.audio": {
95-
duration: Math.round(this.state.recorder.durationSeconds * 1000),
96-
97-
// https://github.com/matrix-org/matrix-doc/pull/3246
98-
waveform: this.state.recorder.getPlayback().thumbnailWaveform.map(v => Math.round(v * 1024)),
99-
},
100-
"org.matrix.msc3245.voice": {}, // No content, this is a rendering hint
101-
});
71+
72+
try {
73+
const upload = await this.state.recorder.upload(this.props.room.roomId);
74+
75+
// noinspection ES6MissingAwait - we don't care if it fails, it'll get queued.
76+
MatrixClientPeg.get().sendMessage(this.props.room.roomId, {
77+
"body": "Voice message",
78+
//"msgtype": "org.matrix.msc2516.voice",
79+
"msgtype": MsgType.Audio,
80+
"url": upload.mxc,
81+
"file": upload.encrypted,
82+
"info": {
83+
duration: Math.round(this.state.recorder.durationSeconds * 1000),
84+
mimetype: this.state.recorder.contentType,
85+
size: this.state.recorder.contentLength,
86+
},
87+
88+
// MSC1767 + Ideals of MSC2516 as MSC3245
89+
// https://github.com/matrix-org/matrix-doc/pull/3245
90+
"org.matrix.msc1767.text": "Voice message",
91+
"org.matrix.msc1767.file": {
92+
url: upload.mxc,
93+
file: upload.encrypted,
94+
name: "Voice message.ogg",
95+
mimetype: this.state.recorder.contentType,
96+
size: this.state.recorder.contentLength,
97+
},
98+
"org.matrix.msc1767.audio": {
99+
duration: Math.round(this.state.recorder.durationSeconds * 1000),
100+
101+
// https://github.com/matrix-org/matrix-doc/pull/3246
102+
waveform: this.state.recorder.getPlayback().thumbnailWaveform.map(v => Math.round(v * 1024)),
103+
},
104+
"org.matrix.msc3245.voice": {}, // No content, this is a rendering hint
105+
});
106+
} catch (e) {
107+
console.error("Error sending/uploading voice message:", e);
108+
Modal.createTrackedDialog('Upload failed', '', ErrorDialog, {
109+
title: _t('Upload Failed'),
110+
description: _t("The voice message failed to upload."),
111+
});
112+
return; // don't dispose the recording so the user can retry, maybe
113+
}
102114
await this.disposeRecording();
103115
}
104116

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,7 @@
16781678
"Invited by %(sender)s": "Invited by %(sender)s",
16791679
"Jump to first unread message.": "Jump to first unread message.",
16801680
"Mark all as read": "Mark all as read",
1681+
"The voice message failed to upload.": "The voice message failed to upload.",
16811682
"Unable to access your microphone": "Unable to access your microphone",
16821683
"We were unable to access your microphone. Please check your browser settings and try again.": "We were unable to access your microphone. Please check your browser settings and try again.",
16831684
"No microphone found": "No microphone found",

src/voice/VoiceRecording.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,17 @@ export class VoiceRecording extends EventEmitter implements IDestroyable {
333333

334334
if (this.lastUpload) return this.lastUpload;
335335

336-
this.emit(RecordingState.Uploading);
337-
const { url: mxc, file: encrypted } = await uploadFile(this.client, inRoomId, new Blob([this.audioBuffer], {
338-
type: this.contentType,
339-
}));
340-
this.lastUpload = { mxc, encrypted };
341-
this.emit(RecordingState.Uploaded);
336+
try {
337+
this.emit(RecordingState.Uploading);
338+
const { url: mxc, file: encrypted } = await uploadFile(this.client, inRoomId, new Blob([this.audioBuffer], {
339+
type: this.contentType,
340+
}));
341+
this.lastUpload = { mxc, encrypted };
342+
this.emit(RecordingState.Uploaded);
343+
} catch (e) {
344+
this.emit(RecordingState.Ended);
345+
throw e;
346+
}
342347
return this.lastUpload;
343348
}
344349
}

0 commit comments

Comments
 (0)