-
+
{
console.log(res);
@@ -432,46 +430,64 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.wsChatMethodsService.getGroupRoom(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
-
- try {
-
- this.storage.get('recordData').then((recordData) => {
- console.log(recordData);
- if(recordData.value.recordDataBase64.includes('data:audio')){
- this.audioRecorded = recordData.value.recordDataBase64;
- }
- else{
- this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`;
- }
- });
- } catch (error) {}
-
+ let audioFile;
+ this.storage.get('recordData').then((recordData) => {
+ console.log(recordData);
+ audioFile = recordData;
+ if(recordData.value.recordDataBase64.includes('data:audio')){
+ this.audioRecorded = recordData.value.recordDataBase64;
+ }
+ else{
+ this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`;
+ }
//Converting base64 to blob
- const base64Response = await fetch(this.audioRecorded);
- const blob = await base64Response.blob();
-
+ const encodedData = btoa(this.audioRecorded);
+ const blob = this.base64toBlob(encodedData, recordData.value.mimeType)
+ console.log(blob)
const formData = new FormData();
formData.append("blobFile", blob);
this.wsChatMethodsService.getGroupRoom(roomId).send({
file: {
"type": "application/audio",
- /* "guid": '', */
+ "msDuration":audioFile.value.msDuration,
+ "mimeType":audioFile.value.mimeType,
},
attachments: [{
"title": fileName ,
- "title_link": this.audioRecorded,
"title_link_download": true,
- "type": "file"
+ "type": "audio"
}],
temporaryData: formData
})
- this.deleteRecording();
+ });
+ this.deleteRecording();
}
@@ -959,40 +975,11 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
card.el.style['z-index'] = 11;
}
- downloadFileMsg(msg) {
- console.log('FILE TYPE', msg.file.type)
- this.downloadFile = "";
- // if (msg.file.type == "application/img") {
- this.AttachmentsService.downloadFile(msg.file.guid).subscribe(async (event) => {
- console.log('FILE TYPE 22', msg.file.guid)
- var name = msg.file.guid;
-
- if (event.type === HttpEventType.DownloadProgress) {
- //this.downloadProgess = Math.round((100 * event.loaded) / event.total);
- console.log('FILE TYPE 33', msg.file.type)
- } else if (event.type === HttpEventType.Response) {
- if (msg.file.type == "application/img") {
- this.downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), ''));
- } else {
-
- this.downloadFile = event.body;
- }
-
- msg.attachments[0] = {
- image_url: this.downloadFile,
- name: msg.attachments[0].name,
- title: msg.attachments[0].title,
- title_link_download: msg.attachments[0].title_link_download,
- ts: msg.attachments[0].ts
- }
- this.sqlservice.updateChatMsg(msg._id, this.downloadFile);
- }
- });
- console.log('FILE TYPE 44', this.downloadFile)
- //}
+ downloadFileMsg(msg: MessageService) {
+ msg.downloadFileMsg()
}
- async openPreview(msg) {
+ async openPreview(msg: MessageService) {
if (!msg.attachments[0].image_url ||msg.attachments[0].image_url === null || msg.attachments[0].image_url === '') {
this.downloadFileMsg(msg)
@@ -1012,5 +999,12 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
}
+
+ 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 {}
+ }
}
diff --git a/src/app/pages/chat/messages/messages.page.html b/src/app/pages/chat/messages/messages.page.html
index bcd95991b..a11653d83 100644
--- a/src/app/pages/chat/messages/messages.page.html
+++ b/src/app/pages/chat/messages/messages.page.html
@@ -1,4 +1,4 @@
-
+