@automerge/automerge-repo-network-messagechannel 1.0.0-alpha.3 → 1.0.0-alpha.4

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
@@ -1,6 +1,7 @@
1
1
  import { type Message, NetworkAdapter, type PeerId } from "@automerge/automerge-repo";
2
2
  import { MessagePortRef } from "./MessagePortRef.js";
3
3
  export declare class MessageChannelNetworkAdapter extends NetworkAdapter {
4
+ #private;
4
5
  channels: {};
5
6
  messagePortRef: MessagePortRef;
6
7
  constructor(messagePort: MessagePort, config?: MessageChannelNetworkAdapterConfig);
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,cAAc,EACd,KAAK,MAAM,EAEZ,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAOpD,qBAAa,4BAA6B,SAAQ,cAAc;IAC9D,QAAQ,KAAK;IACb,cAAc,EAAE,cAAc,CAAA;gBAG5B,WAAW,EAAE,WAAW,EACxB,MAAM,GAAE,kCAAuC;IAWjD,OAAO,CAAC,MAAM,EAAE,MAAM;IAiDtB,IAAI,CAAC,OAAO,EAAE,OAAO;IAmBrB,kBAAkB,CAAC,MAAM,EAAE,MAAM;IAIjC,IAAI;IAOJ,KAAK;CAIN;AAED,UAAU,kCAAkC;IAC1C;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,cAAc,EACd,KAAK,MAAM,EAEZ,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAOpD,qBAAa,4BAA6B,SAAQ,cAAc;;IAC9D,QAAQ,KAAK;IACb,cAAc,EAAE,cAAc,CAAA;gBAI5B,WAAW,EAAE,WAAW,EACxB,MAAM,GAAE,kCAAuC;IAWjD,OAAO,CAAC,MAAM,EAAE,MAAM;IA4DtB,IAAI,CAAC,OAAO,EAAE,OAAO;IAmBrB,kBAAkB,CAAC,MAAM,EAAE,MAAM;IAQjC,IAAI;IAOJ,KAAK;CAIN;AAED,UAAU,kCAAkC;IAC1C;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB"}
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ const log = debug("automerge-repo:messagechannel");
6
6
  export class MessageChannelNetworkAdapter extends NetworkAdapter {
7
7
  channels = {};
8
8
  messagePortRef;
9
+ #startupComplete = false;
9
10
  constructor(messagePort, config = {}) {
10
11
  super();
11
12
  const useWeakRef = config.useWeakRef ?? false;
@@ -52,6 +53,16 @@ export class MessageChannelNetworkAdapter extends NetworkAdapter {
52
53
  this.messagePortRef.addListener("close", () => {
53
54
  this.emit("close");
54
55
  });
56
+ this.join();
57
+ // Mark this messagechannel as ready after 50 ms, at this point there
58
+ // must be something weird going on on the other end to cause us to receive
59
+ // no response
60
+ setTimeout(() => {
61
+ if (!this.#startupComplete) {
62
+ this.#startupComplete = true;
63
+ this.emit("ready", { network: this });
64
+ }
65
+ }, 100);
55
66
  }
56
67
  send(message) {
57
68
  if ("data" in message) {
@@ -66,6 +77,10 @@ export class MessageChannelNetworkAdapter extends NetworkAdapter {
66
77
  }
67
78
  }
68
79
  announceConnection(peerId) {
80
+ if (!this.#startupComplete) {
81
+ this.#startupComplete = true;
82
+ this.emit("ready", { network: this });
83
+ }
69
84
  this.emit("peer-candidate", { peerId });
70
85
  }
71
86
  join() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automerge/automerge-repo-network-messagechannel",
3
- "version": "1.0.0-alpha.3",
3
+ "version": "1.0.0-alpha.4",
4
4
  "description": "MessageChannel network adapter for Automerge Repo",
5
5
  "repository": "https://github.com/automerge/automerge-repo",
6
6
  "author": "Peter van Hardenberg <pvh@pvh.ca>",
@@ -14,10 +14,10 @@
14
14
  "test": "mocha --no-warnings --experimental-specifier-resolution=node --exit"
15
15
  },
16
16
  "dependencies": {
17
- "@automerge/automerge-repo": "^1.0.0-alpha.3"
17
+ "@automerge/automerge-repo": "^1.0.0-alpha.4"
18
18
  },
19
19
  "peerDependencies": {
20
- "@automerge/automerge": "^2.1.0-alpha.10"
20
+ "@automerge/automerge": "^2.1.0-alpha.12"
21
21
  },
22
22
  "watch": {
23
23
  "build": {
@@ -30,5 +30,5 @@
30
30
  "publishConfig": {
31
31
  "access": "public"
32
32
  },
33
- "gitHead": "0ed108273084319aeea64ceccb49c3d58709f107"
33
+ "gitHead": "fbf71f0c3aaa2786a4e279f336f01d665f53ce5b"
34
34
  }
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ const log = debug("automerge-repo:messagechannel")
14
14
  export class MessageChannelNetworkAdapter extends NetworkAdapter {
15
15
  channels = {}
16
16
  messagePortRef: MessagePortRef
17
+ #startupComplete = false
17
18
 
18
19
  constructor(
19
20
  messagePort: MessagePort,
@@ -75,6 +76,17 @@ export class MessageChannelNetworkAdapter extends NetworkAdapter {
75
76
  this.messagePortRef.addListener("close", () => {
76
77
  this.emit("close")
77
78
  })
79
+ this.join()
80
+
81
+ // Mark this messagechannel as ready after 50 ms, at this point there
82
+ // must be something weird going on on the other end to cause us to receive
83
+ // no response
84
+ setTimeout(() => {
85
+ if (!this.#startupComplete) {
86
+ this.#startupComplete = true
87
+ this.emit("ready", { network: this })
88
+ }
89
+ }, 100)
78
90
  }
79
91
 
80
92
  send(message: Message) {
@@ -97,6 +109,10 @@ export class MessageChannelNetworkAdapter extends NetworkAdapter {
97
109
  }
98
110
 
99
111
  announceConnection(peerId: PeerId) {
112
+ if (!this.#startupComplete) {
113
+ this.#startupComplete = true
114
+ this.emit("ready", { network: this })
115
+ }
100
116
  this.emit("peer-candidate", { peerId })
101
117
  }
102
118
 
@@ -1,5 +1,5 @@
1
- import { runAdapterTests } from "../../automerge-repo/src/helpers/tests/network-adapter-tests"
2
- import { MessageChannelNetworkAdapter as Adapter } from "../src"
1
+ import { runAdapterTests } from "../../automerge-repo/src/helpers/tests/network-adapter-tests.js"
2
+ import { MessageChannelNetworkAdapter as Adapter } from "../src/index.js"
3
3
 
4
4
  // bob is the hub, alice and charlie are spokes
5
5
  describe("MessageChannelNetworkAdapter", () => {
package/tsconfig.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "compilerOptions": {
3
3
  "target": "ESNext",
4
4
  "jsx": "react",
5
- "module": "ESNext",
6
- "moduleResolution": "node",
5
+ "module": "NodeNext",
6
+ "moduleResolution": "Node16",
7
7
  "declaration": true,
8
8
  "declarationMap": true,
9
9
  "outDir": "./dist",