Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When making a call from the browser, how can I tell programmatically when the call has been answered?

I'm writing a web client with Flask, and integrating Twilio to let me make phone calls from the browser. All well and good, it's mostly working, but I have some status information I want to update when the call is answered.

The connection.status() method doesn't seem to help, since "open" seems to mean the call is attempting to go through, and the status stays as open until I get "closed" when the call ends.

Is there any good way (either through the browser or by registering a callback from the python code on the server) to get a status update for when the call transitions from "ringing" to "live" ?

like image 432
MahatmaManic Avatar asked Jun 22 '14 02:06

MahatmaManic


People also ask

How does call work in javascript?

The call() allows for a function/method belonging to one object to be assigned and called for a different object. call() provides a new value of this to the function/method. With call() , you can write a method once and then inherit it in another object, without having to rewrite the method for the new object.

Can Twilio be used for calls?

Using the Twilio REST API, you can make outgoing calls to phones, SIP-enabled endpoints, and Twilio Client connections.

What is a Web call?

Webcalling is voice calling, but embedded into a website. This has a wide range of implications. This means, as a customer, you can be browsing a website and start a voice call. Just 1 click required. No plugins, downloads, or need for a separate app or device.

Does Google Voice have a dialer?

From a web browser, you can make Google Voice calls faster and with one click on any web page with a phone number link. Important: One-click dialing only works on computers.


1 Answers

For outbound calls

The twilio.js library states:

Twilio.Device is your main entry point for creating outbound connections, accepting incoming connections, and setting up your connection event handlers.

Within the Device documentation, it goes on to state that the .status() method:

Returns the status of the device.

The key here is in the code snippet:

Twilio.Device.incoming(function(conn) {
    console.log(conn.parameters.From); 
    conn.status // => "pending"
    conn.accept();
    conn.status // => "connecting"
});

Now the key here is to remember that the Device.incoming is used when an outbound call has been made from your browser as specified here:

The Device.incoming handler function is called when an incoming event is fired. 
This is triggered whenever an incoming connection from an outbound REST call or a TwiML <Dial> to this device is made.

With the above code snippet, I was able to check

 conn.status

to be "connecting" when the connection was transitioning to open status and "open" once a call was picked up from an outgoing call. As a result I was able to set a flag and log once a outbound call was picked up. This was the TwiML used:

<Response>
  <Dial callerId="+1888XXXXXXX">
    {{INSERT PHONE NUMBER HERE}}
  </Dial>
</Response>

Here is the documentation for the device specifications and the general twilio.js library:

http://www.twilio.com/docs/client/device

and

http://www.twilio.com/docs/client/twilio-js

Please let me know if you have any other questions!

Thank you for your time,

like image 184
Devarsh Desai Avatar answered Oct 04 '22 23:10

Devarsh Desai