Web RTC Peer Discovery

2.9k views Asked by At

So I am trying to develop a web application that has the capability to make video calls between users of the web application. Theoretically, Caller A can look in a directory in the web application, see that Caller B is online and make a video call. My question is how do you get the IP and port number of Caller B? I realize that this information needs to be exchanged via signaling but how does Caller A ever get their information to Caller B if they don't know what Caller B's IP or port number are?

2

There are 2 answers

6
deceze On BEST ANSWER

The peers discover each other through the ICE protocol. This is part of the normal WebRTC connection establishment. ICE has methods to discover the necessary information like IPs and ports.

What you need to worry about is getting the ICE candidates from one peer to the other. You do this via your signalling server. Peer A is discovering ICE candidates and will surface them to you on the RTCPeerConnection object; you take those candidates, send them to your server, the server sends them to peer B, where they must be incorporated into peer B's RTCPeerConnection; and the whole thing in reverse as well. Once enough ICE candidates have been exchanged and a matching possibility has been discovered, the two peers will establish a direct connection.

The implementation of the signalling server is left up to you and your particular needs.

1
bpulito On

I agree with the comment above that ICE is critical here to exchange the media streams but I'm assuming you are asking this question from a signaling point of view.

One solution for this is a simple presence capability built on MQTT and a feature called retained messages. Basically, every client publishes a document to an MQTT topic in the form of a retained message that subscribers get. Retained messages stay on the broker until they are cleared by the client or when the client disconnects from the broker (using an MQTT Last Will and Testament message). The retained message contains information that can be used to connect to other peers (e.g. peer topic names). You can see a demo of it here: https://angular-rtcomm.wasdev.developer.ibm.com.

This is all implemented in open source. If you want to get a quick demo off the ground you can do it using Node.js with the Mosca MQTT broker and the Rtcomm open source. Takes about 20 mins to set up if you're familiar with Node. Instructions can be found at the link above.