mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
save
This commit is contained in:
@@ -36,6 +36,7 @@ import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, Cur
|
||||
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { MessageService } from 'src/app/services/chat/message.service';
|
||||
import { AlertController } from '@ionic/angular';
|
||||
|
||||
@Component({
|
||||
selector: 'app-group-messages',
|
||||
@@ -85,6 +86,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
durationDisplay = '';
|
||||
duration = 0;
|
||||
showAvatar = true;
|
||||
audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null
|
||||
|
||||
constructor(
|
||||
private menu: MenuController,
|
||||
@@ -111,6 +113,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
private processesService: ProcessesService,
|
||||
private CameraService: CameraService,
|
||||
private sanitiser: DomSanitizer,
|
||||
private alertController: AlertController
|
||||
) {
|
||||
this.loggedUserChat = authService.ValidatedUserChat['data'];
|
||||
this.isGroupCreated = true;
|
||||
@@ -296,15 +299,49 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
}
|
||||
|
||||
startRecording() {
|
||||
console.log('Recording');
|
||||
async checkAudioPermission() {
|
||||
const permissionStatus = await navigator.permissions.query({ name: 'microphone' } as any)
|
||||
|
||||
console.log('permission', permissionStatus.state); // granted, denied, prompt
|
||||
|
||||
if (this.recording) {
|
||||
return;
|
||||
this.audioPermissionStatus = permissionStatus.state
|
||||
|
||||
permissionStatus.onchange = (data : any) => {
|
||||
// console.log("Permission changed to " + data.state);
|
||||
// console.log('permission', permissionStatus.state); // granted, denied, prompt
|
||||
}
|
||||
this.recording = true;
|
||||
VoiceRecorder.startRecording();
|
||||
this.calculateDuration();
|
||||
|
||||
}
|
||||
|
||||
async startRecording() {
|
||||
|
||||
await this.checkAudioPermission();
|
||||
|
||||
if(this.audioPermissionStatus == 'granted') {
|
||||
if (this.recording) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.recording = true;
|
||||
VoiceRecorder.startRecording();
|
||||
this.calculateDuration();
|
||||
} else {
|
||||
|
||||
const alertPopup = await this.alertController.create({
|
||||
cssClass: 'my-custom-class',
|
||||
header: 'Necessita de permissão para gravar áudio',
|
||||
buttons: [{
|
||||
text: 'Ok',
|
||||
handler: () => {
|
||||
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
||||
await alertPopup.present();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AfterViewChecked, AfterViewInit, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, ViewChild } from '@angular/core';
|
||||
import { ActivatedRoute, Router } from '@angular/router'
|
||||
import { GestureController, Gesture, ModalController, NavParams, PopoverController, Platform } from '@ionic/angular';
|
||||
import { GestureController, Gesture, ModalController, NavParams, PopoverController, Platform, AlertController } from '@ionic/angular';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.page';
|
||||
import { EventPerson } from 'src/app/models/eventperson.model';
|
||||
@@ -97,6 +97,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
downloadFile: any;
|
||||
downloadProgess: number;
|
||||
|
||||
audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null
|
||||
|
||||
constructor(
|
||||
public popoverController: PopoverController,
|
||||
private modalController: ModalController,
|
||||
@@ -122,6 +124,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
private storage: Storage,
|
||||
private fileToBase64Service: FileToBase64Service,
|
||||
private sanitiser: DomSanitizer,
|
||||
private alertController: AlertController
|
||||
) {
|
||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||
this.roomId = this.navParams.get('roomId');
|
||||
@@ -143,6 +146,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.scrollToBottomClicked()
|
||||
}, 150)
|
||||
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -220,17 +224,49 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
}
|
||||
|
||||
startRecording() {
|
||||
console.log('Recording');
|
||||
|
||||
if (this.recording) {
|
||||
return;
|
||||
async checkAudioPermission() {
|
||||
const permissionStatus = await navigator.permissions.query({ name: 'microphone' } as any)
|
||||
|
||||
console.log('permission', permissionStatus.state); // granted, denied, prompt
|
||||
|
||||
this.audioPermissionStatus = permissionStatus.state
|
||||
|
||||
permissionStatus.onchange = (data : any) => {
|
||||
// console.log("Permission changed to " + data.state);
|
||||
// console.log('permission', permissionStatus.state); // granted, denied, prompt
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async startRecording() {
|
||||
|
||||
await this.checkAudioPermission();
|
||||
|
||||
if(this.audioPermissionStatus == 'granted') {
|
||||
if (this.recording) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.recording = true;
|
||||
VoiceRecorder.startRecording();
|
||||
this.calculateDuration();
|
||||
} else {
|
||||
|
||||
const alertPopup = await this.alertController.create({
|
||||
cssClass: 'my-custom-class',
|
||||
header: 'Necessita de permissão para gravar áudio',
|
||||
buttons: [{
|
||||
text: 'Ok',
|
||||
handler: () => {
|
||||
|
||||
}
|
||||
}]
|
||||
});
|
||||
|
||||
await alertPopup.present();
|
||||
|
||||
}
|
||||
this.recording = true;
|
||||
VoiceRecorder.startRecording()
|
||||
.then((result: GenericResponse) => console.log(result.value))
|
||||
.catch(error => console.log(error));
|
||||
this.calculateDuration();
|
||||
}
|
||||
|
||||
stopRecording() {
|
||||
@@ -397,35 +433,42 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.storage.get('recordData').then((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}`;
|
||||
|
||||
if(recordData?.value?.recordDataBase64) {
|
||||
if(recordData.value.recordDataBase64.includes('data:audio')){
|
||||
this.audioRecorded = recordData.value.recordDataBase64;
|
||||
}
|
||||
else{
|
||||
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData?.value?.recordDataBase64}`;
|
||||
}
|
||||
|
||||
console.log(this.audioRecorded);
|
||||
|
||||
//Converting base64 to 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.getDmRoom(roomId).send({
|
||||
file: {
|
||||
"type": "application/audio",
|
||||
"msDuration":audioFile.value.msDuration,
|
||||
"mimeType":audioFile.value.mimeType,
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName ,
|
||||
"title_link_download": true,
|
||||
"type": "audio"
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
} else {
|
||||
alert('no audio')
|
||||
}
|
||||
|
||||
console.log(this.audioRecorded);
|
||||
|
||||
//Converting base64 to 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.getDmRoom(roomId).send({
|
||||
file: {
|
||||
"type": "application/audio",
|
||||
"msDuration":audioFile.value.msDuration,
|
||||
"mimeType":audioFile.value.mimeType,
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName ,
|
||||
"title_link_download": true,
|
||||
"type": "audio"
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
this.deleteRecording();
|
||||
|
||||
Reference in New Issue
Block a user