automerge-repo-network-peerjs
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i automerge-repo-network-peerjs

Weekly Downloads

107

Version

1.2.0

License

MIT

Unpacked Size

21.7 kB

Total Files

25

Last publish

Collaborators

  • philcockfield