RTCMultiConnection icon indicating copy to clipboard operation
RTCMultiConnection copied to clipboard

recursion loop when sending to only one peer

Open JustYanns opened this issue 2 years ago • 0 comments

Hi!

I'm having troubles sending data to only one of the connected peers. After digging a bit in the code, I found out you could do that simply by writing connection.send(message, peerId). The problem is that this seems poorly implemented, resulting into a loop and a "too much recursion" error after a while.

From what I found out, when function connection.send executes connection.peers.send whose definition is attached. Because the data type isn't defined, TextSender.send is called, which loops back to connection.peers.send (in yellow) The data type is defined through TextSender.send, now the problem comes from remoteUser.channels.length (in pink) that is equal to zero. So a data channel is created and the connection is negociated again (still in pinkish). Then a timeout is set, which calls connection.peers.send once again ! (in green)

There we go, remoteUser.channels.length is still equal to zero, even after the pink part, so the function loops again, again, until the error is thrown.

I'm wondering if someone could dig deeper and maybe create a pull request, cause I don't really see how to fix this.

Step to reproduce :

  1. Get two (or more) peers connected through webrtc using this library. Make any message received log.
  2. From one of the peers, write connection.send("Something", connection.getAllParticipants()[0]).
  3. Wait and see that noting appears in the console.
  4. Your browser slows down, and a "too much recursion" error pops up. sreenshot

Thanks in advance to anyone willing to help!

JustYanns avatar Aug 08 '21 16:08 JustYanns