I am try to initialize Twilio SDK using a Twilio JWT Token.
Below is my code:
<script type="text/javascript" src="https://<path>/twilio.min.js">
<script type="text/javascript">
const token = "my-jwt-token";
const options = {
"debug": true,
"warnings": true,
"logLevel": 1,
"region": '<default>'
};
let device = new Twilio.Device(token, options);
await navigator.mediaDevices.getUserMedia({ audio: true });
device.audio.availableOutputDevices.forEach(function (device, id) {
console.log('device.label: ', device.label); // I can see devices listed
});
device.on('incoming', function(call) {
console.log('New incoming: ', call);
});
device.on('error', function(error) {
console.log('Error: ', error);
});
device.on('registered', function() {
console.log('Device registered');
});
device.on('ready', function (device) {
console.log('Twilio Device Ready: ', device);
});
device.register();
// I am able to hear sound playing in the browser
// For both of these tests
device.audio.ringtoneDevices.test();
device.audio.speakerDevices.test();
</script>
I am getting below errors:
ERROR #1:
code: 31009
message: "No transport available to send or receive messages"
ERROR #2:
code: 31204
message: "JWT token is missing in request."
I have verified the JWT token and it is valid, it does work in other Twilio SDK without any issue.
Version of Twilio JavaScript SDK: 1.9.1
Browser: Google Chrome Version 105.0.5195.125
Do we require to call device.register()
?
If I don't call device.register()
I don't get errors and I see event ready
is called.
But in any case I don't get incoming call event.