问题
I have created an application using https://www.twilio.com/docs/howto/twilio-client-browser-soft-phone as the template. I am trying to log the CallSid for incoming and outgoing calls so that I can tag calls locally and use the Callsid to link between my local data and twilio's call store. I am able to get the CallSid for incoming calls easily with:
Twilio.Device.incoming(function (conn) {
if (confirm('Accept incoming call from ' + conn.parameters.From + '?')){
connection=conn;
conn.accept();
callsid = connection.parameters.CallSid;
}
else {
connection=conn;
conn.reject();
}
});
However, I can't seem to get it from any outgoing call initiated by the softphone. I have tried here:
$("#call").click(function() {
params = { "tocall" : $('#tocall').val()};
connection = Twilio.Device.connect(params);
callsid = connection.parameters.CallSid;
});
and here:
Twilio.Device.connect(function (conn) {
$('#status').text("Successfully established call");
toggleCallStatus();
callsid = connection.parameters.CallSid;
// And also tried
callsid = conn.parameters.CallSid;
});
However, both of these return undefined. I saw on https://www.twilio.com/docs/client/connection that the CallSid is set in the Outgoing .parameters towards the bottom of the page, so I assume it should be available in one of these function calls.
Is the CallSid available for calls originated by the client? And if so, where/how do I access it?
回答1:
Well, the connection.parameters you are getting is empty and you can check this by plugging console.dir(connection)
However, the reason is : Twilio does not populate parameters on outgoing connections for twilio.js V: 1.1 only for incoming connection so please use twilio.js 1.2 to make it works :)
回答2:
Using TwilioJS 1.2 as recommended by adnanonline is the correct option. This version sets all appropriate parameters for you to access.
//static.twilio.com/libs/twiliojs/1.2/twilio.min.js
来源:https://stackoverflow.com/questions/24020033/getting-callsid-for-twilio-softphone-twilio-js-incoming-outgoing-calls