@Jeroen H The behavior you are experiencing is actually intended. The callEnded
event is triggered when the call ends, but in the case of an incoming call, it is triggered when the ringing stops, which is when the call is either accepted or declined. The callEndReason
subcode changes depending on whether the call was cancelled, declined, or accepted.
To get an event for the call's end, you can subscribe to the callStateChanged
event instead. This event is triggered whenever the call state changes, including when the call ends. You can check the state
property of the Call
object to see if the call has ended. The state
property will be set to 'Disconnected'
when the call ends.
Here's an example of how you can subscribe to the callStateChanged
event:
const callStateChangedHandler = (args) => {
const call = args.call;
if (call.state === 'Disconnected') {
const duration = call.duration;
console.log(`Call ended after ${duration} seconds`);
}
};
call.on('callStateChanged', callStateChangedHandler);
In this example, we're checking if the call state is 'Disconnected'
and logging the call duration when the call ends. You can use the duration
property of the Call
object to get the call duration in seconds.