Send audio bug solved

This commit is contained in:
Eudes Inácio
2022-03-21 13:33:57 +01:00
parent 45bc324deb
commit 78126883dd
6 changed files with 171 additions and 68 deletions
@@ -106,7 +106,7 @@
<ion-label class="file-title">{{file.title}}</ion-label>
</div>
</div>
<div class="audio-contentainer" *ngIf="msg.file.type == 'application/audio'">
<div (click)="audioPreview(msg)" class="audio-contentainer" *ngIf="msg.file.type == 'application/audio'">
<audio [src]="file.title_link|safehtml" preload="metadata" class="flex-grow-1" controls controlsList="nodownload noplaybackrate"></audio>
</div>
<div class="file-details-optional add-attachment-bg-color">
+46 -5
View File
@@ -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);