1

I'm trying to use Twilio to connect workers through a kind of Walkie Talkie (all the workers get a JWT to make browser calls using the Javascript SDK), for this I use the Twiml verb conference, when the worker press the conference button in the browser it sends a list of the active workers (except for the one who started the conference), I use the callSid as the name of the conference to make it unique and the CallResource to put every worker into the conference.

However, the workers in the list start listening the wait music for a conference room, but the caller automatically end the connection as soon as it is open, it doesn't even ends the conference, I don't know what's wrong with the code, I'm following the documentation for conferences in https://www.twilio.com/docs/voice/twiml/conference

Here is the method that's called when a conference needs to be created:

public VoiceResponse ConferenceTalk(List<string> recipients, string caller, string callSid)
{
    TwilioClient.Init(my_account_sid, my_auth_token);
    var confName = $"wt_{callSid}";

    foreach (var recipient in recipients)
    {
        CallResource.Create(
            url: new Uri($"{this.publicUrl}/Conference/WtConference/{confName}"),
            to: new Twilio.Types.Client($"client:{recipient}"),
            from: new Twilio.Types.Client(caller));
    }

    var response = new VoiceResponse();

    var dial = new Dial();
    dial.Conference(confName,
        startConferenceOnEnter: true,
        endConferenceOnExit: true);

    response.Append(dial);

    return response;
}

Here is the endpoint the CallResource target with the url attribute:

[HttpPost]
public TwiMLResult WtConference()
{
    var confName = Request.Url.Segments[Request.Url.Segments.Length - 1];
    var response = new VoiceResponse();
    var dial = new Dial();
    dial.Conference(confName);
    response.Append(dial);
    return TwiML(response);
}
Josef
  • 2,869
  • 2
  • 22
  • 23

1 Answers1

0

I feel like the time all of this takes to happen might be causing your issues here. And the Twilio Voice SDK may not be the best product for this. I'd have to see maybe a video showing how the interaction works to fully commit to this.

In the meantime, I might try to speed up people joining the conference by sending the TwiML for the conference in the API call, not waiting for the webhook. e.g.:

        public VoiceResponse ConferenceTalk(List<string> recipients, string caller, string callSid)
        {
            TwilioClient.Init(my_account_sid, my_auth_token);
            var confName = $"wt_{callSid}";

            var outboundResponse = new VoiceResponse();
            var outboundDial = new Dial();
            outboundDial.Conference(confName);
            outboundResponse.Append(outboudDial);

            foreach (var recipient in recipients)
            {
                CallResource.Create(
                    twiml outboundResponse,
                    to: new Twilio.Types.Client($"client:{recipient}"),
                    from: new Twilio.Types.Client(caller));
            }

            var response = new VoiceResponse();

            var dial = new Dial();
            dial.Conference(confName,
                startConferenceOnEnter: true,
                endConferenceOnExit: true);

            response.Append(dial);

            return response;
        }

I say that Twilio Voice might not be best for this because on the Twilio back end, this is going through a whole stack that is built for making phone calls. Outbound calls are made at a rate of 1 call per second, so that might be slowing the calling of your list down.

You could consider the Twilio Video SDK for this instead (you can make audio only calls with the Twilio Video product). For this you would need to be able to trigger each of workers joining a room that was then used to distribute the audio. There aren't limits on calls per second, workers would just need to connect to a room and your application would be able to control who could talk at any one time.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Thanks for the answer, I took a look and the Twilio Video SDK was a nice solution, just a little bit more of work since the feature require that the call ended as soon as the caller wanted to stop (like a real walkie talkie). – William Herrera Mar 31 '22 at 23:47
  • Fair enough. I'd probably implement that by listening for the `participantDisconnected` event for the originating participant and then disconnecting from the room when that happens. But that will happen more automatically in the Voice SDK too. – philnash Mar 31 '22 at 23:49