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,
})