I am using Twilio JavaScript client. I am able to make calls, capture callback events, connect, and disconnect. How do I implement a callback when a call is answered? I need to show a call timer after answering the call.
Asked
Active
Viewed 866 times
5
-
Can you please share the solutions if you figured out? – doobean Nov 25 '20 at 22:50
-
No, there is no option to show the timer after the call is answered. From the ring starting, we are showing a timer in our application. – prasannaboga Nov 27 '20 at 02:34
1 Answers
1
The Twilio js client has a Device property which has the following methods that you can use.
Twilio.Device.incoming(softPhoneIncoming);
Twilio.Device.connect(softPhoneConnect);
function softPhoneIncoming(conn) {
console.log(conn.parameters.From); // who is calling
conn.accept(); //This will accept the incoming phone call
}
function softPhoneConnect(conn)
{
// Called for all new connections, you could start the timer here
}

Louis Lewis
- 1,298
- 10
- 25
-
1I am doing the same, But timer includes the ringing duration also. – prasannaboga Oct 13 '14 at 06:38
-
Hi Prasanna, I would guess that if you wanted to capture the ringing duration, that you would have to perhaps start a timer when the softPhoneIncomming event fires, you would then stop the timer when your code perhaps calls conn.accept() or stop the timer when the softPhoneConnect event fires. Once you stop the timer, you could use the timer duration and then restart the timer for the call duration. – Louis Lewis Oct 13 '14 at 10:28