1

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?

MomasVII
  • 4,641
  • 5
  • 35
  • 52

1 Answers1

2

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:

  • maxPacketLifeTime - the time in milliseconds during which the DataTrack will transmit or retransmit a message until that message is acknowledged
  • maxRetransmits - the maximum number of retransmit attempts that will be made.

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

philnash
  • 70,667
  • 10
  • 60
  • 88
  • But essentially the answer is you cannot make it 100% right? – MomasVII May 23 '22 at 00:48
  • 1
    That is correct. With WebRTC there is no guarantee that every packet that is sent from one peer will definitely arrive at the other peer. Twilio Video adds the reliability features described above, but nothing can be 100% guaranteed. – philnash May 23 '22 at 00:49
  • Where should I put these parameters? Can you give us an example? – SMahdiS Oct 13 '22 at 08:17