I can't listen any voice in my phone as well as in Web App after receiving the call from twilio

32 Views Asked by At

I have created an application in Angular where the admin calls their user on a phone number, I am using Twilio for this, my frontend is in Angular 14 and my Backend is in .net core API, But when I initiate a call from Web App, I am receiving calls on my phone, but no voice is coming from both side, whereas I can listen to my voice in Twilio console.

OnInit(): void {
console.log(this.data);
this.patientName = this.data.patientName;
    this.phoneNumber = this.data.patientPhoneNumber;
    this.patientId = this.data.id;
    this.user = JSON.parse(localStorage.getItem('userData'));
    console.log(this.user);
    let self = this;
    console.log(this.data.patientName);
    this.authService.getRequest('audiocall/twilio/token', null).subscribe((data) => {
        try {
            this.device = Twilio.Device.setup(data['data'], {
                debug: false,
                closeProtection: true
            });
            this.setupHandlers(this.device);
            setTimeout(function () {
                this.iserror = false;
                self.callCustomer();
            }, 500);
        } catch (err) {
    this.dialogRef.close();
    if (err.error && err.error.message) {
      this.toastr.error(err.error.message);
    }
        }
    });
    }
    setupHandlers(device) {
    let self = this;

    device.on('ready', (_device) => {
        console.log('Ready to call');
    });

    device.on('error', (error) => {
        console.error('ERROR: ' + error.message);
        this.iserror = true;
  if (error.error && error.error.message) {
    this.toastr.error(error.error.message);
  }
  this.dialogRef.close()
    });
    device.on('connect', (connection) => {
        console.log(connection);
        if ('patientPhoneNumber' in connection.message) {
            this.callStartTime = new Date();
        }
        if ('patientId' in connection.message) {
            this.callStartTime = new Date();
        }
        this.addCallStatus(connection);
    });

    device.on('disconnect', (connection) => {
        setTimeout(function () {
            self.callEndTime = new Date();
            let formData = {
                'status' : 'COMPLETED',
                'voiceCallLogId' : self.voiceCallLogId,
                'callEndTime' : self.callEndTime,
                'callSid': connection.parameters.CallSid
            }
            self.updateCallStatus(formData);
        }, 500);
    });

    device.on('hangup', (connection) => {
        this.callEndTime = new Date();
    });
}
0

There are 0 best solutions below