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:
parent
4c1de61ff4
commit
cd29f8d681
7 changed files with 131 additions and 7 deletions
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue