3.0.0-beta.2 • Published 4 years ago

peerjs-esnext v3.0.0-beta.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

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 https://github.com/parcel-bundler/parcel/issues/2883 We'll resolve it when updated to Parcel V2.

Links

Documentation / API Reference

PeerServer

Discuss PeerJS on our Telegram Channel

Changelog

License

PeerJS is licensed under the MIT License.