How to use Web RTC in HTML5?

Web RTC of HTML5 was introduced by World Wide Web Consortium (W3C) which supports browser-to-browser applications for voice calling, video chat, and P2P file sharing.

Web RTC has three API's as shown below

  • MediaStream – is used to get access to the user's camera and microphone.
  • RTCPeerConnection – is used to get access to audio or video calling facility.
  • RTCDataChannel – is used to get access to peer-to-peer communication.


MediaStream signifies synchronized streams of media. Above example contains stream.getAudioTracks() and stream.VideoTracks(). If no audio tracks are present then it will return an empty array and will check for video stream. If webcam is connected, stream.getVideoTracks() returns an array of one MediaStreamTrack showing the stream from the webcam. Best example is chat applications which get stream from web camera, rear camera, microphone.

Sample code of MediaStream

Screen capture

Screen capturing in chrome browser is done with mediaStreamSource but it requires HTTPS. This feature is not yet available in opera.

Session Control, Network & Media Information

Web RTC requires peer-to-peer communication between browsers and also requires signalling, network information, session control and media information. Different mechanisms can be choosen for communicating between the browsers such as SIP or XMPP or any two way communications.

Sample code of createSignalingChannel()

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

HTML 5 Topics