2
votes

I want to catch the accept event when calling a number using the twilio client javascript. The 'connection' event of the device is fired as I want for incoming calls. But the connection event for outgoing calls(created by call function) is fired immediately after created. I want to show if the receiver has accepted a call or not.

-- Server code --

const twiml = new Twilio.twiml.VoiceResponse()

twiml
  .dial({
    answerOnBridge: true,
    callerId: phoneNumber.number,
    record: 'record-from-answer',
  })
  .number(
    {
      statusCallback: apiUrl(
        `twilio-client/callback?smsContactId=${smsContact.id}&agentId=${agent.id}`
      ),
    },
    lead.phone
  )

-- Client code --

this.device = new Twilio.Device(token, {
    codecPreferences: ['opus', 'pcmu'],
    fakeLocalDTMF: true,
    enableIceRestart: true,
    enableRingingState: true,
  })
1

1 Answers

0
votes

Twilio developer evangelist here.

I believe this is the default behaviour, but you can change that by setting the enableRingingState flag when you setup the device.

With that flag, the connection will start by emitting a ringing event. Then, when the call connection changes to "open" it will fire the accept event.

Let me know if that helps at all.