@automerge/automerge-repo-network-broadcastchannel 1.0.13 → 1.0.16
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 +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
- package/src/index.ts +27 -8
package/dist/index.d.ts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* @module
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
|
-
import { NetworkAdapter, PeerId
|
|
16
|
+
import { Message, NetworkAdapter, PeerId } from "@automerge/automerge-repo";
|
|
17
17
|
export type BroadcastChannelNetworkAdapterOptions = {
|
|
18
18
|
channelName: string;
|
|
19
19
|
};
|
|
@@ -21,7 +21,7 @@ export declare class BroadcastChannelNetworkAdapter extends NetworkAdapter {
|
|
|
21
21
|
#private;
|
|
22
22
|
constructor(options?: BroadcastChannelNetworkAdapterOptions);
|
|
23
23
|
connect(peerId: PeerId): void;
|
|
24
|
-
send(message:
|
|
24
|
+
send(message: Message): void;
|
|
25
25
|
disconnect(): void;
|
|
26
26
|
}
|
|
27
27
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AAE3E,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;IAoDtB,IAAI,CAAC,OAAO,EAAE,OAAO;IAcrB,UAAU;CAIX"}
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@automerge/automerge-repo-network-broadcastchannel",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
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>",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"@automerge/automerge": "^2.1.5"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@automerge/automerge-repo": "^1.0.
|
|
19
|
+
"@automerge/automerge-repo": "^1.0.16"
|
|
20
20
|
},
|
|
21
21
|
"watch": {
|
|
22
22
|
"build": {
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"publishConfig": {
|
|
30
30
|
"access": "public"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "d8334e6a3c2a8eb980fc78511c3d9672009cd6cb"
|
|
33
33
|
}
|
package/src/index.ts
CHANGED
|
@@ -14,12 +14,7 @@
|
|
|
14
14
|
*
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
import {
|
|
18
|
-
Message,
|
|
19
|
-
NetworkAdapter,
|
|
20
|
-
PeerId,
|
|
21
|
-
RepoMessage,
|
|
22
|
-
} from "@automerge/automerge-repo"
|
|
17
|
+
import { Message, NetworkAdapter, PeerId } from "@automerge/automerge-repo"
|
|
23
18
|
|
|
24
19
|
export type BroadcastChannelNetworkAdapterOptions = {
|
|
25
20
|
channelName: string
|
|
@@ -41,7 +36,7 @@ export class BroadcastChannelNetworkAdapter extends NetworkAdapter {
|
|
|
41
36
|
|
|
42
37
|
this.#broadcastChannel.addEventListener(
|
|
43
38
|
"message",
|
|
44
|
-
(e: { data:
|
|
39
|
+
(e: { data: BroadcastChannelMessage }) => {
|
|
45
40
|
const message = e.data
|
|
46
41
|
if ("targetId" in message && message.targetId !== this.peerId) {
|
|
47
42
|
return
|
|
@@ -87,7 +82,7 @@ export class BroadcastChannelNetworkAdapter extends NetworkAdapter {
|
|
|
87
82
|
this.emit("peer-candidate", { peerId })
|
|
88
83
|
}
|
|
89
84
|
|
|
90
|
-
send(message:
|
|
85
|
+
send(message: Message) {
|
|
91
86
|
if ("data" in message) {
|
|
92
87
|
this.#broadcastChannel.postMessage({
|
|
93
88
|
...message,
|
|
@@ -106,3 +101,27 @@ export class BroadcastChannelNetworkAdapter extends NetworkAdapter {
|
|
|
106
101
|
throw new Error("Unimplemented: leave on BroadcastChannelNetworkAdapter")
|
|
107
102
|
}
|
|
108
103
|
}
|
|
104
|
+
|
|
105
|
+
/** Notify the network that we have arrived so everyone knows our peer ID */
|
|
106
|
+
type ArriveMessage = {
|
|
107
|
+
type: "arrive"
|
|
108
|
+
|
|
109
|
+
/** The peer ID of the sender of this message */
|
|
110
|
+
senderId: PeerId
|
|
111
|
+
|
|
112
|
+
/** Arrive messages don't have a targetId */
|
|
113
|
+
targetId: never
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** Respond to an arriving peer with our peer ID */
|
|
117
|
+
type WelcomeMessage = {
|
|
118
|
+
type: "welcome"
|
|
119
|
+
|
|
120
|
+
/** The peer ID of the recipient sender this message */
|
|
121
|
+
senderId: PeerId
|
|
122
|
+
|
|
123
|
+
/** The peer ID of the recipient of this message */
|
|
124
|
+
targetId: PeerId
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
type BroadcastChannelMessage = ArriveMessage | WelcomeMessage | Message
|