This commit is contained in:
tiago.kayaya
2022-03-04 14:51:08 +01:00
parent 932b0b3c05
commit 0c9d5275a6
3 changed files with 93 additions and 6 deletions
@@ -366,6 +366,86 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.wsChatMethodsService.getDmRoom(this.roomId).send({})
}
async sendAudio(fileName) {
const roomId = this.roomId
/* const file: any = await this.fileService.getFileFromDevice(audio);
console.log('Add file', file)
const blob = new Blob([file],{type: file.type})
console.log('Add file', blob)
const formData = new FormData();
formData.append("blobFile", blob);
let pdfBase64;
this.blobToBase64(blob).then(res => {
console.log('Base64 pdf', res);
this.wsChatMethodsService.getDmRoom(roomId).send({
file: {
"type": file.type,
"guid": '',
},
attachments: [{
"title": file.name ,
"title_link": res,
"title_link_download": true,
"type": "file"
}],
temporaryData: formData
})
}); */
const audioFile = await Filesystem.readFile({
path: fileName,
directory: Directory.Data
})
console.log(audioFile);
const base64sound = audioFile.data;
const audioRef = new Audio(`data:audio/aac;base64,${base64sound}`)
console.log(audioRef);
//Converting base64 to blob
const base64 = await fetch(base64sound);
const base64Response = await fetch(`data:audio/aac;base64,${base64sound}`);
const blob = await base64Response.blob();
console.log(blob);
const formData = new FormData();
formData.append("blobFile", blob);
this.wsChatMethodsService.getDmRoom(roomId).send({
file: {
"type": "audio/aac",
"guid": '',
},
attachments: [{
"title": fileName ,
"title_link": audioRef,
"title_link_download": true,
"type": "file"
}],
temporaryData: formData
})
alert('OK')
}
blobToBase64 = blob => {
const reader = new FileReader();
reader.readAsDataURL(blob);
return new Promise(resolve => {
reader.onloadend = () => {
resolve(reader.result);
};
});
};
viewDocument(msg: any, url?: string) {
console.log(msg)
if (msg.attachments.type == "application/webtrix") {