mirror of https://github.com/vector-im/riot-web
Merge pull request #354 from Half-Shot/develop
Add support for sending uploaded content as m.videopull/21833/head
commit
2190dcbe1e
|
@ -52,6 +52,36 @@ function infoForImageFile(imageFile) {
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function infoForVideoFile(videoFile) {
|
||||||
|
var deferred = q.defer();
|
||||||
|
|
||||||
|
// Load the file into an html element
|
||||||
|
var video = document.createElement("video");
|
||||||
|
|
||||||
|
var reader = new FileReader();
|
||||||
|
reader.onload = function(e) {
|
||||||
|
video.src = e.target.result;
|
||||||
|
|
||||||
|
// Once ready, returns its size
|
||||||
|
video.onloadedmetadata = function() {
|
||||||
|
deferred.resolve({
|
||||||
|
w: video.videoWidth,
|
||||||
|
h: video.videoHeight
|
||||||
|
});
|
||||||
|
};
|
||||||
|
video.onerror = function(e) {
|
||||||
|
deferred.reject(e);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
reader.onerror = function(e) {
|
||||||
|
deferred.reject(e);
|
||||||
|
};
|
||||||
|
reader.readAsDataURL(videoFile);
|
||||||
|
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ContentMessages {
|
class ContentMessages {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.inprogress = [];
|
this.inprogress = [];
|
||||||
|
@ -81,6 +111,12 @@ class ContentMessages {
|
||||||
} else if (file.type.indexOf('audio/') == 0) {
|
} else if (file.type.indexOf('audio/') == 0) {
|
||||||
content.msgtype = 'm.audio';
|
content.msgtype = 'm.audio';
|
||||||
def.resolve();
|
def.resolve();
|
||||||
|
} else if (file.type.indexOf('video/') == 0) {
|
||||||
|
content.msgtype = 'm.video';
|
||||||
|
infoForVideoFile(file).then(function (videoInfo) {
|
||||||
|
extend(content.info, videoInfo);
|
||||||
|
def.resolve();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
content.msgtype = 'm.file';
|
content.msgtype = 'm.file';
|
||||||
def.resolve();
|
def.resolve();
|
||||||
|
|
Loading…
Reference in New Issue