斯柯达老明锐遥控器汽车钥匙换电池子磁(全过程)

PeerJS

PeerJS 实现了真正的浏览器上的点对点数据通讯。PeerJS 将 WebRTC 作为 API 抽象、连接代理和二进制序列化。

连接端代码:

1 <script>
2   var peer = new Peer('someid', {key: 'apikey'});
3   peer.on('connection', function(conn) {
4     conn.on('data', function(data){
5       // Will print 'hi!'
6       console.log(data);
7     });
8   });
9 </script>

对端代码:

1 <script>
2   var peer = new Peer('anotherid', {key: 'apikey'});
3   var conn = peer.connect('someid');
4   conn.on('open', function(){
5     conn.send('hi!');
6   });
7 </script>
posted @ 2013-02-17 16:10  读书  阅读(1515)  评论(0编辑  收藏  举报