mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
Send audio bug solved
This commit is contained in:
@@ -356,6 +356,27 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).send({})
|
||||
}
|
||||
|
||||
base64toBlob(base64Data, contentType) {
|
||||
contentType = contentType || '';
|
||||
var sliceSize = 1024;
|
||||
var byteCharacters = atob(base64Data);
|
||||
var bytesLength = byteCharacters.length;
|
||||
var slicesCount = Math.ceil(bytesLength / sliceSize);
|
||||
var byteArrays = new Array(slicesCount);
|
||||
|
||||
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
|
||||
var begin = sliceIndex * sliceSize;
|
||||
var end = Math.min(begin + sliceSize, bytesLength);
|
||||
|
||||
var bytes = new Array(end - begin);
|
||||
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
|
||||
bytes[i] = byteCharacters[offset].charCodeAt(0);
|
||||
}
|
||||
byteArrays[sliceIndex] = new Uint8Array(bytes);
|
||||
}
|
||||
return new Blob(byteArrays, { type: contentType });
|
||||
}
|
||||
|
||||
async sendAudio(fileName) {
|
||||
|
||||
const roomId = this.roomId
|
||||
@@ -369,12 +390,16 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
else{
|
||||
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
console.log(this.audioRecorded)
|
||||
|
||||
//Converting base64 to blob
|
||||
const base64Response = await fetch(this.audioRecorded);
|
||||
const blob = await base64Response.blob();
|
||||
|
||||
//const base64Response = await fetch(this.audioRecorded);
|
||||
//console.log(base64Response)
|
||||
const encodedData = btoa(this.audioRecorded);
|
||||
const blob = this.base64toBlob(encodedData,'audio/webm')
|
||||
console.log(blob)
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
|
||||
@@ -387,12 +412,14 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName ,
|
||||
"title_link": this.audioRecorded,
|
||||
//"title_link": this.audioRecorded,
|
||||
"title_link_download": true,
|
||||
"type": "audio"
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
|
||||
});
|
||||
this.deleteRecording();
|
||||
|
||||
}
|
||||
@@ -898,12 +925,15 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
} else if (msg.file.type === 'application/pdf') {
|
||||
|
||||
this.downloadFile = event.body;
|
||||
} else if (msg.file.type == 'application/audio') {
|
||||
this.downloadFile = new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '');
|
||||
}
|
||||
|
||||
msg.attachments[0] = {
|
||||
image_url: this.downloadFile,
|
||||
name: msg.attachments[0].name,
|
||||
title: msg.attachments[0].title,
|
||||
title_link: this.downloadFile,
|
||||
title_link_download: msg.attachments[0].title_link_download,
|
||||
ts: msg.attachments[0].ts
|
||||
}
|
||||
@@ -936,6 +966,17 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
DocumentViewer.viewDocument
|
||||
}
|
||||
|
||||
async audioPreview(msg) {
|
||||
console.log(msg);
|
||||
if (!msg.attachments[0].title_link || msg.attachments[0].title_link === null || msg.attachments[0].title_link === '') {
|
||||
this.downloadFileMsg(msg)
|
||||
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async openPreview(msg) {
|
||||
console.log(msg);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user