Search code examples
twiliotwilio-click-to-call

Twilio SDK JS, is possible to get status of participant on conference/phone?


I'm trying to get events on specific participants on the client side when they get put on hold. I can set the participant on hold on the backend via REST API, but I wonder how I can get the events of the call or participant when it changes to hold/unhold?


Solution

  • The Twilio Voice JavaScript SDK allows you to make voice calls from the browser, but it will not emit events like when someone is put on hold.

    However there are techniques to achieve your goal:

    • You could create a WebSocket (bidirectional connection) from your web client to your backend, and when you put someone on hold, send an event with the details over the WebSocket. When your web client receives your event, it can update its UI.
    • You could use Twilio Sync to share and update state in real-time between your web client and your backend. When you put someone on hold, you can update the state on the server, and the web client can receive this update so you can update your UI. There are also other real-time database/services you could use.
    • You could persist state about your call in your backend and request the data from your web client every couple of seconds. When the data changes, the web client can update its UI. This is not ideal as it sends many unnecessary HTTP requests, but it works.

    I recommend the first two solutions, but would avoid the 3rd which I am including for completeness. This sounds like an interesting project, good luck!