Webrtc

This chapter covers the usage of webRTC to send video streaming between teachers and students.

How it works

WebRTC is a standard protocol that allow video and audio streaming between two peers. To acheive that is necessary to know the following concepts.

Peer connections

A peer connection is the most important feature of webrtc. Is the object that allows us to send data to another peer. These connections have streams associated. A local stream which is the source of data that your connection takes to send these data. And a remote stream, the source of data that your connection gives to you from remote peer.

Media Streams

Media streams are a source of data that gives us video or audio. Those streams can be provided by:

  • A physical device: webcam, microphone.
  • A virtual device: A desktop display, a game engine cam, etc.

Any source of video or audio could be used to get a media streaming.

These media streams has tracks. A track is a source of video or audio. Remember that a meda stream can have video and audio at the same time. This is possible because a media stream has multiple tracks. Even can have multiple videos and audio tracks.

When you create a peer connection you attach these tracks to the connection before start signaling process.

Signaling

Before send data between peers these needs to establish a connection specifying how this data will be send. You can use the default configuration or specify how you want to send the data depending on your needs. Normally this configuratio is called session description.

There are two types of session description:

  • Offer: This is the initial configuration which will be send to another peer.
  • Answer: This is the configuration gived by the remote peer.

Webrtc don’t specify how this offer and answer should be sent. So is your responsability to implement a system that allows two peers to exchange this data. Normally a realtime protocol is used like websockets. In this documentation we will use socket.io.

STUN servers

Due the configuration of the majority of networks those can change while establishing connection. This is why to connect two peers it’s necessary to use an external service to discover possible candidates to connect to a peer. This service is called ICE and it uses a type of servers called STUN or TURN servers. Both can be used without any problem but TURN servers are more advanced and for the moment we only will use STUN servers.

For this tutorial we will use free google stun servers but you can use the one you prefer.

  • stun:stun1.l.google.com:19302
  • stun:stun2.l.google.com:19302