Support send/receive of videos

Naive approach, just downloading the whole chunk every time! Need to figure out caching and streaming for long-play stuff.
This commit is contained in:
N-Pex 2021-03-17 12:13:53 +01:00
parent 4c1de61ff4
commit cd29f8d681
7 changed files with 131 additions and 7 deletions

View file

@ -12,7 +12,7 @@ var duration = require('dayjs/plugin/duration')
dayjs.extend(duration);
class Util {
getAttachment(matrixClient, event) {
getAttachment(matrixClient, event, progressCallback) {
return new Promise((resolve, reject) => {
const content = event.getContent();
if (content.url != null) {
@ -31,7 +31,13 @@ class Util {
reject("No url found!");
}
axios.get(url, { responseType: 'arraybuffer' })
axios.get(url, { responseType: 'arraybuffer', onDownloadProgress: progressEvent => {
let percentCompleted = Math.floor((progressEvent.loaded * 100) / progressEvent.total);
if (progressCallback) {
progressCallback(percentCompleted);
}
}
})
.then(response => {
return this.decryptIfNeeded(file, response);
})
@ -41,7 +47,12 @@ class Util {
.catch(err => {
console.log("Download error: ", err);
reject(err);
});
})
.finally(() => {
if (progressCallback) {
progressCallback(null);
}
});
});
}