webrtc权威指南 第2版
ACKNOWLEDGMENTS We would like to thank our technical reviewers Alex Agranovsky, Carol Davids, Emil Ivov, David Kemp, Henry Sinnreich, Harvey Waxman, and Dan york. We would also like to thank marina burnett and chris Comfort for their proofreading and comments. We would also like to thank our families for their encouragement and support And finally we would like to acknowledge our colleagues in W3C and the ietf who are working incredibly hard at creating the webrto andards PREFACE WebrtC continues to evolve and grow in the handful of months since we published the first edition of webrTC: APIs and Protocols of the HTML5 Real-Time Web There has been real progress in many areas in the IEtf and w3c standards, although much work remains. Eventing, stream representation at the protocol level, and even the syntax for some callbacks are all still very much under discussion, while details such as how multiple video tracks within a single MediaStream work and what should happen when a media Stream attached to an html element has tracks added or removed are only now beginning to be considered. Nevertheless, the core APls are firming up. On the usage side, conferences, meetups, and startups have sprung up and are growing rapidly in size, with the world seeking to understand WebRTC's impact and opportunities Other trends have become clear as well. The disagreement about codecs, especially video codecs is escalating from a fight to a war, to Mutually assured Patent Destruction. The authors sincerely hope that the standards and industry come to agreement quickly on the mandatory to implement video codec very soon While the basic parts of WebrtC are working well in demos and applications today, many of the concerns and issues with WebrtC revolve around security and the signaling channel, which have complete new chapters in this second edition. Additionally, the sample code out there on the Web today is often either too complex or insufficiently explained, motivating the complete running and completely explained example in this new edition. This demo code, running on both Chrome andfirefoxisalsoonourwebsiteathttp://demo.webrtcbook.com Note that all code and lists will look best with the smallest font size of your device We hope that this new updated edition keeps you excited and informed about WebrTC. Happy reading PREFACE TO THE FIRST EDITION The Internet and the world wide web have changed our world. when the history of this period is written, much will be said about the impact of these technologies on life in the late 20th and early 2lst centuries. The web has changed the way we receive information, interact with others work, and play. Now, the web is about to dramatically change the way we communicate using voice and video. This book gives an up-to-the minute snapshot of the standards and industry effort known as WebrTC which is short for Web Real-Time Communications. This technology, along with other advances in hTML5 browsers, has the potential to revolutionize the way we all communicate, in both personal and business spheres The authors have been involved in the internet communications industry for many years, and have seen the advances and impact of the Internet on voice and video communications. We have worked on signaling protocols such as Session Initiation Protocol(SIP), Session Description Protocol (SDP), and security protocols such as ZRTP for voice and video communication systems that will form the basis of what will inevitably replace the telephone system(called the Public Switched Telephone Network or PStN). These Internet Communications technologies have brought an amazing wave of disruption, but we believe WebrtC has the potential to create even greater disruption This book provides information for web developers and telephony developers who want to catch this new wave while it is still building The standards and protocols needed for Webrtc are still being developed and invented. Browsers are starting to support WebRTC functionality, little by little. However, the authors have seen the need for a book to explain this still-developing technology. This book will explain the technical goals, architectures, protocols, and Application Programming Interfaces (APIs) of WebRTC. In a publishing experiment, we plan to produce frequent editions of this book, perhaps as often as three per year, and focus on digital delivery and on-demand publishing to keep costs down and for maximum hyper linking usefulness. For information on the latest edition and for a list of updates andchangesvisithttp://webrtcbook.com This book begins with an introduction to WebRtC and discusses what is new about it. The unique aspects of Webrtc peer-to-peer media flows are explored, and Network Address Translation ( NAT traversal explained. We then discuss the working documents and finalized documents that together comprise the WebrtC standards-in progress in both the World wide Web Consortium(W3C)and the Internet Engineering Task Force (IETF). Each chapter ends with a references section, listing the various standards documents. References of the form RFC... are IEtF Request For Comments documents References of the form [draft-. are IETF Internet-Drafts, working documents, whose content may have been updated or changed since the publication of this book. The hyperlinks provided will, in most cases retrieve the most recent version of the document References to w3C drafts include a link to the latest public working draft, and also a link to le latest editors draft. For those of you unfamiliar with the standardization processes of w3C and the IETF, we have provided a reference in Appendices a and b. Finally, we discuss the current state of deployment in popular browsers If you are a web developer, welcome to the world of Internet Communications! Your users will greatly enjoy the ability to interact with each other using your application's real-time voice and video capabilities. To understand our descriptions of APIs, you will need a working knowledge of HTML and JavaScript, and some experience in web applications. See appendix d for some useful references for this If you are a voip or telephony developer, welcome to the web world Your users will enjoy the capabilities of high quality audio and video communication, and rich, web-powered user interfaces. To understand our descriptions of the on-the-wire protocols for transporting voice, video, and data, you will need a basic understanding of the Internet Knowledge of another Internet Communication signaling protocol such as siP or Jingle is also useful. See Appendix d for some additional useful reference reading. In many ways, WebrtC is a merging of worlds between the web and telephony. To help bridge the gap between the web and telephony world, we have also included a Glossary in Appendix c to briefly explain some common terms and concepts from each world The authors look forward to participating in the next wave of disruption and innovation that webrtc will likely unleash We would love to hear from you and interact with you on Twitter (@alanbjohnston @danielcburnett) on Google+ (alanbjohnston@gmail.comanddanielcburnett(@gmail.com) 1 INTRODUCTION TO WEB REAL-TIME COMMUNICATIONS Web Real-Time Communications (RTC), or WebRTC, adds new functionality to the web browser. For the first time browsers will interact directly with other browsers, resulting in a number of architectures including a triangle and trapezoid model. The media capabilities of WebrTC are state-of-the-art, with many new features The underlying standards of WebrtC are being developed by the World Wide Web Consortium(W3C) and the Internet Engineering Task Force (IETF) 1.1 Webrtc Introduction Webrtc is an industry and standards effort to put real-time communications capabilities into all browsers and make these capabilities accessible to web developers via standard [html5 tags and JavaScript APIs(Application Programming Interfaces ). For example consider functionality similar to that offered by SkypeTM [SKYPe] but without having to install any software or plug-ins. For a website or web application to work regardless of which browser is used, standards are required. Also, standards are required so that browsers can communicate with non-browsers, including enterprise and service provider telephony and communications equipment l.l.I The Web Browsing Model The basic model of web applications is shown in Figure 1. 1. Transport of information between the browser and the web server is provided by the Hyper-text Transport Protocol Http(seCtion 6.2.1). which runs over Transmission Control Protocol, TCP(Section 6.29), or in some new implementations, over the Web Socket protocol(see Section 6.2.2) The content or application is carried in Hyper-Text Markup Language HTML, which typically includes JavaScript and Cascading Style Sheets Css. In the simple case the browser sends an Http request to the web server for content, and the web server sends a response containing the document or image or other information requested. In the more complex case, the server sends JavaScript which runs on the browser interacting with the browser through APIs and with the user through clicks and selects. The browser exchanges information with the server throughanopenhttporwebsocketschannel WebRTC: APis and rTCWeb protocols of the real-Time Web Web server Transport Content Hyper-textTransportProtocol(http) Hyper-Text Markup Language over Transmission Control Protocol (TCP) (HTML) which includes Java Script or WebSockets over TCP and Cascading Style Sheets(CSS) Web browser Figure 1.1 Web browser model In figures in this book, we will show an arrow between the web browser and the web server to indicate the web session between them Since WebrtC can utilize any web transport, the details of this connectionandwhetheritishttporWebsocketsisnotdiscussed 1.1.2 The real-Time Communication function in the browser Figure 1.2 shows the browser model and the role of the real-time communication function. The lighter block called "Browser RTC Function? is the focus of this book. The unique nature and requirements of real-time communications means that adding and standardizing this block is non-trivial. The rtc function interacts with the web application using standard APIs. It communicates with the Operating System using the browser. A new aspect of Webrtc is the interaction that occurs browser-to-browser known as a " Peer Connection,, where the Rtc Function in one browser communicates using on-the-wire standard protocols (not Http) wIth the Rtc Function in another browser or Voice over IP (VolP)or video application. While web traffic uses TCP for transport, the on-the-wire protocol between browsers can use other transport protocols such as User Datagram Protocol, UDP. Also new is the Signaling Server, which provides the signaling channel between the browser and the other end of the peer connection I Introduction to Webrtc Web Signaling Server Server Http or Websockets Http or Websockets (Signaling) Java Script/HTML/CSS Other APis RTC APIs Web Browser On-the-wire protocols Browser Function Media or Data Native os services Figure 1.2 Real-Time Communication in the Browser 1. 1.3 Elements of a WebRTC System Figure 1.3 shows a typical set of elements in a WebrTC system. This includes web servers browsers running various operating systems on various devices including desktop PCs, tablets, and mobile phones, and other servers. Additional elements include gateways to the Public Switched Telephone Network(PSTN) and other Internet communication endpoints such as Session Initiation Protocol (SIP)phones and clients or Jingle clients. WebrTC enables communication among all these devices. The figures in this book will use these icons and elements as examples WebRTC: APis and rTCWeb protocols of the real-Time Web Other Servers Web servers PSTN Internet Browser M on Mobile Jingle Client 国罐 Browser L on Laptop sIP Client Browser t on Tablet Browser D Figure 1.3 Elements in a WebRTC Environment 1. 1. 4 The WebrtC triangle Initially, the most common scenario is likely to be where both browsers are running the same WebrtC web application, downloaded from the same webpage. This produces the WebrtC"Triangle?"shown in Figure 1. 4. This arrangement is called a triangle due to the shape of the signaling(sides of triangle) and media or data flows(base of triangle between the three elements. A Peer Connection establishes the transport for voice and video media and data channel flows directly between the browsers