版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
WebRTC:
APIsandRTCWEBProtocolsoftheHTML5Real-TimeWeb
AlanB.JohnstonDanielC.Burnett
SecondEditionJune2013
C:
DigitalCodexLLC
ØØØ1
©Copyright2013DigitalCodexLLC
P.O.Box9131,St.Louis,MO63117,
USA
SmashwordsEdition
Allrightsreserved.
Alltrademarksarethepropertyoftheirrespectiveholders.
ISBN-13:978-0-9859788-5-3
ISBN-10:0985978856
DEDICATION
ForAidan&Nora,andCraig&Fiona
ACKNOWLEDGMENTS
WewouldliketothankourtechnicalreviewersAlexAgranovsky,CarolDavids,EmilIvov,DavidKemp,HenrySinnreich,HarveyWaxman,andDanYork.WewouldalsoliketothankMarinaBurnettandChrisComfortfortheirproofreadingandcomments.Wewouldalsoliketothankourfamiliesfortheirencouragementandsupport.
Andfinally,wewouldliketoacknowledgeourcolleaguesinW3CandtheIETFwhoareworkingincrediblyhardatcreatingtheWebRTCstandards.
iii
PREFACE
WebRTCcontinuestoevolveandgrowinthehandfulofmonthssincewepublishedthefirsteditionofWebRTC:APIsandProtocolsoftheHTML5Real-TimeWeb.
TherehasbeenrealprogressinmanyareasintheIETFandW3Cstandards,althoughmuchworkremains.Eventing,streamrepresentationattheprotocollevel,andeventhesyntaxforsomecallbacksareallstillverymuchunderdiscussion,whiledetailssuchashowmultiplevideotrackswithinasingleMediaStreamworkandwhatshouldhappenwhenaMediaStreamattachedtoanHTMLelementhastracksaddedorremovedareonlynowbeginningtobeconsidered.Nevertheless,thecoreAPIsarefirmingup.Ontheusageside,conferences,meetups,andstartupshavesprungupandaregrowingrapidlyinsize,withtheWorldseekingtounderstandWebRTC’simpactandopportunities.
Othertrendshavebecomeclearaswell.Thedisagreementaboutcodecs,especiallyvideocodecsisescalatingfromafight,toawar,toMutuallyAssuredPatentDestruction.Theauthorssincerelyhopethatthestandardsandindustrycometoagreementquicklyonthemandatorytoimplementvideocodecverysoon.
WhilethebasicpartsofWebRTCareworkingwellindemosandapplicationstoday,manyoftheconcernsandissueswithWebRTCrevolvearoundsecurityandthesignalingchannel,whichhavecompletenewchaptersinthissecondedition.Additionally,thesamplecodeoutthereontheWebtodayisofteneithertoocomplexorinsufficientlyexplained,motivatingthecompleterunningandcompletelyexplainedexampleinthisnewedition.Thisdemocode,runningonbothChromeandFirefox,isalsoonourwebsiteat
.
Notethatallcodeandlistswilllookbestwiththesmallestfontsizeofyourdevice.
WehopethatthisnewupdatededitionkeepsyouexcitedandinformedaboutWebRTC.Happyreading!
iv
PREFACETOTHEFIRSTEDITION
TheInternetandtheWorldWideWebhavechangedourworld.Whenthehistoryofthisperiodiswritten,muchwillbesaidabouttheimpactofthesetechnologiesonlifeinthelate20thandearly21stcenturies.Thewebhaschangedthewaywereceiveinformation,interactwithothers,work,andplay.Now,thewebisabouttodramaticallychangethewaywecommunicateusingvoiceandvideo.Thisbookgivesanup-to-the-minutesnapshotofthestandardsandindustryeffortknownasWebRTC,whichisshortforWebReal-TimeCommunications.Thistechnology,alongwithotheradvancesinHTML5browsers,hasthepotentialtorevolutionizethewayweallcommunicate,inbothpersonalandbusinessspheres.
TheauthorshavebeeninvolvedintheInternetCommunicationsindustryformanyyears,andhaveseentheadvancesandimpactoftheInternetonvoiceandvideocommunications.WehaveworkedonsignalingprotocolssuchasSessionInitiationProtocol(SIP),SessionDescriptionProtocol(SDP),andsecurityprotocolssuchasZRTPforvoiceandvideocommunicationsystemsthatwillformthebasisofwhatwillinevitablyreplacethetelephonesystem(calledthePublicSwitchedTelephoneNetworkorPSTN).TheseInternetCommunicationstechnologieshavebroughtanamazingwaveofdisruption,butwebelieveWebRTChasthepotentialtocreateevengreaterdisruption.
Thisbookprovidesinformationforwebdevelopersandtelephonydeveloperswhowanttocatchthisnewwavewhileitisstillbuilding.ThestandardsandprotocolsneededforWebRTCarestillbeingdevelopedandinvented.BrowsersarestartingtosupportWebRTCfunctionality,littlebylittle.However,theauthorshaveseentheneedforabooktoexplainthisstill-developingtechnology.Thisbookwillexplainthetechnicalgoals,architectures,protocols,andApplicationProgrammingInterfaces(APIs)ofWebRTC.Inapublishingexperiment,weplantoproducefrequenteditionsofthisbook,perhapsasoftenasthreeperyear,andfocusondigitaldeliveryandon-demandpublishingtokeepcostsdownandformaximumhyperlinkingusefulness.Forinformationonthelatesteditionandforalistofupdatesandchanges,visit
.
ThisbookbeginswithanintroductiontoWebRTCanddiscusseswhatisnewaboutit.TheuniqueaspectsofWebRTCpeer-to-peermediaflowsareexplored,andNetworkAddressTranslation(NAT)traversalexplained.WethendiscusstheworkingdocumentsandfinalizeddocumentsthattogethercomprisetheWebRTCstandards-in-
progressinboththeWorldWideWebConsortium(W3C)andtheInternetEngineeringTaskForce(IETF).Eachchapterendswithareferencessection,listingthevariousstandardsdocuments.Referencesoftheform[RFC…]areIETFRequestForCommentsdocuments.Referencesoftheform[draft-…]areIETFInternet-Drafts,workingdocuments,whosecontentmayhavebeenupdatedorchangedsincethepublicationofthisbook.Thehyperlinksprovidedwill,inmostcases,retrievethemostrecentversionofthedocument.ReferencestoW3Cdraftsincludealinktothelatestpublicworkingdraft,andalsoalinktothelatesteditor’sdraft.ForthoseofyouunfamiliarwiththestandardizationprocessesofW3CandtheIETF,wehaveprovidedareferenceinAppendicesAandB.Finally,wediscussthecurrentstateofdeploymentinpopularbrowsers.
Ifyouareawebdeveloper,welcometotheworldofInternetCommunications!Youruserswillgreatlyenjoytheabilitytointeractwitheachotherusingyourapplication’sreal-timevoiceandvideocapabilities.TounderstandourdescriptionsofAPIs,youwillneedaworkingknowledgeofHTMLandJavaScript,andsomeexperienceinwebapplications.SeeAppendixDforsomeusefulreferencesforthis.
IfyouareaVoIPortelephonydeveloper,welcometothewebworld!Youruserswillenjoythecapabilitiesofhighqualityaudioandvideocommunication,andrich,web-powereduserinterfaces.Tounderstandourdescriptionsoftheon-the-wireprotocolsfortransportingvoice,video,anddata,youwillneedabasicunderstandingoftheInternet.KnowledgeofanotherInternetCommunicationsignalingprotocolsuchasSIPorJingleisalsouseful.SeeAppendixDforsomeadditionalusefulreferencereading.
Inmanyways,WebRTCisamergingofworldsbetweenthewebandtelephony.Tohelpbridgethegapbetweenthewebandtelephonyworld,wehavealsoincludedaGlossaryinAppendixCtobrieflyexplainsomecommontermsandconceptsfromeachworld.
TheauthorslookforwardtoparticipatinginthenextwaveofdisruptionandinnovationthatWebRTCwilllikelyunleash.
WewouldlovetohearfromyouandinteractwithyouonTwitter(@alanbjohnstonand@danielcburnett)oronGoogle+
(alanbjohnston@
anddanielcburnett@).
vi
1INTRODUCTIONTOWEBREAL-TIMECOMMUNICATIONS
WebReal-TimeCommunications(RTC),orWebRTC,addsnewfunctionalitytothewebbrowser.Forthefirsttime,browserswillinteractdirectlywithotherbrowsers,resultinginanumberofarchitecturesincludingatriangleandtrapezoidmodel.ThemediacapabilitiesofWebRTCarestate-of-the-art,withmanynewfeatures.TheunderlyingstandardsofWebRTCarebeingdevelopedbytheWorldWideWebConsortium(W3C)andtheInternetEngineeringTaskForce(IETF).
WebRTCIntroduction
WebRTCisanindustryandstandardsefforttoputreal-timecommunicationscapabilitiesintoallbrowsersandmakethesecapabilitiesaccessibletowebdevelopersviastandard[HTML5]tagsandJavaScriptAPIs(ApplicationProgrammingInterfaces).Forexample,considerfunctionalitysimilartothatofferedbySkype™[SKYPE]butwithouthavingtoinstallanysoftwareorplug-ins.Forawebsiteorwebapplicationtoworkregardlessofwhichbrowserisused,standardsarerequired.Also,standardsarerequiredsothatbrowserscancommunicatewithnon-browsers,includingenterpriseandserviceprovidertelephonyandcommunicationsequipment.
TheWebBrowsingModel
ThebasicmodelofwebapplicationsisshowninFigure1.1.TransportofinformationbetweenthebrowserandthewebserverisprovidedbytheHyper-TextTransportProtocol,HTTP(Section6.2.1),whichrunsoverTransmissionControlProtocol,TCP(Section6.2.9),orinsomenewimplementations,overtheWebSocketprotocol(seeSection6.2.2).ThecontentorapplicationiscarriedinHyper-TextMarkupLanguage,HTML,whichtypicallyincludesJavaScriptandCascadingStyleSheets[CSS].Inthesimplecase,thebrowsersendsanHTTPrequesttothewebserverforcontent,andthewebserversendsaresponsecontainingthedocumentorimageorotherinformationrequested.Inthemorecomplexcase,theserversendsJavaScriptwhichrunsonthebrowser,interactingwiththebrowserthroughAPIsandwiththeuserthroughclicksandselects.ThebrowserexchangesinformationwiththeserverthroughanopenHTTPorWebSocketschannel.
1
WebRTC:APIsandRTCWEBProtocolsoftheReal-TimeWeb
Figure1.1WebBrowserModel
Infiguresinthisbook,wewillshowanarrowbetweenthewebbrowserandthewebservertoindicatethewebsessionbetweenthem.SinceWebRTCcanutilizeanywebtransport,thedetailsofthisconnection,andwhetheritisHTTPorWebSocketsisnotdiscussed.
TheReal-TimeCommunicationFunctionintheBrowser
Figure1.2showsthebrowsermodelandtheroleofthereal-timecommunicationfunction.Thelighterblockcalled“BrowserRTCFunction”isthefocusofthisbook.Theuniquenatureandrequirementsofreal-timecommunicationsmeansthataddingandstandardizingthisblockisnon-trivial.TheRTCfunctioninteractswiththewebapplicationusingstandardAPIs.ItcommunicateswiththeOperatingSystemusingthebrowser.AnewaspectofWebRTCistheinteractionthatoccursbrowser-to-browser,knownasa“PeerConnection”,wheretheRTCFunctioninonebrowsercommunicatesusingon-the-wirestandardprotocols(notHTTP)withtheRTCFunctioninanotherbrowserorVoiceoverIP(VoIP)orvideoapplication.WhilewebtrafficusesTCPfortransport,theon-the-wireprotocolbetweenbrowserscanuseothertransportprotocolssuchasUserDatagramProtocol,UDP.AlsonewistheSignalingServer,whichprovidesthesignalingchannelbetweenthebrowserandtheotherendofthePeerConnection.
2
1IntroductiontoWebRTC
Figure1.2Real-TimeCommunicationintheBrowser
ElementsofaWebRTCSystem
Figure1.3showsatypicalsetofelementsinaWebRTCsystem.Thisincludeswebservers,browsersrunningvariousoperatingsystemsonvariousdevicesincludingdesktopPCs,tablets,andmobilephones,andotherservers.AdditionalelementsincludegatewaystothePublicSwitchedTelephoneNetwork(PSTN)andotherInternetcommunicationendpointssuchasSessionInitiationProtocol(SIP)phonesandclientsorJingleclients.WebRTCenablescommunicationamongallthesedevices.Thefiguresinthisbookwillusetheseiconsandelementsasexamples.
3
WebRTC:APIsandRTCWEBProtocolsoftheReal-TimeWeb
Figure1.3ElementsinaWebRTCEnvironment
TheWebRTCTriangle
Initially,themostcommonscenarioislikelytobewherebothbrowsersarerunningthesameWebRTCwebapplication,downloadedfromthesamewebpage.ThisproducestheWebRTC“Triangle”showninFigure
1.4.Thisarrangementiscalledatriangleduetotheshapeofthesignaling(sidesoftriangle)andmediaordataflows(baseoftriangle)betweenthethreeelements.APeerConnectionestablishesthetransportforvoiceandvideomediaanddatachannelflowsdirectlybetweenthebrowsers.
4
1IntroductiontoWebRTC
Figure1.4TheWebRTCTriangle
Notethatwhilewesometimesrefertotheconnectionbetweenthebrowserandserverassignaling,itisnotreallysignalingasusedintelephonysystems.SignalingisnotstandardizedinWebRTCasitisjustconsideredpartoftheapplication.ThissignalingmayrunoverHTTPorWebSocketstothesamewebserverthatservesHTMLpagestothebrowser,ortoacompletelydifferentwebserverthatjusthandlesthesignaling.
TheWebRTCTrapezoid
Figure1.5showstheWebRTCTrapezoid[draft-ietf-rtcweb-overview],basedontheSIPTrapezoid[RFC3261].ThetwowebserversareshowncommunicatingusingastandardsignalingprotocolsuchasSessionInitiationProtocol(SIP),usedbymanyVoIPandvideoconferencingsystems,orJingle[XEP-0166],usedtoaddvoiceandvideocapabilitytoJabber[RFC6120]instantmessagingandpresencesystems.Alternatively,aproprietarysignalingprotocolcouldbeused.Notethatinthesemorecomplicatedcases,themediamaynotflowdirectlybetweenthetwobrowsers,butmaygothroughmediarelaysandotherelements,asdiscussedinChapter3.
5
WebRTC:APIsandRTCWEBProtocolsoftheReal-TimeWeb
Figure1.5TheWebRTCTrapezoid
WebRTCandtheSessionInitiationProtocol(SIP)
Figure1.6showsWebRTCinteroperatingwithSIP.TheWebServerhasabuilt-inSIPsignalinggatewaytoallowthecallsetupinformationtobeexchangedbetweenthebrowserandtheSIPclient.TheresultingmediaflowisdirectlybetweenthebrowserandtheSIPclient,asthePeerConnectionestablishesastandardReal-timeTransportProtocol(RTP)mediasession(Section6.2.3)withtheSIPUserAgent.OtherwaysofinteroperatingwithSIParecoveredinSection2.2.6.
Figure1.6WebRTCInteroperatingwithSIP
WebRTCandJingle
Figure1.7showshowWebRTCcaninteroperatewithJingle.TheWeb
6
1IntroductiontoWebRTC
Serverhasabuilt-inExtensibleMessagingandPresenceProtocol,XMPP[RFC6120],alsoknownasJabber,serverwhichtalksthroughanotherXMPPservertoaJingleclient.
Figure1.7WebRTCInteroperatingwithJingle
WebRTCandthePublicSwitchedTelephoneNetwork(PSTN)
Figure1.8showshowWebRTCcaninteroperatewiththePublicSwitchedTelephoneNetwork(PSTN).ThePSTNGatewayterminatestheaudio-onlymediastreamandconnectsthePSTNtelephonecallwiththemedia.SomesortofsignalingisneededbetweentheWebServerandthePSTNGateway.ItcouldbeSIP,oramaster/slavecontrolprotocol.
Figure1.8WebRTCInteroperatingwiththePSTN
ItisnotexpectedthatbrowserswillbeassignedtelephonenumbersorbepartofthePSTN.Instead,anInternetCommunicationservicecouldassignatelephonenumbertoauser,andthatusercoulduseWebRTCto
7
WebRTC:APIsandRTCWEBProtocolsoftheReal-TimeWeb
accesstheservice.Asaresult,atelephonecalltothatPSTNnumberwould“ring”thebrowserandanansweredcallwouldresultinanaudiosessionacrosstheInternetconnectedtothePSTNcaller.Otherservicescouldincludetheabilityto“dial”atelephonenumberinaWebRTCapplicationwhichwouldresultintheaudiopathacrosstheInternettothePSTN.
NotethatthephoneinFigure1.8couldbeanormalPSTNphone(“landline”or“blackphone”)oramobilephone.ThefactthatitmightberunningVoLTE(VoiceoverLongTermEvolution)orotherVoIP(VoiceoverInternetProtocol)protocoldoesn’tchangethispicture,asthePeerConnectionwillterminatewithaVoIPgateway.
AnotherinterestingareaistheroleofWebRTCinprovidingemergencyservices.WhileaWebRTCservicecouldsupportemergencycallinginthesamewayasVoIPInternetCommunicationservices,thereisthepotentialthatthePublicServiceAnsweringPoint(PSAP)couldbecomeaWebRTCapplication,andansweremergency“calls”directlyfromotherbrowsers,completelybypassingthePSTN.Ofcourse,thisraisesallkindsofinterestingsecurity,privacy,andjurisdictionissues.
MultipleMediaStreamsinWebRTC
Devicestodaycangenerateandconsumemultiplemediatypesandmultiplestreamsofeachtype.Eveninthesimplepoint-to-pointexampleshowninFigure1.9,amobilephoneandadesktopPCcouldgenerateatotalofsixmediastreams.Formultipartysessions,thisnumberwillbemuchhigher.Asaresult,WebRTChasbuilt-incapabilitiesfordealingwithmultiplemediastreamsandsources.
Figure1.9MultipleMediaStreamsinaPoint-to-PointWebRTCSession
Multi-PartySessionsinWebRTC
Theprecedingexampleshavebeenpoint-to-pointsessionsbetweentwobrowsers,orbetweenabrowserandanotherendpoint.WebRTCalsosupportsmulti-partyorconferencingsessionsinvolvingmultiplebrowsers.
8
1IntroductiontoWebRTC
OnewaytodothisistohaveeachbrowserestablishaPeerConnectionwiththeotherbrowsersinthesession.ThisisshowninFigure1.10.Thisissometimesreferredtoasa“fullmesh”or“fullydistributed”conferencingarchitecture.EachbrowserestablishesafullmeshofPeerConnectionswiththeotherbrowsers.Foraudiomedia,thismightmeanmixingthemediareceivedfromeachbrowser.Forvideo,thismightmeanrenderingthevideostreamsfromotherbrowserstodifferentwindowswithappropriatelabeling.Asnewbrowsersjointhesession,newPeerConnectionsareestablishedtosendandreceivethenewmediastreams.
Figure1.10MultiplePeerConnectionsBetweenBrowsers
Analternativearchitecturetothefull-meshmodelofFigure1.10isalsopossiblewithWebRTC.Foramultiplebrowserconference,acentralizedmediaserver/mixer/selectorcanbeused;thisrequiresonlyasinglePeerConnectiontobeestablishedbetweeneachbrowserandthemediaserver.ThisisshowninFigure1.11.Thisissometimesreferredtoasa“centrallymixed”conferencingarchitecture.Eachbrowsersendsmediatotheserver,whichdistributesittotheotherbrowsers,withorwithoutmixing.FromtheperspectiveofbrowserM,mediastreamsfrombrowserLandTarereceivedoverasinglePeerConnectionfromtheserver.Asnewbrowsersjointhesession,nonewPeerConnectionsinvolvingbrowserMneedtobeestablished.Instead,newmediastreamsarereceivedovertheexistingPeerConnectionbetweenbrowserMandthemediaserver.
9
WebRTC:APIsandRTCWEBProtocolsoftheReal-TimeWeb
Thefull-mesharchitectureofFigure1.10hastheadvantagesofnomediaserverinfrastructure,andlowestmedialatencyandhighestquality.However,thisarchitecturemaynotbesuitableforalargemulti-partyconferencebecausethebandwidthrequiredateachbrowsergrowswitheachnewparticipant.ThecentralizedarchitectureofFigure1.11hastheadvantageofbeingabletoscaletoverylargesessionswhilealsominimizingtheamountofprocessingneededbyeachbrowserwhenanewparticipantjoinsthesession,althoughitisperhapsinefficientwhenonlyoneorasmallnumberofbrowsersareinvolved,suchasinpeer-to-peergaming.
Figure1.11SinglePeerConnectionwithMediaServer
WebRTCStandards
TheWebRTCstandardsarecurrentlyunderjointdevelopmentbytheWorldWideWebConsortium(W3C)[W3C]andtheInternetEngineeringTaskForce(IETF)[IETF].W3CisworkingondefiningtheAPIsneededforJavaScriptwebapplicationstointeractwiththebrowserRTCfunction.TheseAPIs,suchasthePeerConnectionAPI,aredescribedinChapter5.TheIETFisdevelopingtheprotocolsusedbythebrowserRTCfunctiontotalktoanotherbrowserorInternetCommunicationsendpoint.Theseprotocols,forexample,extensionstotheReal-timeTransportProtocol,aredescribedinChapter8.
Therearepre-standardimplementationsofmanyofthecomponentsofWebRTCinsomebrowserstoday.SeeChapter8fordetails.
Notethatthereisanimportantdistinctionbetween‘pre-standard’and‘proprietary’implementations.Pre-standardimplementations
10
1IntroductiontoWebRTC
emergeduringthedevelopmentstageofstandards,andarecriticaltogainexperienceandinformationbeforestandardsarefinalizedandlockeddown.Pre-standardimplementationsoftenfollowanearlyordraftversionofthestandards,orpartiallyimplementstandardsasa‘proofofconcept’.Oncethestandardhasbeenfinalized,thesepre-standardimplementationsmustmovetowardsthestandards,orelsetheyriskbecomingaproprietaryimplementation.Proprietaryimplementationsfragmenttheuseranddevelopmentbase,whichinanareasuchascommunicationscangreatlyreducethevalueoftheservices.
TheW3CworkiscenteredaroundtheWEBRTCWorkingGroupandtheIETFworkiscenteredaroundtheRTCWEB(Real-TimeCommunicationsWeb)WorkingGroup.Thetwogroupsareindependent,butcloselycoordinatetogetherandhavemanycommonparticipants,includingtheauthors.
TheprojectedtimeframeforpublicationofthefirstversionofstandardsintheIETFandW3Cisin2014.However,thesedatesaremostlikelyoverlyoptimistic.(Whendoengineerseverrealisticallyestimatelevelofeffort?)Standards-compliantWebRTCbrowsersareexpectedtobegenerallyavailablesometimeinlate2014.
WhatisNewinWebRTC
TherearemanynewandexcitingcapabilitiesinWebRTCthatarenotavailableevenintoday’sVoIPandvideoconferencingsystems.SomeofthesefeaturesarelistedinTable1.1.TherestofthisbookwillexplainhowtheseareachievedusingtheWebRTCAPIsandprotocols.
ImportantTerminologyNotes
Inthisbook,whenwerefertotheentireefforttoaddstandardizedcommunicationcapabilitiesintobrowsers,weshalluseWebRTC.WhenwearereferringtotheW3CWorkingGroup,wewilluseWEBRTC.WhenwearereferringtotheIETFWorkingGroup,wewilluseRTCWEB.NotethatWebRTCisalsousedtodescribetheGoogle/Mozillaopensourcemediaengine[WEBRTC.ORG],whichisanimplementationofWebRTC.
Inaddition,becausethemainW3Cspecificationistitled“TheWebRTCSpecification”[WEBRTC1.0],weuseitsfulltitletoreferencethisparticularW3Cdocument,whichisakeypartofWebRTC,butbynomeanstheentirespecification.
AlsonotethattheWorldWideConsortiumreferstoitselfas“W3C”
11
WebRTC:APIsandRTCWEBProtocolsoftheReal-TimeWeb
andnot“theW3C”.Wehaveadoptedthisconventionthroughoutthisbook.
12
1IntroductiontoWebRTC
Table1.1NewFeaturesofWebRTC
References
13
WebRTC:APIsandRTCWEBProtocolsoftheReal-TimeWeb
[HTML5]
/TR/html5
[SKYPE]
[CSS]
/Style/CSS
[draft-ietf-rtcweb-overview]
/html/draft-ietf-rtcweb-
overview
[RFC3261]
/html/rfc3261
[XEP-0166]
/extensions/xep-0166.html
[RFC6120]
/html/rfc6120
[W3C]
[IETF]
[WEBRTC.ORG]
[WEBRTC1.0]
/TR/webrtc
14
2HOWTOUSEWEBRTC
WebRTCiseasytouse,withjustafewstepsnecessarytoestablishmediasessions.Anumberofmessagesflowbetweenthebrowserandtheserver,whileothersflowdirectlybetweenthetwobrowsers,knownaspeers.WebRTCcanevenestablishsessionswithSIP,Jingle,andPSTNendpoints.TherearemanystandardsinvolvedintheWebRTCeffort–somanythatitcanbedifficulttoknowwheretostartwhenlearningaboutit.SincemanyreadersofthistextwilllikelybedevelopersofWebRTCapplications,thefollowingsectionsgiveanoverviewofhowtosetupaWebRTCsession,whatcanbedonewhilethesessionisrunning,andhowtoclosedownthesession.WebRTCcanbeusedinanumberofdifferentarchitectures.ExamplepseudocodeillustratestheoperationoftheWebRTCAPIs.
SettingUpaWebRTCSession
Asanapplicationdeveloper,thefourmainactionstotakewhensettingupaWebRTCsessionare:
Obtainlocalmedia,
Setupaconnectionbetweenthebrowserandthepeer(otherbrowserorendpoint),
Attachmediaanddatachannelstotheconnection,and
Exchangesessiondescriptions
ThesefourstepsareshowninFigure2.1. NotethatthisfigurecorrespondswithFigure1.4.
Figure2.1WebRTCSessionEstablishment,APIView
15
WebRTC:APIsandRTCWEBProtocolsoftheReal-TimeWeb
Figure2.2WebRTCAPIViewwithSignaling
Figure2.2showsanotherviewofthesteps,thistimewithsignalingstepsshown.
Thefollowingsubsectionsbrieflydescribeeachofthesesteps,aswellastheprocessforclosingdownasessionwhencomplete.
ObtainingLocalMedia
Thereareavarietyofwaystoobtainmedia,thecompletelistofwhichisoutofscopeforthisbook.However,oneofthemostcommonwaysisdefinedbytheWebRTCeffort:getUserMedia()(Section5.3.2).ThismethodcanbeusedtoobtainasinglelocalMediaStream.Onceyouhaveoneormoremediastreams,youcanpiecethemtogetherintothestreamsyouwantusingtheMediaStreamAPI(ApplicationProgrammingInterface).Forprivacyreasons,awebapplication’srequestforaccesstoauser’smicrophoneorcamerawillonlybegrantedafterthebrowserhasobtainedpermissionfromtheuser.
SettingupthePeerConnection
AnotherimportantstepistosetupthePeerConnectionusingtheAPIbythesamename.ThecoreofWebRTCistheRTCPeerConnectionAPI,which,asitsnamesuggests,setsupaconnectionbetweentwoPeers.Inthiscontext,“peers”meanstwocommunicationendpointsontheWorldWideWeb,asinthephrase“peer-to-peerfilesharing”.Insteadofrequiringcommunicationthroughaserver,thecommunicationisdirectbetweenthetwoentities.InthespecificcaseofWebRTC,aPeerConnectionisadirectmediaconnectionbetweentwowebbrowsers.
16
2HowtoUseWebRTC
Thisisparticularlyrelevantwhenamulti-waycommunicationsuchasaconferencecallissetupamongthreeormorebrowsers.EachpairofbrowserswillrequireasinglePeerConnectiontojointhem,allowingforaudioandvideomediatoflowdirectlybetweenthetwo,asshowninFigure1.10.Thus,threebrowserscommunicatingwouldneedatotalofthreeconnectionsamongthem.AnapplicationdeveloperwillneedtosetuponePeerConnectionperpairofbrowsers(orabrowserandanotherendpointsuchasanexistingcommunicationsnetwork)beingconnected.Thealternativearchit
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年国际粮食市场形势及风险应对知识题库
- 2026年礼品礼金登记上交规定培训题库
- 2026年促进绿色消费实施方案及绿色低碳产品推广与闲置物品交易题库
- 2026年非高危转高危岗位题库
- 2026年职场称呼礼仪与人际沟通技巧试题
- 2026年街道地质灾害识别与紧急避险试题
- 2026年铁路系统面试中如何展现自我优势
- 2026年教育心理学教师资格证考试题目
- 2026年事业单位工作人员考核与岗位聘用衔接知识考核
- 2026年儿童参与权保障知识竞赛试题
- 2026年地铁运营控制中心行车调度员招聘笔试题库含答案
- 广西循环经济发展:模式、成效、挑战与展望
- 2024年公路养护工专业技能考试题库(附答案解析)
- 艺人助理课件
- 2025 七年级数学下册实数大小比较的特殊值代入法课件
- 大检修培训课件
- 2025年甘肃卫生职业学院单招职业适应性考试模拟测试卷附答案
- 2025年江苏省安全员《A证》考试题库及答案
- 2025年AP考试物理C真题
- 2025课堂惩罚 主题班会:马达加斯加企鹅课堂惩罚 课件
- 施工现场交通安全课件
评论
0/150
提交评论