forked from mystiq/hydrogen-web
clean up video upload error handling
This commit is contained in:
parent
a672b0c78a
commit
9506bf1b81
1 changed files with 13 additions and 8 deletions
|
@ -188,20 +188,29 @@ export class RoomViewModel extends ViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
async _pickAndSendVideo() {
|
async _pickAndSendVideo() {
|
||||||
let file;
|
|
||||||
try {
|
try {
|
||||||
if (!this.platform.hasReadPixelPermission()) {
|
if (!this.platform.hasReadPixelPermission()) {
|
||||||
alert("Please allow canvas image data access, so we can scale your images down.");
|
alert("Please allow canvas image data access, so we can scale your images down.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
file = await this.platform.openFile("video/*");
|
const file = await this.platform.openFile("video/*");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!file.blob.mimeType.startsWith("video/")) {
|
if (!file.blob.mimeType.startsWith("video/")) {
|
||||||
return this._sendFile(file);
|
return this._sendFile(file);
|
||||||
}
|
}
|
||||||
let video = await this.platform.loadVideo(file.blob);
|
let video;
|
||||||
|
try {
|
||||||
|
video = await this.platform.loadVideo(file.blob);
|
||||||
|
} catch (err) {
|
||||||
|
// TODO: extract platform dependent code from view model
|
||||||
|
if (err instanceof window.MediaError && err.code === 4) {
|
||||||
|
throw new Error(`this browser does not support videos of type ${file?.blob.mimeType}.`);
|
||||||
|
} else {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
const content = {
|
const content = {
|
||||||
body: file.name,
|
body: file.name,
|
||||||
msgtype: "m.video",
|
msgtype: "m.video",
|
||||||
|
@ -219,11 +228,7 @@ export class RoomViewModel extends ViewModel {
|
||||||
this._room.createAttachment(thumbnail.blob, file.name);
|
this._room.createAttachment(thumbnail.blob, file.name);
|
||||||
await this._room.sendEvent("m.room.message", content, attachments);
|
await this._room.sendEvent("m.room.message", content, attachments);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof window.MediaError && err.code === 4) {
|
|
||||||
this._sendError = new Error(`this browser does not support videos of type ${file?.blob.mimeType}.`);
|
|
||||||
} else {
|
|
||||||
this._sendError = err;
|
this._sendError = err;
|
||||||
}
|
|
||||||
this.emitChange("error");
|
this.emitChange("error");
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue