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 { Camera, CameraResultType, CameraSource } from '@capacitor/camera';
|
||||
import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder';
|
||||
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { AlertController, Platform, NavParams } from '@ionic/angular';
|
||||
|
||||
/*
|
||||
import * as pdfjsLib from 'pdfjs-dist';
|
||||
@@ -99,6 +100,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
durationDisplay = '';
|
||||
duration = 0;
|
||||
|
||||
audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null
|
||||
|
||||
constructor(
|
||||
public wsChatMethodsService: WsChatMethodsService,
|
||||
private modalController: ModalController,
|
||||
@@ -121,6 +124,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
private CameraService: CameraService,
|
||||
private toastService: ToastService,
|
||||
private sanitiser: DomSanitizer,
|
||||
private alertController: AlertController
|
||||
|
||||
) {
|
||||
console.log('OnCONSTRUCTOR');
|
||||
@@ -293,15 +297,49 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
stopRecording() {
|
||||
@@ -331,7 +369,7 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
async deleteRecording(){
|
||||
async deleteRecording() {
|
||||
this.storage.remove('fileName');
|
||||
this.storage.remove('recordData');
|
||||
|
||||
|
||||
@@ -232,6 +232,7 @@
|
||||
<button #recordbtn *ngIf="!wsChatMethodsService.getDmRoom(roomId).message && !lastAudioRecorded" (click)="startRecording()" class="btn-no-color">
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " class="chat-icon-send" src="assets/icon/theme/default/icons-chat-record-audio.svg"></ion-icon>
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " class="chat-icon-send" src="assets/icon/theme/gov/icons-chat-record-audio.svg"></ion-icon>
|
||||
<!-- <ion-icon *ngIf="audioPermissionStatus != 'granted' " class="chat-icon-send" src="assets/icon/theme/gov/icons-chat-record-audio-disable.svg"></ion-icon> -->
|
||||
</button>
|
||||
<button *ngIf="wsChatMethodsService.getDmRoom(roomId).message" class="btn-no-color" (click)="sendMessage()">
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " class="chat-icon-send" src="assets/icon/theme/gov/icons-chat-send.svg"></ion-icon>
|
||||
|
||||
@@ -35,6 +35,7 @@ import { DocumentViewer, DocumentViewerOptions } from '@ionic-native/document-vi
|
||||
import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder';
|
||||
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { AlertController, Platform, NavParams } from '@ionic/angular';
|
||||
|
||||
const IMAGE_DIR = 'stored-images';
|
||||
@Component({
|
||||
@@ -90,6 +91,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
durationDisplay = '';
|
||||
duration = 0;
|
||||
|
||||
audioPermissionStatus: 'granted'| 'denied' | 'prompt' | null = null
|
||||
|
||||
constructor(
|
||||
public popoverController: PopoverController,
|
||||
private modalController: ModalController,
|
||||
@@ -118,8 +121,11 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
private processesService: ProcessesService,
|
||||
private fileToBase64Service: FileToBase64Service,
|
||||
private sanitiser: DomSanitizer,
|
||||
private alertController: AlertController
|
||||
) {
|
||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||
|
||||
this.checkAudioPermission()
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
@@ -144,6 +150,20 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.scrollToBottom();
|
||||
|
||||
@@ -268,14 +288,36 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
}
|
||||
|
||||
startRecording() {
|
||||
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();
|
||||
|
||||
if (this.recording) {
|
||||
return;
|
||||
}
|
||||
this.recording = true;
|
||||
VoiceRecorder.startRecording();
|
||||
this.calculateDuration();
|
||||
|
||||
}
|
||||
|
||||
stopRecording() {
|
||||
|
||||
Reference in New Issue
Block a user