Reputation: 11
I have implemented Twilio Client for the in-browser calls using PHP/Laravel and Twilio Client JS SDK. The implementation is working fine I can make the call from the browser and can even receive a call in the browser.
Now, I want to show calls coming in, at the same time while I'm in call with some another customer in the browser and then I can handle them whether I want to accept that call or not If I answer that then the in-progress customer should go on hold and I can talk with another customer, exactly the same way we do it in our cellphones.
The scenario is this, I'm in call with some customer on the line, Now at the same point of time another customer is calling on the same Twilio number, So, now I should get the notification/popup to answer that call, reject, and hold, etc.
So if anybody can help me with proper code/example it would be really appreciated.
P.S: I went through the concept of Enqueue in Twilio but couldn't understand how to implement it.
Thanks in advance.
Upvotes: 1
Views: 1046
Reputation: 1466
As from the official docs Twilio.Device.incoming get call when you receive an incoming call, as callback you get a connection
, call conn.accept()
method to start audio streaming, Add a global variable to check if already call is already ongoing
var isOngoing = false; // Global variable
Twilio.Device.incoming(function(conn) {
console.log('Incoming connection from ' + conn.parameters.From);
// accept the incoming connection only if you are not on another call.
if(!isOngoing) {
isOngoing = true;
conn.accept();
} else {
// Add you other implementation for displaying your popup or a message box.
conn.reject();
}
});
/* Callback for when a call ends */
Twilio.Device.disconnect(function(connection) {
isOngoing = false
});
isOngoing
variable to false
so that you can receive another call. Upvotes: 2