Search code examples
javascriptwebrtc

How to create multi party webrtc connections, just for dataChannels?


I just want to share light weight data between mesh of rtc peers. But not able to figure out programmatically how I can create a mesh network and create multiple dataChannels.


Solution

  • You need to create a new peerconnection on each user for each new user that you get. Then you will have to create data channels for each peer connection.
    EX. peers A B C

    • peer A has two RTCPeerConnection one to C and one to B
    • peer B has two RTCPeerConnection one to A and one to C
    • peer C has two RTCPeerConnection one to A and one to B

    ps. EACH of these CONNECTIONS have a data channel.

    Alternative: A->B->C->A you connect them in a chain, which is computationally better, but it is harder to manage messages and destinations