Reputation: 2383
I'm creating a webb application where one can click on a number and dial from the browser.
I'm using the Twilio JS Client API and a Django back end to generate capability tokens. I'm using this Python Helper Library.
Everything seems to be working just fine but as soon as I'm trying to make a call I get a error on my client:
Uncaught Twilio.Exception: 31205: [object Object] twilio.min.js:45
WebSocket is already in CLOSING or CLOSED state.
Error 31205 is a JWT token expired error which is strange as the token has had a lifetime of 1 minute at most when I click-to-dial.
This is my view method in Django which generates a nice capability token:
def dialer(req, phone_number):
capability = TwilioCapability(settings.TWILIO_ACCOUNT_SID,
settings.TWILIO_AUTH_TOKEN)
# allow outgoing voice
capability.allow_client_outgoing(settings.TWILIO_APP_SID)
profile = user_models.UserProfile.objects.get(user=req.user)
v = {'capability_token': capability.generate(expires=600),
'phone_number': phone_number, 'user': req.user,
'caller_id': profile.user_phone}
return shortcuts.render_to_response('dialer.html', v)
And this is the JavaScript in my dialer.html:
Twilio.Device.setup('{{capability_token}}');
Twilio.Device.ready( function(device) {
console.log('Device ready...');
});
Twilio.Device.connect({
CallerId:'{{caller_id}}',
PhoneNumber: '{{phone_number}}'
});
$('#hang-up').click( function() {
Twilio.Device.disconnectAll();
});
Any ideas on why I'm getting this error? The Twilio documentation says that the capability_token has a lifetime of one hour as default.
Thanks!
PS. I made the exact same application using Node.js as back end and that works great :)
Upvotes: 2
Views: 1827
Reputation: 2383
SOLVED IT!
So there isn't any issues with code. The problem was my Virtual Machine that had the wrong date/time settings.
So, make sure that is correct when your trying to retrieve capability tokens from Twilio :)
Upvotes: 3