I'm using Azure Communication Service to create video calls between 2 people (person 1 and person 2).
Person 1 logs in and waits for person 2 to log in. When person 2 connects person 1 is notified by the "incomingCall" function
callAgent.on('incomingCall', async (args) => {
console.log("-------- ON incomingCall ------------");
try {
incomingCall = args.incomingCall;
acceptCallPop.style.display = "block";
ring();
} catch (error) {
console.error("incomingCall ERROR");
console.error(error);
}
});
Person 1 can therefore accept the call with the "acceptCall" button. But if person 1 takes too long to accept (around 30s), the call is destroyed and if person 1 clicks on "acceptCall" there is an error.
I manage to activate a function for person 2 who can therefore know that the call is destroyed but I cannot find how to make person 1 aware when the call is destroyed.
How can person 1 know that the call is destroyed in real time ?
For voice and video calling, access tokens are typically used to authenticate users and enable them to make calls. These tokens are issued for a limited timeframe (30 seconds in this case) and have a limit on the number of requests (1000 for issuing access tokens). When integrating voice and video calling features into your application, managing user identities and their associated access tokens within these limits is necessary, as stated in this document.
Identity:
To handle the scenario where Person 1 needs to know if the call is destroyed in real time, event handling in Azure Communication Services can be utilized. -Code was taken from git
call.on('stateChanged', async () => {
console.log(`Call state changed: ${call.state}`);
if (call.state === 'Disconnected') {
// Call has been terminated
console.log('Call has been terminated');
// Send notification to person 1
sendCallTerminationNotification();
}
});
function sendCallTerminationNotification() {
// Update UI
console.log('Sending call termination notification to Person 1');
}
Alternatively, listen for the callEnded
event on the Call
object, as shown in this doc.