Real-Time Communication in the Web, WebRTC in short, is a set of APIs allowing web applications to send and receive streaming real-time video, audio and data to/from remote peers, without relying it through the centralized server. The server, implementing one of the specific signalling protocols, is needed for initial discovery and connection handshake, though. The APIs rely on the
mediaStream object - see Audio & Video Capture.
connection = new RTCPeerConnection(configuration)
- Creates a connection object that will be used to establish serverless connection between peers. The
configurationmay include the set of
iceServersthat will be used for discovery and connection handshake.
- An event fired when the signalling server registers a remote peer with which the connection may be established.
- Adds an existing local Media Stream (e.g. the local web cam) to the remote peer connection.
connection.onaddstream = event => video.src = URL.createObjectURL(event.stream)
- Registers an
onaddstreamevent handler that, if and when called, retrieves the remote party's Media Stream and plugs it into a <video> tag
- Returns a
Promiseresolved when the remote peer connects to the connections and streams offered.
- Accepts the connection offerred by the remote peer. Returns a
Promiseresolved when the connection is established.
dataChannel = connection.createDataChannel(label, configuration)
- Opens a data channel for the connection, allowing it to transmit arbitrary types of data.
- Sends the data over the data channel to the remote peer.
- An event fired when the data has been received via the data channel.