From 18f85b6ff36cc3ff722f34aeeb8a3312bf5884c2 Mon Sep 17 00:00:00 2001 From: Sam Gwilym Date: Tue, 16 May 2023 13:16:49 +0200 Subject: [PATCH] Edit CHANGELOG and README for discovery features --- CHANGELOG.md | 5 ++++- README.md | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e126f672..c6fc5013 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog -## next +## v10.2.0 + +This is a feature release adding APIs to **automatically discover and sync with +peers on the local network**. - (Feature) Added `Peer.discover`, a new method for automatically discovering other peers. How it does that it left to the `DiscoveryService` you provide diff --git a/README.md b/README.md index b9026164..0b0ffb56 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,6 @@ import * as Earthstar from "earthstar"; // Node and browser APIs are namespaced in the NPM distribution: import { ReplicaDriverWeb } from "earthstar/browser"; import { ReplicaDriverSqlite } from "earthstar/node"; - ``` We recommend the browser and Deno versions. This module has been built with many @@ -361,6 +360,28 @@ const allDocsWithAttachments = await replica.addAttachments(allDocs); `attachment` property. The type of this property will either be `DocAttachment`, `undefined`, or `ValidationError`. +## Discovering other peers on the local network + +Earthstar is able to automatically discover other Earthstar peers on the same +network, and in turn advertise itself to others. + +```ts +const discoveryLan = new DiscoveryLAN({ name: "My Computer" }); + +for await (const discoveryEvent of peer.discover(discoveryLan)) { + if (discoveryEvent.kind === "PEER DISCOVERED") { + discoveryEvent.sync(); + } +} +``` + +> On Node, the `DiscoveryLAN` API is exported from "earthstar/node". +> +> On Deno, this feature uses unstable APIs and is not included with the default +> module exports. It can be imported from +> `https://deno.land/x/earthstar/src/discovery/discovery_lan.ts`. Usage also +> requires the `--unstable` flag. + ## Subscribing to replica changes There are many ways to subscribe to the many events a replica generates during