I'm building a web app for cam broadcasting. I'm using Django for web app and coturn as (STUN/TURN) signalling server. My goal is to do it with WebRTC.
I don't know how to connect a peer to the signalling server in order to be reachable by other peer. So what I need to know is how to stablish "PeerConnection".
In web application, I have all I need (I think): user.id, shared secret, signalling server IP and port, ... But I don't know how to mix it in HTML JS scripts to connect with coturn server.
I've read coturn server docs and searched for some examples but can't find examples for this part.
Can anybody show me an a example?
I think you are bit confused, coturn
is not a signalling server, it is a TURN/ STUN server.
Signalling server is something though which you exchange sdp, ice candidates and other data between the peers before they get a direct peer to peer connection, coturn
does not do that.
I cannot explain all the bits, but gist is STUN is used for providing public IP of a peer, and TURN is used for a proxy point for transmitting and receving data from a peer when it cannot be directly accessed, and in most cases all you require is a STUN server. The only time they get involved in your WebRTC application is when you create the PeerConnection
object, you pass the STUN/TURN server details in the config object, example:
let pc = new RTCPeerConnection({
"iceServers": [
{"urls": "stun:example.com"}, // STUN Server address
{"urls": "turn:example.com", "credential": "test", "username": "test"} // TURN Server address
]
});
So as I understand I will not need to use coturn, just one signalling server like SignalMaster or any other like it. Am I wrong?
You still might need coTurn or any other STUN/TURN server to achieve peer-to-peer or relay connection when host-host connection is not possible. STUN/TURN is required for ICE to have server-reflexive and relayed candidates to perform ICE and guarantee the connectivity.
WebRTC works as offer-answer model, so you need some kind of signalling method like SIP/Jingle or another signalling mechanism to exchange the SDP between two party. You may use some third party solution above of WebRTC implementation or you can write your own simple signalling stack.