I have implemented Twilio Voice JS SDK to make/receive outgoing/incoming calls from within browser.
Using the status callbacks, I get to know when the call was initiated, ringing, in progress and completed.
However, I am not able to find and record which user made/answered a call (All users have different log id and different client identity id).
When the Incoming call is received, incoming event is triggered on voice client (browser), however, there is no call information availale (call SID etc) to record it.
Similarly, when an outgoing call is made, Call SID information is not available.
Code for incoming calls and to record callsid
device.on("incoming", handleIncomingCall);
function handleIncomingCall(call) {
try{
console.log(call.properties.CallSid);
}
catch (err)
{
console.log("An error occurred while retrieving callsid properties from call object.");
}
//show incoming call div
incomingCallDiv.classList.remove("d-none");
//add event listeners for Accept, Reject, and Hangup buttons
incomingCallAcceptButton.onclick = () => {
acceptIncomingCall(call);
};
incomingCallRejectButton.onclick = () => {
rejectIncomingCall(call);
};
incomingCallHangupButton.onclick = () => {
hangupIncomingCall(call);
};
}
Message that I am getting in the console
An error occurred while retrieving callsid properties from call object.
When you make an outgoing call or recive an incoming call event with the Twilio Voice SDK, the
Call
object has aparameters
property that contains the call parameters you would also receive via the webhook.So, if you are placing an outgoing call, you can get the call Sid like this:
Or if you are receiving a call:
Note that the CallSid you receive here will not match the outbound CallSid to a another phone when placing an outbound call, and will not match the inbound CallSid when receiving the call. Twilio calls between two people (or phone numbers or clients) have a leg for each connection between Twilio and that person, with a different Call Sid for each leg. You can connect the calls together by understanding the call parent. If you are receiving an incoming call, the parent call is the inbound leg. If you are placing an outgoing call, the parent call is that outbound leg. You can list calls and filter by the parent call Sid using the API.