appeerjs

1.0.0 • Public • Published

AppeerJS

A basic encapsulation of Native WebRTC, this would offer an easy to use and understand API for beginners out there

Getting Started

  1. Go to your project directory using your command line tool then install the project using npm.
npm install appeerjs
  1. Include socket.io and appeer.js to your index page.
<script type="text/javascript" src="socket.io.js"></script>
<script type="text/javascript" src="appeer.min.js"></script>
  1. You need to start the signaling server with the [appeerjs-server] (https://github.com/TMJPEngineering/appeerjs-server).

  2. After finishing the step three you can now connect to AppeerJS.

var appeer = new Appeer('customId', {
  host: 'localhost',
  port: '9000',
  debug: true // Set to true to show console logs and errors, defaults to false
});
  1. Listen to the appeerjs events.
// Triggers when you successfully connects to appeerjs
appeer.on('connection', function (event) {
  var appeerId = event.data.id;
  console.log('My appeer id is', appeerId);
});

// Triggers when the other peers is calling you
appeer.on('call', function (event) {
  var call = event.data.call;
  
  navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
    call.answer(stream); // Answer the call with your stream
  });
});

// Triggers when the remote peer answers the call with a stream
appeer.on('stream', function (event) {
  var stream = event.detail.stream;
  // Do something with the stream
});

// Triggers when a peer connection has been disconnected
appeer.on('close', function (event) {
  var appeerId = event.data.id;
  console.log('User ', peerId, 'has left the call');
});

// Triggers when connecting to appeer fails
appeer.on('error', function (event) {
  var error = event.detail.error;
  // Handle error
});
  1. You can now call to a connected peer, using appeer.call.
navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
  appeer.call(appeerId, stream);
});
  1. You can do a conference call by joining a room first
var roomId = '1234';

appeer.join(roomId);
navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
  appeer.call(roomId, stream);
});
  1. Disconnect from a connection
var id = '123'; // Either appeer id or room id
apppeer.close(id);

Limitations

Currently WebRTC is not supported in all browsers.
Please see [supported browser versions] (http://caniuse.com/#feat=rtcpeerconnection) for more information on the official support specification.

Inspirations and Motivations

Credits

License

This project is licensed under the MIT License - see the [LICENSE] (https://github.com/TMJPEngineering/appeerjs/blob/master/LICENSE) file for details

TODO

  • [ ] Unit tests
  • [x] Group conference feature
  • [x] Replace Native Javascript Events with a lightweight Event Library or make a new one
  • [ ] Trigger 'close' event when a single connection user has disconnected unintentionally e.g Page refresh, etc.

Readme

Keywords

Package Sidebar

Install

npm i appeerjs

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • jmsanpascual