@automerge/automerge-repo-network-broadcastchannel 1.1.0-alpha.1 → 1.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -13,14 +13,14 @@
13
13
  * @module
14
14
  *
15
15
  */
16
- import { NetworkAdapter, type Message, type PeerId, type StorageId } from "@automerge/automerge-repo";
16
+ import { NetworkAdapter, type Message, type PeerId, type PeerMetadata } from "@automerge/automerge-repo";
17
17
  export type BroadcastChannelNetworkAdapterOptions = {
18
18
  channelName: string;
19
19
  };
20
20
  export declare class BroadcastChannelNetworkAdapter extends NetworkAdapter {
21
21
  #private;
22
22
  constructor(options?: BroadcastChannelNetworkAdapterOptions);
23
- connect(peerId: PeerId, storageId: StorageId | undefined, isEphemeral: boolean): void;
23
+ connect(peerId: PeerId, peerMetadata: PeerMetadata): void;
24
24
  send(message: Message): void;
25
25
  disconnect(): void;
26
26
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,cAAc,EACd,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,SAAS,EACf,MAAM,2BAA2B,CAAA;AAElC,MAAM,MAAM,qCAAqC,GAAG;IAClD,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,qBAAa,8BAA+B,SAAQ,cAAc;;gBAKpD,OAAO,CAAC,EAAE,qCAAqC;IAK3D,OAAO,CACL,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,GAAG,SAAS,EAChC,WAAW,EAAE,OAAO;IA0DtB,IAAI,CAAC,OAAO,EAAE,OAAO;IAcrB,UAAU;CAIX"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,cAAc,EACd,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,YAAY,EAClB,MAAM,2BAA2B,CAAA;AAElC,MAAM,MAAM,qCAAqC,GAAG;IAClD,WAAW,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,qBAAa,8BAA+B,SAAQ,cAAc;;gBAKpD,OAAO,CAAC,EAAE,qCAAqC;IAK3D,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY;IAqDlD,IAAI,CAAC,OAAO,EAAE,OAAO;IAcrB,UAAU;CAIX"}
package/dist/index.js CHANGED
@@ -21,9 +21,9 @@ export class BroadcastChannelNetworkAdapter extends NetworkAdapter {
21
21
  super();
22
22
  this.#options = { channelName: "broadcast", ...(options ?? {}) };
23
23
  }
24
- connect(peerId, storageId, isEphemeral) {
24
+ connect(peerId, peerMetadata) {
25
25
  this.peerId = peerId;
26
- this.storageId = storageId;
26
+ this.peerMetadata = peerMetadata;
27
27
  this.#broadcastChannel = new BroadcastChannel(this.#options.channelName);
28
28
  this.#broadcastChannel.addEventListener("message", (e) => {
29
29
  const message = e.data;
@@ -38,10 +38,10 @@ export class BroadcastChannelNetworkAdapter extends NetworkAdapter {
38
38
  targetId: senderId,
39
39
  type: "welcome",
40
40
  });
41
- this.#announceConnection(senderId, storageId, isEphemeral);
41
+ this.#announceConnection(senderId, peerMetadata);
42
42
  break;
43
43
  case "welcome":
44
- this.#announceConnection(senderId, storageId, isEphemeral);
44
+ this.#announceConnection(senderId, peerMetadata);
45
45
  break;
46
46
  default:
47
47
  if (!("data" in message)) {
@@ -62,8 +62,8 @@ export class BroadcastChannelNetworkAdapter extends NetworkAdapter {
62
62
  });
63
63
  this.emit("ready", { network: this });
64
64
  }
65
- #announceConnection(peerId, storageId, isEphemeral) {
66
- this.emit("peer-candidate", { peerId, storageId, isEphemeral });
65
+ #announceConnection(peerId, peerMetadata) {
66
+ this.emit("peer-candidate", { peerId, peerMetadata });
67
67
  }
68
68
  send(message) {
69
69
  if ("data" in message) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automerge/automerge-repo-network-broadcastchannel",
3
- "version": "1.1.0-alpha.1",
3
+ "version": "1.1.0-alpha.2",
4
4
  "description": "BroadcastChannel network adapter for Automerge Repo",
5
5
  "repository": "https://github.com/automerge/automerge-repo/tree/master/packages/automerge-repo-network-broadcastchannel",
6
6
  "author": "Peter van Hardenberg <pvh@pvh.ca>",
@@ -13,7 +13,7 @@
13
13
  "test": "vitest"
14
14
  },
