I am making a web application where I need to call customers, Everything is working fine, but I need the call status when the customer receives the call or rejects the call from their phone. below is the ts code, where i am trying to get status of call but only i am getting accept and close status , where i can get call is accepted or rejected status
ngOnInit(): void {
this.patientName = this.data.patientName;
this.phoneNumber = this.data.patientPhoneNumber;
this.patientId = this.data.id;
let self = this;
this.authService.getRequest('cutsomer/api/gettoken', 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.modalService.dismissAll();
if (err.error && err.error.message) {
this.toastr.error(err.error.message);
}
}
});
}
setupHandlers(device) {
let self = this;
device.on('ready', (_device) => {
});
device.on('error', (error) => {
if (error.error.message) {
this.toastr.error(error.error.message);
}
this.modalService.dismissAll();
});
device.on('connect', (connection) => {
console.log(connection);
if ('patientPhoneNumber' in connection.message) {
this.callStartTime = new Date();
}
console.log(connection.status);
console.log('getcallstatus'+ connection._status);
});
device.on('disconnect', (connection) => {
console.log('endcall'+ connection._status);
this.dialogRef.close();
setTimeout(function () {
self.callEndTime = new Date();
//self.addMessageCenterData();
let formData = {
'status' : 'COMPLETED',
'voiceCallLogId' : self.voiceCallLogId,
'callEndTime' : self.callEndTime,
'callSid': connection.parameters.CallSid
}
self.updateCallStatus(formData);
this.timerRunning = false;
this.device.disconnectAll();
self.modalService.dismissAll();
}, 500);
});
device.on('hangup', (connection) => {
this.callEndTime = new Date();
});
}