Fix browser phone Twilio SDK v2 API compatibility issues
- Update makeCall function to use async/await with new SDK - Wrap connect params in {params: params} object as required by SDK v2 - Make setupTwilioDevice async and await device.register() - Add proper error handling for Promise-based API calls 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -102,7 +102,7 @@
|
||||
/**
|
||||
* Setup Twilio Device
|
||||
*/
|
||||
function setupTwilioDevice(token) {
|
||||
async function setupTwilioDevice(token) {
|
||||
// Check if Twilio SDK is loaded
|
||||
if (typeof Twilio === 'undefined' || !Twilio.Device) {
|
||||
updateStatus('offline', 'Twilio SDK not loaded');
|
||||
@@ -138,7 +138,8 @@
|
||||
isConnected = false;
|
||||
});
|
||||
|
||||
twilioDevice.register();
|
||||
// Register device asynchronously
|
||||
await twilioDevice.register();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to setup Twilio Device:', error);
|
||||
@@ -287,7 +288,7 @@
|
||||
/**
|
||||
* Make outbound call
|
||||
*/
|
||||
function makeCall(number, callerId) {
|
||||
async function makeCall(number, callerId) {
|
||||
if (currentCall) {
|
||||
showMessage('Already in a call', 'error');
|
||||
return;
|
||||
@@ -302,8 +303,10 @@
|
||||
};
|
||||
|
||||
try {
|
||||
currentCall = twilioDevice.connect(params);
|
||||
console.log('Making call with params:', params);
|
||||
currentCall = await twilioDevice.connect({params: params});
|
||||
|
||||
// Setup call event handlers
|
||||
currentCall.on('accept', function() {
|
||||
updateCallState('connected');
|
||||
showCallInfo('Connected');
|
||||
|
Reference in New Issue
Block a user