PeerJSWeb 的点对点通信
PeerJS 实现了真正的浏览器上的点对点数据通讯。PeerJS 将 WebRTC 作为 API 抽象、连接代理和二进制序列化。
PeerJS 项目的目的是实现运行在不同系统上的Web应用程序相互通讯。PeerJS完善了WebRTC,因为作为视频连接协议,WebRTC并没有说明基于WebRTC的客户端应该如何定位连接的用户。
连接端代码:
<script>
  var peer = new Peer('someid', {key: 'apikey'});
  peer.on('connection', function(conn) {
    conn.on('data', function(data){
      // Will print 'hi!'
      console.log(data);
    });
  });
</script> 
对端代码:
<script>
  var peer = new Peer('anotherid', {key: 'apikey'});
  var conn = peer.connect('someid');
  conn.on('open', function(){
    conn.send('hi!');
  }); 
</script>评论
