WebRTC
Web Real-Time Communication
in a nutshell
WebRTC is a free, open project that provides browsers and mobile applications with Real-Time Communications (RTC) capabilities via simple APIs. The WebRTC components have been optimized to best serve this purpose.
2011
2017
- In November 2017, the WebRTC 1.0 specification transitioned from Working Draft to Candidate Recommendation.
Mission
Our mission: To enable rich, high-quality RTC applications to be developed for the browser, mobile platforms, and IoT devices, and allow them all to communicate via a common set of protocols.
Where can I use WebRTC?
Browser
- Chrome
- Firefox
- Opera
- Safari
- Android Browser
Native
- IOS
- Android
WebRTC Peer-to-peer connections
Source: caniuse.com
What can WebRTC do?
- P2P Video Streaming
- Game
- ...
Architecture
Architecture
Design
Design
- getUserMedia(): capture audio and video.
- MediaRecorder: record audio and video.
- RTCPeerConnection: stream audio and video between users.
- RTCDataChannel: stream data between users.
How does Webrtc work?
4 simple step
-
Agree to begin communication
-
Know how to locate one another
-
Bypass security and firewall protections
-
Transmit all multimedia communications in real-time
RTCPeerConnection ...
- Phet creates an RTCPeerConnection object.
- Phet creates an offer (an SDP session description) with the RTCPeerConnection createOffer() method.
- Phet calls setLocalDescription() with his offer.
-
Phet stringifies the offer and uses a signaling mechanism to send it to Luong.
- Phet calls setRemoteDescription() with Alice's offer, so that her RTCPeerConnection knows about Alice's setup.
And
- Luong calls createAnswer(), and the success callback for this is passed a local session description: Luong's answer.
- Luong sets her answer as the local description by calling setLocalDescription().
- Luong then uses the signaling mechanism to send her stringified answer back to Phet.
-
Phet sets Luong's answer as the remote session description using setRemoteDescription().
Problem!!!
- Exchange metadata to coordinate communication --> Solve by signaling.
- Cope with network address translators (NATs) and firewalls.
--> use STUN, TURN
What is signaling?
Signaling is the process of coordinating communication
What is SDP?
SDP = Session Description Protocol format
NAT
Network address translation
- 2 type of IP: IP public and IP private
-
Limit the number of public IP
- NAT cung cấp địa chỉ IP private cho mạng local còn IP public do nhà cung cấp dịch vụ cung cấp.
ICE
Interactive Connectivity Establishment
Về cơ bản là framework giúp Phet va Luong tìm ra cách ngắn nhất để thiết lập kết nội Peer-to-peer với nhau
ICE tìm cách kết nối trực tiếp bằng cách thông tin có được tư OS và network card. Nếu không được, ICE sẽ dùng đến STUN server. Nếu tiếp tục thất bại thì nó sẽ sử dụng TURN relay framework
STUN
Simple Traversal Of UDP Through NAT
Khi 1 server nào dùng NAT thì STUN sẽ giúp cho client đó biết được địa chỉ IP và Port mà thiết bị NAT sử dụng. Và từ đó giúp cho các peer có thể lấy được địa chỉ của peer khác (IP nào, cổng mấy, NAT loại gì) để mà vượt rào đến với nhau.
STUN
TURN
Traversal Using NAT Relay
Tương tự như STUN nhưng sử dung TCP là giao thức.
- Điểm cộng là kết nối TCP làm giảm package loss, đảm bảo an toàn thông tin.
- Điểm trừ là tốn băng thông.
TURN
Thank you!!
Source
- https://www.html5rocks.com/en/tutorials/webrtc/infrastructure/
- https://kipalog.com/posts/WebRTC-basic---Phan-1--Tim-hieu-ve-NAT--STUN--TURN-vs-ICE
- https://en.wikipedia.org/wiki/Interactive_Connectivity_Establishment
- https://codelabs.developers.google.com/codelabs/webrtc-web/#0
- https://viblo.asia/p/webrtc-phan-1-E375zEPdlGW
WebRTC
By nghiatv
WebRTC
Slide webRTC cho focal lab
- 51