Skip to content

Latest commit

 

History

History
77 lines (51 loc) · 1.62 KB

README.md

File metadata and controls

77 lines (51 loc) · 1.62 KB

PeerJS: Simple peer-to-peer with WebRTC ESNext

PeerJS provides a complete, configurable, and easy-to-use peer-to-peer API built on top of WebRTC.

Warning

This fork only supports data connections and json serialization.

Setup

Include the library

with npm: npm install peerjs and the usage:

import Peer from 'peerjs-esnext';

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);
  });
  conn.on('open', () => {
    conn.send('hello!');
  });
});

Running tests

npm test

FAQ

Q. I have a message Critical dependency: the request of a dependency is an expression in browser's console

A. The message occurs when you use PeerJS with Webpack. It is not critical! It relates to Parcel parcel-bundler/parcel#2883 We'll resolve it when updated to Parcel V2.

Links

License

PeerJS is licensed under the MIT License.