peerjs npm

SkyWay対応版のPeerJS

2 years after

PeerJS: Simple peer-to-peer with WebRTC

PeerJS provides a complete, configurable, and easy-to-use peer-to-peer API built on top of WebRTC, supporting both data channels and media streams.

http://nttcom.github.io/skyway

Setup

Include the library

<script src="https://skyway.io/dist/0.3/peer.js"></script>

Create a Peer
Get a free API key. Your id only needs to be unique to the namespace of your API key.

var peer = new Peer('pick-an-id', {key: 'myapikey'}); 
// You can pick your own id or omit the id if you want to get a random one from the server.

Data connections

Connect

var conn = peer.connect('another-peers-id');
conn.on('open', function(){
  conn.send('hi!');
});

Receive

peer.on('connection', function(conn) {
  conn.on('data', function(data){
    // Will print 'hi!'
    console.log(data);
  });
});

Media calls

Call

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
navigator.getUserMedia({video: true, audio: true}, function(stream) {
  var call = peer.call('another-peers-id', stream);
  call.on('stream', function(remoteStream) {
    // Show stream in some <video> element.
  });
}, function(err) {
  console.log('Failed to get local stream' ,err);
});

Answer

navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
peer.on('call', function(call) {
  navigator.getUserMedia({video: true, audio: true}, function(stream) {
    call.answer(stream); // Answer the call with an A/V stream.
    call.on('stream', function(remoteStream) {
      // Show stream in some <video> element.
    });
  }, function(err) {
    console.log('Failed to get local stream' ,err);
  });
});

SkyWay Links

Documentation / API Reference

Changelog

free API key

Discuss SkyWay on our Google Group

PeerJS links

WebRTC Browser compatibility status

PeerServer

Discuss PeerJS on our Google Group

Related Repositories

peerjs-server

peerjs-server

Server for PeerJS ...

peerjs-audio-chat

peerjs-audio-chat

WebRTC / PeerJS audio chat demo ...

PeerObjectiveC

PeerObjectiveC

PeerObjectiveC is WebRTC client library for iOS, that communicate to peerjs-serv ...

bower-peerjs

bower-peerjs

Bower package for PeerJS. ...

peerjs-lobby

peerjs-lobby

a lobby system for peer to peer apps ...


Top Contributors

michelle ericz yusuke84 alanmshelly michelle-stripe hnry iwashi KensakuKOMATSU lmb xizhao hansoksendahl MatthiasLohr mururu khankuan zag2art cvan creatorrr ezanattatray UnsungHero97 jhamit che-burashco gdi2290 sho-y sbalko sblaurock yemel emersion rocky85

Releases

-   0.3.6 zip tar
-   0.3.5 zip tar
-   0.3.4 zip tar
-   0.3.3 zip tar
-   0.3.2 zip tar
-   0.3.1 zip tar
-   0.3.0 zip tar
-   0.2.8 zip tar
-   0.2.7 zip tar
-   0.2.6 zip tar
-   0.2.5 zip tar
-   0.2.1 zip tar
-   0.2.0 zip tar
-   0.1.7 zip tar
-   0.1.6 zip tar
-   0.1.5 zip tar
-   0.1.0 zip tar