how to answer incoming call in twilio API -
how answer in twilio api using answer button, m unable pick call on browser, want know how answer or reject call while connecting device on answer button click, plz me
my snippet is
twilio.device.setup('<?=$token?>'); twilio.device.ready(function(device) { }); twilio.device.incoming(function(conn) { $("#number").val(conn.parameters.from); var ss= "incomging call:\n"+conn.parameters.from; $("#log").text("incoming connection " + conn.parameters.from); // accept incoming connection , start two-way audio conn.accept(); }); twilio.device.error(function(conn) { alert("error:\n"+data); }); function call() { // phone number or client connect call // params = {"phonenumber": $("#number").val()}; // twilio.device.connect(params); twilio.device.connect(); } function hangup() { twilio.device.disconnectall(); } <input type="text" id="number" name="number" /> <button class="call" onclick="call();"> answer </button> <button class="hangup" onclick="hangup();"> reject </button> <div id="log">loading app</div>
have idea in twilio incoming call???
twilio evangelist here.
the code you've included above automatically answering incoming calls because calling accept()
function in incoming event callback.
if want change app calls answered after button clicked, first need add second button ui. in buttons click
event call function calls accept
function.
you can continue use incoming callback enable accept button when there incoming call, notice you'll need create global variable holds incoming connection can access in accept
function.
var connection; twilio.device.incoming(function(conn) { connection = conn; $("#number").val(conn.parameters.from); var ss= "incomging call:\n"+conn.parameters.from; $("#log").text("incoming connection " + conn.parameters.from); //enable accept button $(".accept").prop('disabled', false); }); function accept() { connection.accept(); } <button class="accept" onclick="accept();" disabled>accept</button>
of course can lot more complex in incoming function whats shown above. check out this blog post more complex example shows how use jquery dialog widget show screen pop. hope helps.
Comments
Post a Comment