5

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.

i alarmed alien
  • 9,412
  • 3
  • 27
  • 40
prasannaboga
  • 1,004
  • 1
  • 14
  • 36

1 Answers1

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
  • 1
    I 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