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:
- a Node.js signaling server
- a Javascript client library (this repository) for the browser
npm install icebreaker.io-client --save
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.
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.
npm run test
This command runs the gulp
task test
, which runs the unit tests in the tests
directory.