Preview Webrtc Tutorial
Total Page:16
File Type:pdf, Size:1020Kb
WebRTC About the Tutorial With Web Real-Time Communication (WebRTC), modern web applications can easily stream audio and video content to millions of people. In this tutorial, we would explain how you can use WebRTC to set up peer-to-peer connections to other web browsers quickly and easily. Audience This tutorial is going to help all those developers who would like to learn how to build applications such as real-time advertising, multiplayer games, live broadcasting, e-learning, to name a few, where the action takes place in real time. Prerequisites WebRTC is a powerful tool that can be used to infuse Real-Time Communications (RTC) capabilities into browsers and mobile applications. This tutorial covers only the basics of WebRTC and any regular developer with some level of exposure to real-time session management can easily grasp the concepts discussed here. Disclaimer & Copyright © Copyright 2015 by Tutorials Point (I) Pvt. Ltd. All the content and graphics published in this e-book are the property of Tutorials Point (I) Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute, or republish any contents or a part of contents of this e-book in any manner without written consent of the publisher. We strive to update the contents of our website and tutorials as timely and as precisely as possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt. Ltd. provides no guarantee regarding the accuracy, timeliness, or completeness of our website or its contents including this tutorial. If you discover any errors on our website or in this tutorial, please notify us at [email protected] i WebRTC Table of Contents About the Tutorial ............................................................................................................................................. i Audience ........................................................................................................................................................... i Prerequisites ..................................................................................................................................................... i Disclaimer & Copyright ...................................................................................................................................... i Table of Contents ............................................................................................................................................. ii 1. WEB RTC – OVERVIEW ................................................................................................................... 1 Basic Scheme .................................................................................................................................................... 1 Browser Compatibility ...................................................................................................................................... 2 Use Cases ......................................................................................................................................................... 4 2. WEBRTC – ARCHITECTURE ............................................................................................................. 6 MediaStream API ............................................................................................................................................. 9 3. WEBRTC – ENVIRONMENT .......................................................................................................... 12 WebRTC Protocols ...........................................................................................................................................14 The Session Description Protocol ....................................................................................................................16 Finding a Route ...............................................................................................................................................20 STUN ...............................................................................................................................................................21 TURN ...............................................................................................................................................................22 ICE ...................................................................................................................................................................24 Stream Control Transmission Protocol ............................................................................................................24 4. WEBRTC – MEDIASTREAM APIS ................................................................................................... 26 Using the MediaStream API .............................................................................................................................26 MediaStream API ............................................................................................................................................28 ii WebRTC 5. WEBRTC – RTCPEERCONNECTION APIS ....................................................................................... 34 RTCPeerConnection API ...................................................................................................................................34 Establishing a Connection ................................................................................................................................38 6. WEBRTC – RTCDATACHANNEL APIS ............................................................................................. 45 RTCDataChannel API .......................................................................................................................................45 7. SENDING MESSAGES .................................................................................................................... 47 8. WEBRTC – SIGNALING ................................................................................................................. 54 Signaling and Negotiation ...............................................................................................................................54 Building the Server ..........................................................................................................................................54 User Registration .............................................................................................................................................57 Making a Call ...................................................................................................................................................60 Answering .......................................................................................................................................................60 ICE Candidates .................................................................................................................................................61 Leaving the Connection ...................................................................................................................................62 Complete Signaling Server ...............................................................................................................................63 9. WEBRTC – BROWSER SUPPORT ................................................................................................... 68 Browser Support .............................................................................................................................................68 10. WEBRTC – MOBILE SUPPORT ....................................................................................................... 70 Android ...........................................................................................................................................................70 iOS ...................................................................................................................................................................71 Windows Phones .............................................................................................................................................71 Blackberry .......................................................................................................................................................71 Using a WebRTC Native Browser .....................................................................................................................71 Using WebRTC via Browser Applications .........................................................................................................71 Native Mobile Applications .............................................................................................................................72 iii WebRTC Constraining Video Stream for Mobile and Desktop Devices ...........................................................................72 11. WEBRTC – VIDEO DEMO .............................................................................................................. 76 Signaling Server ...............................................................................................................................................77 Client Application ............................................................................................................................................87 12. WEBRTC