This is a known problem. Magic doe snot exist. mediasoup cannot buffer all data that receivers must receive.
- Alice and Bob join the same mediasoup
Router
. - Alice create a WebRTC reliable
DataProducer
and Bob consumes its data by creating a WebRTC reliableDataConsumer
. - Alice sends ton of data. Bob has poor downlink quality.
- Eventually mediasoup (the SCTP stack) cannot send that many messages to Bob and its sending buffer gets filled so some messages are lost.
Workaround (the bad way)
Set a higher sctpSendBufferSize
: mediasoup :: API
Proper solution
- Create a
DirectTransport
in mediasoup and create aDataConsumer
on it to consume from Alices WebRTC
DataProducer`. - Create another
DirectTransport
and a fakeDataProducer
on it both associated to Bob (such a fakeDataProducer
is required due the design of producers and consumers). - Make the WebRTC
DataConsumer
of Bob consume from such aDataProducer
instead of consuming from the original WebRTCDataProducer
. - When a message is received in mediasoup by Alice’s direct
DataConsumer
, take the message and calldataConsumer.send(message or whatever)
in the WebRTCDataConsumer
of Bob.
And here the thing:
- You must check the async result of
dataConsumer.send()
(see the API) and you must properly use thedataConsumer.getBufferedAmount()
method and thedataConsumer.on(“bufferedamountlow”)
event and buffer the messages in Node land (within your app) is needed, so if there is a memory leak it will be a failure in your Node app rather than in mediasoup.
PS: I know this is complex and that’s why this is gonna change in mediasoup v4 eventually, but unfortunately I cannot give more tips about this solution. Hope it helps.