Web Real Time Communication
Real Time P2P communication of Audio, Video and Data
Without plugins.
API Standards & Specs @
W3C.
Browser Support
Frameworks / Implementations
Acquiring Video and Audio
var constraints = {video: true, audio: true };
navigator.getUserMedia(constraints, successCallback, errorCallback);
function successCallback(stream) {
var video = document.querySelector("video");
video.src = window.URL.createObjectURL(stream);
}
function errorCallback(error) {
alert("Error: ", error);
}
-
constraints
- Must for getUserMedia, specifies Media type, resolution, etc.
-
video
- HTML5 DOM element
Communicating Streams
var peerCon = new window.RTCPeerConnection(configuration);
peerCon.addStream(localStream); // got from getUserMedia
peerCon.onaddstream = function(e) {
...
peerCon.addIceCandidate(candidate);
peerCon.onicecandidate = function(e) {
...
peerCon.setLocalDescription(description); peerCon.setRemoteDescription(new RTCSessionDescription(..));
peerCon.createOffer(IceCandidate); peerCon.createAnswer(...)
-
IceCandidate
- ICE - f/w to bypass Firewalls
-
RTCSessionDescription
- Metadata per SDP
Communicating Data
var peerCon = new window.RTCPeerConnection( servers, {
optional: [{ RtpDataChannels: true }]
});
peerCon.ondatachannel = function(event) {
receiverChannel = event.channel;
receiverChannel.onmessage = function(event){ receiveDOMElement.innerHTML = event.data; };
};
XmitterChannel = pc.createDataChannel("sendDataChannel", {reliable: false});
XmitterChannel.send('Hello WebRTC');
-
RtpDataChannels: true
- Arbitrary data via the same RTCPeerConnection.
-
onmessage
, etc. - Same API as WebSockets.
Feature Support
Chrome
Desktop 20+,
Chrome
Android 29+
FireFox 17+
Opera, Opera Mobile 12+
Chrome
Desktop 20+,
Chrome
Android 29+
FireFox 22+
Chrome
Desktop 26+,
Chrome
Android 29+
FireFox 22+