RTCMultiConnection
RTCMultiConnection copied to clipboard
recursion loop when sending to only one peer
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 :
- Get two (or more) peers connected through webrtc using this library. Make any message received log.
- From one of the peers, write
connection.send("Something", connection.getAllParticipants()[0])
. - Wait and see that noting appears in the console.
- Your browser slows down, and a "too much recursion" error pops up.
Thanks in advance to anyone willing to help!