Commit deb1f3e2 by Lee Munkyeong

動画エンコード実装

parent 5405f280
...@@ -825,49 +825,90 @@ CHAT_UI.deleteButtonAction = function(isInvite) { ...@@ -825,49 +825,90 @@ CHAT_UI.deleteButtonAction = function(isInvite) {
CHAT_UI.showConfirmView(isInvite) CHAT_UI.showConfirmView(isInvite)
$('#select_user_list .user_list').find('.userCheckBox').show(); $('#select_user_list .user_list').find('.userCheckBox').show();
} }
var GetFileBlobUsingURL = function (url, convertBlob) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.responseType = "blob";
xhr.addEventListener('load', function() {
console.log(xhr.response);
convertBlob(xhr.response);
});
xhr.send();
};
var blobToFile = function (blob, name) {
blob.lastModifiedDate = new Date();
blob.name = name;
return blob;
};
var GetFileObjectFromURL = function(filePathOrUrl, convertBlob) {
GetFileBlobUsingURL(filePathOrUrl, function (blob) {
convertBlob(blobToFile(blob, 'testFile.mp4'));
});
};
CHAT_UI.videoEncodeEnd = function(encodedUri) { CHAT_UI.videoEncodeEnd = function(encodedUri) {
console.log('encode end'); console.log('encode end');
console.log(encodedUri); console.log('file:'+encodedUri);
var fileName = encodedUri.split('/')[encodedUri.split('/').length-1];
// convert base64 to raw binary data held in a string //var testFile = new File(decodeURI('file://'+encodedUri));
// doesn't handle URLEncoded DataURIs - see SO answer #6850276 for code that does this var FileURL='file:'+encodedUri;
var byteString = atob(encodedUri.split(',')[1]); var xhr = new XMLHttpRequest();
xhr.open("GET", FileURL);
// separate out the mime component xhr.responseType = "blob";
var mimeString = encodedUri.split(',')[0].split(':')[1].split(';')[0] xhr.addEventListener('load', function() {
console.log(xhr.response);
// write the bytes of the string to an ArrayBuffer var formData=new FormData();
var ab = new ArrayBuffer(byteString.length); formData.append("image", xhr.response, fileName);
formData.append('sid', CHAT.globalLoginParameter.sid);
// create a view into the buffer formData.append('roomId', CHAT.globalLoginParameter.roomId);
var ia = new Uint8Array(ab); jQuery.ajax({
async: true,
// set the bytes of the buffer to the correct values url: CMS_SERVER_URL+"/chatapi/file/upload",
for (var i = 0; i < byteString.length; i++) { type: "post",
ia[i] = byteString.charCodeAt(i); data: formData,
} contentType: false,
processData: false,
// write the ArrayBuffer to a blob, and you're done error: function () {
var blob = new Blob([ab], {type: "video/mp4"}); alert("読み込み失敗");
console.log(blob); CHAT_UI.dismissLoadingIndicator();
var formData=new FormData(); }
/*formData.append("fileData",blob,uploadFileName); }).done(function(res) {
formData.append('sid', globalUserInfo.sid); var imgPath = CMS_SERVER_URL + '/chatapi/file/getImage?fileName=' + res.fileName + '&roomId=' + CHAT.globalLoginParameter.roomId;
formData.append('roomId', globalUserInfo.roomId);*/ var imageName = res.fileName
CHAT_UI.dismissLoadingIndicator(); // uploadFileの判断
/* var path = CHAT_DB.loadEncodedFile(); var extension = imageName.substr(imageName.lastIndexOf('.') + 1).toLowerCase();
var file = $('#videoInputTag');
file = path; if (res.thumbnailPath && res.thumbnailPath.length > 0) {
if (file) { imgPath = CMS_SERVER_URL + '/chatapi/file/getImage?fileName=' + res.thumbImageFileName + '&roomId=' + CHAT.globalLoginParameter.roomId;
var fd = new FormData($('#video-form')[0]); }
// var requestFile = RequestBody.create(MediaType.parse("video/mp4"), file) let downloadPath = CMS_SERVER_URL + '/chatapi/file/download?fileName=' + imageName + '&roomId=' + CHAT.globalLoginParameter.room
// var fd = new FormData($('#video-form')[0]); var videoSrc = CMS_SERVER_URL + '/chatapi/file/getImage?fileName=' + res.fileName + '&roomId=' + CHAT.globalLoginParameter.roomId;
// console.log("kdh check requestFile = " + requestFile); const totalDiv = $('<div/>', {id:"attachedImages"});
CHAT.uploadImage(fd); const videoTag = $('<video/>', {controls:"true", width:'auto', style:'max-width:100%'});
return; const source = $('<source/>', {src:videoSrc});
}*/ const downloadIcon = $('<a/>',{href:downloadPath, class:'fa fa-download', download:res.fileName
videoTag.append(source);
totalDiv.append(videoTag);
totalDiv.append(downloadIco
let text = totalDiv.prop('outerHTML');
let encodedText
try {
encodedText = encodeURIComponent(text)
} catch(e) {
encodedText = text;
}
socket.emit('createMessage', {
text: encodedText + messageSeperator + messageType.VIDEO
}, 1);
$('.overlay').removeClass('active undismissable');
$('.loader').removeClass('active');
CHAT_UI.dismissLoadingIndicator();
})
});
xhr.send();
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment