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> |

浙公网安备 33010602011771号