Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WebRTC. Real-time communication for mobile devi...

WebRTC. Real-time communication for mobile devices.

Sergey Zenchenko

April 12, 2014
Tweet

More Decks by Sergey Zenchenko

Other Decks in Programming

Transcript

  1. Who am I? • Sergey Zenchenko @ Techery • [email protected]

    • http://techery.io • @sergeyzenchenko
  2. Examples of Real-time • VOIP • Instant messaging • Video

    conferencing • Real-time collaboration
  3. Tasks • Record audio from the mic • Encode audio

    • Send audio to Bob • Decode audio • Send audio to the speaker
  4. TCP • Used almost everywhere • Connection based • Reliable

    • Error detection • Flow control • Congestion control
  5. User Datagram Protocol (UDP) A self-contained, independent entity of data

    carrying sufficient information to be routed from the source to the destination nodes without reliance on earlier exchanges between the nodes and the transporting network. Datagram is:
  6. UDP good parts • Low overhead • We are not

    waiting for packet receiving acknowledgement! • Optimal for real-time
  7. UDP problems • No guarantee of message delivery • No

    guarantee of order of delivery • No connection state tracking • No congestion control
  8. Real-time Transmission Protocol • Industrial standard for real-time communication •

    Designed for stream delivery over IP network • http://en.wikipedia.org/wiki/Real-time_Transport_Protocol • http://www.ietf.org/rfc/rfc3550.txt
  9. RTP/RTCP • Works over UDP or TCP • RTCP for

    feedback and QoS • Guarantee of order of delivery • Connection state tracking • Congestion control • Can provide packet retransmission
  10. What about devices outside local network? 192.169.0.2 10.15.0.6 Router A

    Router B 193.110.176.232 88.110.56.23 Bob Alice
  11. Interactive Connectivity Establishment (ICE) ICE is a protocol, and a

    set of methods, that seek to establish the most efficient tunnel between the participants
  12. STUN • http://en.wikipedia.org/wiki/STUN • Protocol that allows the host application

    to discover the presence of a network address translator on the network and obtain the allocated public IP and port tuple for the current connection • Free to use STUN servers available in the internet Session Traversal Utilities for NAT
  13. How it works • The application discovers its public IP

    and port tuple and is then able to use this information as part of its application data when communicating with its peers. • The outbound binding request to the STUN server establishes NAT routing entries along the path, such that the inbound packets arriving at the public IP and port tuple can now find their way back to the host application on the internal network. • The STUN protocol defines a simple mechanism for keepalive pings to keep the NAT routing entries from timing out.
  14. IcE

  15. WebRTC • http://www.webrtc.org • https://www.youtube.com/watch?v=p2HzZkd2A40 WebRTC is a free, open

    project that enables web browsers with Real-Time Communications (RTC) capabilities via simple JavaScript APIs. The WebRTC components have been optimized to best serve this purpose.
  16. WebRTC features • ICE, STUN, TURN protocols implementation • Audio/Video

    codecs • Session management • RTP stack • Security
  17. WebRTC native api • http://www.webrtc.org/webrtc-native-code-package • http://www.webrtc.org/reference/native-apis • Designed for

    browser developers • Available for iOS, Android. • http://ninjanetic.com/how-to-get-started-with-webrtc- and-ios-without-wasting-10-hours-of-your-life/
  18. RTCPeerConnection • RTCPeerConnection manages the full ICE workflow for NAT

    traversal. • RTCPeerConnection sends automatic (STUN) keepalives between peers. • RTCPeerConnection keeps track of local/remote streams. • RTCPeerConnection triggers automatic stream renegotiation as required. • RTCPeerConnection provides necessary APIs to generate the connection offer, accept the answer, allows us to query the connection for its current state, and more.
  19. RTCPeerConnection Setup 1. Create peer connection 2. Create local stream

    3. Add audio/video tracks to stream 4. Add stream to peer connection
  20. m=audio 1 RTP/SAVPF 111 ... 1 a=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level a=candidate:1862263974 1

    udp 2113937151 192.168.1.73 60834 typ host ... 2 a=mid:audio a=rtpmap:111 opus/48000/2 3 a=fmtp:111 minptime=10 Session Description Protocol (SDP)