2

I'm trying to develop a WEBRTC videochat on a website. I've already create my database with users and their unique ID but I'm a little confused to how I can use this ID to connect clients with PeerConnection. I've already read this http://www.html5rocks.com/en/tutorials/webrtc/basics/ and other documentation but I'm not understanding if i can use users' Id in some way in the remote/local description or I have to use other solutions like PeerJs?

Thanks.

Marco
  • 23
  • 1
  • 7

2 Answers2

1

You need to set up signalling yourself. That means, you will need to provide a means for exchanging messages between both users. Just having an id doesn't help anyone in establishing a connection. Both users need to be able to send a message to your server and the server needs to relay that message to the other user they're trying to connect to. You'll probably use the ids in some ways to decide whom to relay to exactly; but that's a secondary implementation detail.

In practice a web socket connection between each user and your server works well. User A sends a message via web socket to your server, your server passes this message on to user B via web socket; repeat that a couple of times until a direct connection has been negotiated.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • Thanks. And User A using remote/local description how can it find the User B? https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection I may use the IPs in this description ? – Marco Apr 13 '15 at 11:41
  • You don't need to care about IPs at all. You need to relay the SDP offers and responses and ICE candidates between both peers. As long as you're doing that, they'll sort out the rest between themselves. – deceze Apr 13 '15 at 11:51
  • Ok thanks,sorry another question, how User A Or SDP offer find the User B? have you some documentation about "calling" someone with this method? – Marco Apr 13 '15 at 11:57
  • 1
    See [this answer](http://stackoverflow.com/questions/29032884/why-signaling-server-needed-for-webrtc/29056385#29056385) about discovery. In short it depends on your context. Typically, if you have a server then that's where people meet. – jib Apr 13 '15 at 12:34
  • @Marco That's up to you. That's why you basically need a server in the middle which facilitates the initial handshake. It's your business logic which determines how one person finds another. If you have technical problems with the implementation of such logic you should open a detailed new question. – deceze Apr 13 '15 at 14:15
  • Ok, i've a server and I have ips and all parameters. But I'm not understanding how rtcpeerconnection methods or description can help me. I've to create my own logic or I can use my parameters in the protocol? – Marco Apr 14 '15 at 07:41
  • @Marco WebRTC/RTCPeerConnection is able to establish a **direct P2P connection** between two clients, for example so you can stream direct audio and video between two users without needing an expensive media streaming server in the middle, or send a large file directly P2P without taxing a server's bandwidth and resources. Only the initial handshake needs a little help from a server, because it'd otherwise be virtually impossible for two peers to find each other. – deceze Apr 14 '15 at 07:49
  • Ok I know that only the handshake need the server. But Can I use the IPs or Id etc and how? – Marco Apr 14 '15 at 07:50
  • @Marco You don't use any IPs in the RTCPeerConnection explicitly. The RTCPeerConnection generates SessionDescription offers and answers and ICE candidates, when that happens you need to send those to the other peer via your server. The ICE candidates in particular contain IP information as discovered by the peer itself, that's how the two peers will find a way to talk to each other. Whatever IP address your server knows is irrelevant, as there may be a whole 'nother way for the peers to contact each other than via that IP. – deceze Apr 14 '15 at 07:56
1

In short, WebRTC does not specify the signalling channel (it is up to the developer), ie how users discover and know about each other.

Some tutorials tend to skip the signalling entirely, which is a shame. It might be better to set up your signalling first, verify that it works using your ID method of discovery, and then add WebRTC on top of that.

jonpd
  • 306
  • 1
  • 6