Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Repository files navigation

⚠️ This project is unmaintained. Please, use peerjs.

quickp2p

A simple WebRTC Data Channel library. It allows the communication between two nodes.

Install

npm install --save quickp2p

Configuration

  • Deploy the server folder (a node.js server for temporary storage) somewhere.
  • Configure the store:
importquickp2p,{SimpleStore}from"quickp2p";quickp2p.setStore(newSimpleStore(YOUR_STORE_URL));

Usage

First, you have to create a channel:

constchannel=awaitquickp2p.createChannel();channel.on("connected",()=>{/* channel connected */}).on("data",(message)=>{/* message received */}).on("timeout",()=>{/* connection timeout */}).on("disconnected",()=>{/* channel disconnected */});

Then, you can send channel.token to the other side, which should be running the following code:

constchannel=awaitquickp2p.joinChannel(token);channel.on("connected",()=>{/* channel connected */}).on("data",(message)=>{/* message received */}).on("timeout",()=>{/* connection timeout */}).on("disconnected",()=>{/* channel disconnected */});

All channels have these methods:

MethodParameterDescription
sendString or BufferSends the data or throws an error if the connection was lost.
disconnect-Ends the connection.

If a channel emitted "timeout" or "disconnected", it should be discarded.

Demo

See https://afska.github.io/quickp2p for a live demo!

Signalling server

You can use your own key-value store:

quickp2p.setStore({save(key,data){// save `data` under a certain `key`// return a promise},get(key){// retrieve the data from `key`// return a promise of the data}});// `data` is always a base64-encoded String

ICE Servers

By default, it uses the following ICE servers:

[{urls: "stun:stun.l.google.com:19302"}]

You can set another list of servers by using quickp2p.setIceServers([ ... ]).

Timeout

You can change connection timeout (in milliseconds) by using quickp2p.setTimeout(15 * 1000).

⚠️ Symmetric NATs

This default server list won't work if both peers are under Symmetric NATs. To address that problem, you'll need to use a TURN server.

A quick workaround could be enabling a DMZ on one side.

Development

Install

nvm use
npm install

Run the app

npm start

Build

Demo

npm run build

Library

npm run build-lib

Deploy

Demo

./deploy-demo.sh

Library

./deploy-lib.sh

About

πŸ“‘ Dead simple WebRTC Data Channels!

Topics

Resources

Stars

3 stars

Watchers

0 watching

Forks

Used by

Contributors

Languages