-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert to using [NetworkAdapterInterface] (#4)
* rename * Update README.md * export t ypes * 0.0.12 * Update README.md * emit message events * implement [NetworkAdapterInterface] dropping deprecated [NetworkAdapter] inherits. * Update README.md * 1.1.1 * Update NetworkAdapter.test.ts
- Loading branch information
1 parent
2daf2e4
commit 7d46c85
Showing
7 changed files
with
105 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,43 @@ | ||
[](https://github.com/philcockfield/automerge-repo-network-peerjs/actions/workflows/ci.node.yml) | ||
# automerge-repo-network-peerjs | ||
[](https://github.com/philcockfield/automerge-repo-network-peerjs/actions/workflows/ci.node.yml) | ||
|
||
A network adapter for WebRTC, based on the point-to-point [MessageChannelNetworkAdapter](https://github.com/automerge/automerge-repo/blob/main/packages/automerge-repo-network-messagechannel/src/index.ts). | ||
|
||
|
||
**Please Note:** This is not an official part of the [automerge-repo](https://github.com/automerge/automerge-repo) project, rather a community contribution that includes a dependency on the [peerjs](https://github.com/peers/peerjs) library. | ||
|
||
## Setup | ||
|
||
``` | ||
yarn add automerge-repo-network-peerjs | ||
``` | ||
|
||
## Licence: MIT | ||
## Usage | ||
|
||
Establish a data connection as per [peerjs](https://github.com/peers/peerjs#data-connections) documentation: | ||
|
||
```ts | ||
import { Peer } from "peerjs"; | ||
const conn = peer.connect("another-peers-id"); | ||
``` | ||
|
||
Then use that to pass into the constructor of the automerge network adapter: | ||
|
||
```ts | ||
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 | ||
to keep track of directional data being sent and received, for example: | ||
|
||
```ts | ||
function monitor(adapter: PeerjsNetworkAdapter, dispose$?: Observable<any>) { | ||
const detach = adapter.onData((e) => console.log(`⚡️ ${e.direction}: ${e.bytes} bytes`)); | ||
dispose$?.subscribe(() => detach()); | ||
} | ||
|
||
``` | ||
|
||
|
||
## Licence | ||
MIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { WebrtcNetworkAdapter } from "./NetworkAdapter.js"; | ||
export { PeerjsNetworkAdapter } from "./NetworkAdapter.js"; | ||
export type { NetworkMessage, NetworkMessageAlert } from "./types.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters