Skip to content

automerge/automerge-repo-network-peerjs

Repository files navigation

automerge-repo-network-peerjs

ci.node

A network adapter for WebRTC using peerjs, based on the point-to-point MessageChannelNetworkAdapter.

 

Setup

yarn add automerge-repo-network-peerjs

 

Usage

Establish a data connection as per peerjs documentation:

import { Peer } from "peerjs";
const peer = new Peer("pick-an-id");
const conn = peer.connect("another-peers-id");

Then use that to pass into the constructor of the automerge network adapter:

import { PeerjsNetworkAdapter } from "automerge-repo-network-peerjs";
const adapter = new PeerjsNetworkAdapter(conn);

Along with the usual NetworkAdapterInterface events an additional onData event is available to keep track of directional data being sent and received, for example:

function monitor(adapter: PeerjsNetworkAdapter, dispose$?: Observable) {
  const detach = adapter.onData((e) => console.log(`⚡️ ${e.direction}: ${e.bytes} bytes`));
  dispose$?.subscribe(detach);
}

 


Please Note:
This is not an official part of the automerge-repo project, rather a community contribution that includes a dependency on the peerjs library.

About

Network adapter for automerge-repo using peerjs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published