Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
old 2013 last commit: Releasing RTCMultiConnection-v1.5.js Dec 31, 2013

WebRTC One-to-One video sharing using / Demo

It supports any signaling gateway. over Node.js is preferred. You can customize events too.


How to use it in your own website?

First of all; link following library:


Simplest Demo

var offerer = new PeerConnection('http://domain:port', 'message', 'offerer');
offerer.onStreamAdded = function(e) {
var answerer = new PeerConnection('http://domain:port', 'message', 'answerer');
answerer.onStreamAdded = function(e) {



Constructor takes three arguments. Last two are optional.

var peer = new PeerConnection('socket-url', 'socket-event', 'user-id');

// you can write like this:
var peer = new PeerConnection('socket-url');
  1. socket-url: it is mandatory
  2. socket-event: default event is "message"
  3. user-id: by default, it is auto generated

There are two ways to connect peers:

  1. The easiest method of "manual" peers connection is call "sendParticipationRequest" and pass user-id of the target user.
  2. otherwise, call "startBroadcasting" (behind the scene) this function will be invoked recursively until a participant found.

// or

By default peers are auto-connected; however, you can override this behavior and be alerted if a user transmitted himself using "startBroadcasting":

// "onUserFound" allows you connect multiple peers i.e. one-to-many
peer.onUserFound = function(userid) {

You can access local or remote media streams using "onStreamAdded":

offerer.onStreamAdded = function(e) {
   // e.mediaElement --- HTMLVideoElement
   //       --- MediaStream
   // e.type         --- "local" or "remote"

You may want to remove HTML video elements if a peers leaves:

offerer.onStreamEnded = function(e) {
   // e.mediaElement --- HTMLVideoElement
   //       --- MediaStream
   // e.type         --- "local" or "remote"


You can override user-id any time:

peer.userid = '123';

setTimeout(function() {
   peer.userid = '890
}, 5000);

You can manually leave/close the room:


You can access target user's id too:

console.log('target user-id is', peer.participant);

You may want to be alerted for each participantion request; and manually allow/reject them:

peer.onParticipationRequest = function(userid) {
  1. override "onParticipationRequest" to prevent auto-accept of requests
  2. use "acceptRequest" method to manually allow requests

You may want to list number of users connected with you:

var numberOfUsers = 0;
for(var user in peer.peers) {
   console.log(user, 'is connected with you.');
console.log('total users connected with you:', numberOfUsers);

You can access media stream like this:

console.log('local media stream:', peer.MediaStream);

// you can stop media strema too:

// however, instead of "stopping" media-stream manually
// you "close" method instead:


Browser Support

This PeerConnection.js supports following web-browsers:

Browser Support
Firefox Stable / Aurora / Nightly
Google Chrome Stable / Canary / Beta / Dev
Android Chrome Beta



PeerConnection.js is released under MIT licence . Copyright (c) 2013 Muaz Khan.

You can’t perform that action at this time.