Skip to content

Client JavaScript library for peer-to-peer WebRTC communications

License

Notifications You must be signed in to change notification settings

marifehe/icebreaker.io-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

icebreaker.io-client

icebreaker.io enables peer-to-peer real-time communications, using WebRTC technology. It is built on top of socket.io, and it basically allows two peers to resolve how to connect over the internet and start an RTCPeerConnection. It consists in:

Installation

npm install icebreaker.io-client --save

How to use

icebreaker.io-client uses the same interface as socket.io-client, since it is built on top of it. As an example, below you can find how to initialize it using ES6 import:

import icebreaker from 'icebreaker.io-client';
const icebreakerClient = icebreaker('https://localhost:8443', {
  path: '/socket'
});

Once the client has been initialized, the webrtc connection can be started as showed below:

// These are events you can subscribe to:
icebreakerClient.events.connectionEnded.addOnce(yourConnectionEndedHandler);
icebreakerClient.events.getUserMediaError.addOnce(yourGetUserMediaErrorHandler);
icebreakerClient.events.localStreamReady.addOnce(yourLocalStreamReadyHandler);
icebreakerClient.events.remoteStreamReady.addOnce(yourRemoteStreamHandler);

// All the properties are optional
const props = {
  connId: 'my-test-connection',
  mediaConstraints: {
    audio: true,
    video: true
  },
  configuration: {
    iceServers: [
      { url: 'stun:stun.l.google.com:19302' }
    ]
  }
};
icebreakerClient.start(props).then(connId => {
  console.log('>>>>> The connection id is: ', connId);
});

The same code can be used for the two peers. If a peer is joining a connection that exists and that has another peer already in, the WebRTC connection between the two will be established. The remote stream can be accessed through the remoteStreamReady event.

Demo project

You can find a fully working demo project that uses both server and client icebreaker.io libraries here. It is a very basic video-chat application.

Tests

npm run test

This command runs the gulp task test, which runs the unit tests in the tests directory.

License

GPLv3

About

Client JavaScript library for peer-to-peer WebRTC communications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published