https://webrtc.github.io/samples/
https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API
- CLIENT1 creates RTCPeerConnection
const rtcPeerConnection = new RTCPeerConnection({
'iceServers': [
{
'urls': [
'stun:stun.l.google.com:19302',
'stun:stun.xten.com'
]
}
]
});
- Someone must getUserMedia() - CLIENT1/Init/Caller/Offerer
// [...]
if (navigator.mediaDevices.getUserMedia) {
// const stream = await navigator.mediaDevices.getUserMedia(constraints);
navigator.mediaDevices.getUserMedia(constraints)
.then((stream) => {
localVideo.srcObject = stream;
stream.getTracks().forEach(track => {
rtcPeerConnection.addTrack(track, stream);
});
})
.catch((error) => {
console.error(error);
});
}
- peerConnection needs STUN servers
- we will need ICE candidates later
- CLIENT1 add localstream tracks to peerConnection
- we need to associate CLIENT1 feed with peerConnection
- CLIENT1 creates an offer
- needed peerConnection with tracks
- offer = RTCSessionDescription
- SDP - codec/resolution information
- Type (offer)
- CLIENT1 hands offer to pc.setLocalDescription
- ICE candidates can now start coming in (ASYNC) SIGNALING (someone to help the browser find/talk to each)
- CLIENT1 emits offer
- socket.io server holds it for the other browser
- associate with CLIENT1 ~9. Once 7 happens, emit ICE c. up to signaling server
- socket.io server holds it for the other browser
- associate with CLIENT1 CLIENT1 and Signaling server wait.
- wait for an answerer/CLIENT2/reciever
- CLIENT2 loads up the webpage with io.connect()
- a new client is connected to signaling/socket.io server
- socket.io emit out the RTCSessionDesc to the new client
- an offer to be sent!
- CLIENT2 runs getUserMedia()
- CLIENT2 creates a peerConnection()
- pass STUN servers
- CLIENT2 adds localstream tracks to peerconnection
- CLIENT2 creates an answer (createAnswer());
- createAnswer = RTCSessionDescription (sdp/type)
- CLIENT2 hands answer to pc.setLocalDescription
- Because CLIENT2 has the offer, CLIENT2 can hand the offer to pc.setRemoteDescription ~18. when setLocalDescription, start collecting ICE candidates (ASYNC) Signaling server has been waiting...
- CLIENT2 emit answer (RTCSessionDesc - sdp/type) up to signaling server
~20. CLIENT2 will listen for tracks/ICE from remote.
- and is done.
- waiting on ICE candidates
- waiting on tracks
- signaling server listens for answer, emits CLIENT1 answer (RTCSessionDesc - sdp/type)
- CLIENT1 takes the answer and hands it to pc.setRemoteDesc ~23. CLIENT1 waits for ICE candidates and tracks
21 & 23 are waiting for ICE. Once ICE is exchanged, tracks will exchange
docker run -d --network=host -v $(pwd)/turnserver.conf:/etc/coturn/turnserver.conf coturn/coturn
listening-port=3478
tls-listening-port=5349
fingerprint
lt-cred-mech
user=user1:pass1
syslog