Chapter 2. Handling Media in the Browser
In this chapter, we start delving into the details of the WebRTC framework, which basically specifies a set of JavaScript APIs for the development of web-based applications. The APIs have been conceived at the outset as friendly tools for the implementation of basic use cases, like a one-to-one audio/video call. They are also meant to be flexible enough to guarantee that the expert developer can implement a variegated set of much more complicated usage scenarios. The programmer is hence provided with a set of APIs which can be roughly divided into three logical groups:
Acquisition and management of both local and remote audio and video:
-
MediaStreaminterface (and related use of the HTML5<audio>and<video>tags)
-
Management of connections:
-
RTCPeerConnectioninterface
-
Management of arbitrary data:
-
RTCDataChannelinterface.
-
WebRTC in 10 Steps
The following 10-step recipe describes a typical usage scenario of the WebRTC APIs:
-
Create a
MediaStreamobject from your local devices (e.g., microphone, webcam). -
Obtain a URL blob from the local
MediaStream. - Use the obtained URL blob for a local preview.
-
Create an
RTCPeerConnectionobject. - Add the local stream to the newly created connection.
- Send your own session description to the remote peer.
- Receive the remote session description from your peer.
-
Process the received session description and add the remote stream to your
RTCPeerConnection. - Obtain a URL blob from the remote stream.
- Use ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access