twiliotwilio-video

How can I make sure the Twilio Video dataTrack message gets sent and recieved?


I have a simple dataTrack for twilio-video

let dataTrack = new LocalDataTrack()
const tracks = track.concat(dataTrack)
room = await connectToRoom(roomConnectId, tracks)

....

function closeRoom() {
    dataTrack.send(JSON.stringify('disconnected'))
}

How can I make sure this message is sent and recieved? Can I wrap it in a loop that keeps trying until it works? Are there any other options I can add to it to make it work?

I need the receiver to get this message 100%. Is that possible?


Solution

  • The DataTrack API uses WebRTC data channels which cannot 100% guarantee delivery. From the docs on configuring DataTrack reliability:

    DataTracks are intended for low-latency communication between Participants. Importantly, to optimize for lowest latency possible, delivery of DataTrack messages is not guaranteed. You can think of them more like UDP messages, rather than TCP.

    However there are some extra reliability features with the Twilio Video DataTrack.

    You can set two parameters for the DataTrack API:

    Check out more on using these parameters in the Twilio Video DataTrack documentation.