15
15
  "dependencies": {
16
- "@automerge/automerge-repo": "^1.1.0-alpha.1"
16
+ "@automerge/automerge-repo": "^1.1.0-alpha.2"
17
17
  },
18
18
  "watch": {
19
19
  "build": {
@@ -26,5 +26,5 @@
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
- "gitHead": "11805d698f860bd6ffb3ca028d3b57e718690b5a"
29
+ "gitHead": "d73e71588c3835a172fdf4d19e56a1f946c041ed"
30
30
  }
package/src/index.ts CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  NetworkAdapter,
19
19
  type Message,
20
20
  type PeerId,
21
- type StorageId,
21
+ type PeerMetadata,
22
22
  } from "@automerge/automerge-repo"
23
23
 
24
24
  export type BroadcastChannelNetworkAdapterOptions = {
@@ -35,13 +35,9 @@ export class BroadcastChannelNetworkAdapter extends NetworkAdapter {
35
35
  this.#options = { channelName: "broadcast", ...(options ?? {}) }
36
36
  }
37
37
 
38
- connect(
39
- peerId: PeerId,
40
- storageId: StorageId | undefined,
41
- isEphemeral: boolean
42
- ) {
38
+ connect(peerId: PeerId, peerMetadata: PeerMetadata) {
43
39
  this.peerId = peerId
44
- this.storageId = storageId
40
+ this.peerMetadata = peerMetadata
45
41
  this.#broadcastChannel = new BroadcastChannel(this.#options.channelName)
46
42
 
47
43
  this.#broadcastChannel.addEventListener(
@@ -61,10 +57,10 @@ export class BroadcastChannelNetworkAdapter extends NetworkAdapter {
61
57
  targetId: senderId,
62
58
  type: "welcome",
63
59
  })
64
- this.#announceConnection(senderId, storageId, isEphemeral)
60
+ this.#announceConnection(senderId, peerMetadata)
65
61
  break
66
62
  case "welcome":
67
- this.#announceConnection(senderId, storageId, isEphemeral)
63
+ this.#announceConnection(senderId, peerMetadata)
68
64
  break
69
65
  default:
70
66
  if (!("data" in message)) {
@@ -88,12 +84,8 @@ export class BroadcastChannelNetworkAdapter extends NetworkAdapter {
88
84
  this.emit("ready", { network: this })
89
85
  }
90
86
 
91
- #announceConnection(
92
- peerId: PeerId,
93
- storageId: StorageId | undefined,
94
- isEphemeral: boolean
95
- ) {
96
- this.emit("peer-candidate", { peerId, storageId, isEphemeral })
87
+ #announceConnection(peerId: PeerId, peerMetadata: PeerMetadata) {
88
+ this.emit("peer-candidate", { peerId, peerMetadata })
97
89
  }
98
90
 
99
91
  send(message: Message) {
@@ -123,12 +115,8 @@ type ArriveMessage = {
123
115
  /** The peer ID of the sender of this message */
124
116
  senderId: PeerId
125
117
 
126
- /** Unique ID of the storage that the sender peer is using, is persistent across sessions */
127
- storageId?: StorageId
128
-
129
- /** Indicates whether other peers should persist the sync state of the sender peer.
130
- * Sync state is only persisted for non-ephemeral peers */
131
- isEphemeral: boolean
118
+ /** The peer metadata of the sender of this message */
119
+ peerMetadata: PeerMetadata
132
120
 
133
121
  /** Arrive messages don't have a targetId */
134
122
  targetId: never
@@ -141,12 +129,8 @@ type WelcomeMessage = {
141
129
  /** The peer ID of the recipient sender this message */
142
130
  senderId: PeerId
143
131
 
144
- /** Unique ID of the storage that the sender peer is using, is persistent across sessions */
145
- storageId?: StorageId
146
-
147
- /** Indicates whether other peers should persist the sync state of the sender peer.
148
- * Sync state is only persisted for non-ephemeral peers */
149
- isEphemeral: boolean
132
+ /** The peer metadata of the sender of this message */
133
+ peerMetadata: PeerMetadata
150
134
 
151
135
  /** The peer ID of the recipient of this message */
152
136
  targetId: PeerId