1.0.0 • Published 7 years ago

appeerjs v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

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
  2. 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>
  3. You need to start the signaling server with the appeerjs-server.

  4. 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
    });
  5. 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
    });
  6. You can now call to a connected peer, using appeer.call.

    navigator.mediaDevices.getUserMedia(constraints).then(function (stream) {
      appeer.call(appeerId, stream);
    });
  7. 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);
    });
  8. 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 for more information on the official support specification.

Inspirations and Motivations

Credits

License

This project is licensed under the MIT License - see the LICENSE file for details

TODO

  • Unit tests
  • Group conference feature
  • 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.
1.0.0

7 years ago

0.1.1

7 years ago

0.0.1

8 years ago