In my front end Javascript code, I call Twilio.Device.connect()
, and it is not firing a request to my Voice Request URL. I am not sure what is going on here. I ensure that I setup my capability token before hand, and there are no errors, but it still doesn't work. Here is front end JS code.
Twilio.Device.setup(resp.token);
Twilio.Device.connect({autoDial: true});
// respond to "connect" event
Twilio.Device.connect(function (conn) {
alert("Got here!");
}
Also here is my code to generate the token.
public static void getToken()
{
TwilioCapability t = new TwilioCapability(ACCOUNT_SID, AUTH_TOKEN);
t.allowClientOutgoing(APP_SID);
t.allowClientIncoming("test");
try {
throw new OKResponse(ImmutableMap.of("token", t.generateToken(3600)));
} catch (DomainException e) {
Logger.error(e, "Error generating twilio token: %s", e.getMessage());
}
}
I had the same problem,
You need to call the function generateToken() after calling allowClientOutgoing() and allowClientIncoming() so that the object created by Services_Twilio_Capability() has the app link.
This works:
This does not:
Also, it will not throw an error but your js will always show as "disconnected"
UPDATE
Here is an edit of my backend:
And here is the frontend (AJAX response callback):