A network adapter for WebRTC using peerjs, based on the point-to-point MessageChannelNetworkAdapter.
yarn add automerge-repo-network-peerjs
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.