19
votes

I have successfully connected clients A and B. Problem is I want to add new clients, C and D to build a group chat. Do I need to spawn new RTC connection and exchange offer/answer/ICE candidates for each clients? For example:

A connects to B A connects to C A connects to D B connects to C B connects to D C connects to D

Each of the above client combination spawns their own RTCPeerConnection and goes through the webrtc handshake (offer,icecandidate,answer)

1
Do you have some code? Is very hard to find an example where C can join A and B. - Leopoldo Sanczyk

1 Answers

14
votes

Do I need to spawn new RTC connection and exchange offer/answer/ICE candidates for each clients?

Exactly. Each client just need to create new RTCPeerConnection, attach their unique audio and video tracks to them and exchange their SDP & ICE candidates every time a new client arrives.

An example is available here: https://webrtc.github.io/samples/src/content/peerconnection/multiple/

Source code: https://github.com/webrtc/samples/blob/gh-pages/src/content/peerconnection/multiple/js/main.js