Giter Site home page Giter Site logo

quickp2p's Introduction

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:
import quickp2p, { SimpleStore } from "quickp2p";

quickp2p.setStore(new SimpleStore(YOUR_STORE_URL));

Usage

First, you have to create a channel:

const channel = await quickp2p.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:

const channel = await quickp2p.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:

Method Parameter Description
send String or Buffer Sends 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

quickp2p's People

Contributors

afska avatar javi avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.