PeerJS 介绍
Peerjs 提供了 一个 完整、可配置、易于使用、基于WebRTC的点对点的数据通信。Peerjs是 一个 开源的JavaScript库,目的是允许运行在不同系统上的Web应用程序相互联系。Peerjs开发者称,Peerjs完善了WebRTC,因为作为视频连接协议,WebRTC并没有说明基于WebRTC的客户端应该如何定位连接的 用户 。
Peerjs有 一个 简单的API,允许通过三行 代码 来实现对等连接。PeerServer作为Peerjs的后端,这是 一个 基于Node.js的web服务器,这也是开源的。
Setup
Include the library
with npm: npm install peerjs and the usage:
import Peer from 'peerjs';
Create a Peer
const peer = new Peer('pick-an-id');
// You can pick your own id or omit the id if you want to get a random one from the server.
Data connections
Connect
const conn = peer.connect('another-peers-id');
conn.on('open',() => {
conn.send('hi!');
});
Receive
peer.on('connection',(conn) => {
conn.on('data',(data) => {
// Will print 'hi!'
console.log(data);
});
});
网站地址 : http://peerjs.com
GitHub: https://github.com/peers/peerjs/
网站描述: 一个 完整、可配置、易于使用、基于WebRTC的点对点API
PeerJS官方网站
官方网站: http://peerjs.com
如果觉得 网站内容还不错,欢迎将 网站 推荐给程序员好友。