A simple WebRTC Data Channel library. It allows the communication between two nodes.
npm install --save quickp2p
- 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));
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.
See https://afska.github.io/quickp2p for a live demo!
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
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([ ... ])
.
You can change connection timeout (in milliseconds) by using quickp2p.setTimeout(15 * 1000)
.
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.
nvm use
npm install
npm start
npm run build
npm run build-lib
./deploy-demo.sh
./deploy-lib.sh