Skip to content

Commit 26d44a4

Browse files
Update Adapter API (#8)
* update refs * Update network adapter for API changes (published 1.2.2) Update notes (from @pvh): https://patchwork.inkandswitch.com/#automerge-repo-network-adapter-api-changes--4RicZ28GjFaTi12xssztkpDjqruu?type=essay * tweak changelog
1 parent ec087e3 commit 26d44a4

File tree

4 files changed

+74
-56
lines changed

4 files changed

+74
-56
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1010
#### Fixed
1111
#### Security
1212

13+
## [1.2.2] - 2024-08-27
14+
#### Changed
15+
- Updates to Network interface (via @pvg, see [notes](https://patchwork.inkandswitch.com/#automerge-repo-network-adapter-api-changes--4RicZ28GjFaTi12xssztkpDjqruu?type=essay))
16+
17+
- Removed emitting "ready" event.
18+
- Implemented `isReady` and `whenReady`
19+
- `disconnect()` already implemented.
20+
1321
## [1.2.1] - 2024-07-27
1422
#### Changed
1523
- Updated refs (automerge-repo)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "automerge-repo-network-peerjs",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "Network adapter for automerge-repo using peerjs",
55
"author": "phil Cockfield",
66
"license": "MIT",
@@ -21,7 +21,7 @@
2121
"eventemitter3": ">=5.0.1",
2222
"peerjs": ">=1.5.4",
2323
"typescript": "5.5.4",
24-
"vitest": "2.0.4"
24+
"vitest": "2.0.5"
2525
},
2626
"publishConfig": {
2727
"access": "public"

src/NetworkAdapter.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,32 @@ export class PeerjsNetworkAdapter
1818
peerId?: t.PeerId;
1919
peerMetadata?: t.PeerMetadata;
2020

21-
#isReady = false;
2221
#conn: t.DataConnection;
2322
#events = new EventEmitter<EventTypes>();
2423

24+
#ready = false;
25+
#readyResolver?: () => void;
26+
#readyPromise: Promise<void> = new Promise<void>((resolve) => (this.#readyResolver = resolve));
27+
#forceReady() {
28+
if (this.#ready) return;
29+
this.#ready = true;
30+
this.#readyResolver?.();
31+
}
32+
2533
constructor(conn: t.DataConnection) {
2634
if (!conn) throw new Error(`A peerjs data-connection is required`);
2735
super();
2836
this.#conn = conn;
2937
}
3038

39+
isReady() {
40+
return this.#ready;
41+
}
42+
43+
whenReady() {
44+
return this.#readyPromise;
45+
}
46+
3147
connect(peerId: t.PeerId, meta?: t.PeerMetadata) {
3248
const senderId = (this.peerId = peerId);
3349
const conn = this.#conn;
@@ -72,7 +88,7 @@ export class PeerjsNetworkAdapter
7288
conn.on("data", handleData);
7389

7490
this.on("peer-disconnected", () => {
75-
this.#isReady = false;
91+
this.#ready = false;
7692
conn.off("open", handleOpen);
7793
conn.off("close", handleClose);
7894
conn.off("data", handleData);
@@ -83,7 +99,7 @@ export class PeerjsNetworkAdapter
8399
* must be something weird going on at the other end to cause us
84100
* to receive no response.
85101
*/
86-
setTimeout(() => this.#setAsReady(), 100);
102+
setTimeout(() => this.#forceReady(), 100);
87103
}
88104

89105
disconnect() {
@@ -117,14 +133,8 @@ export class PeerjsNetworkAdapter
117133
this.#events.emit("data", payload);
118134
}
119135

120-
#setAsReady() {
121-
if (this.#isReady) return;
122-
this.#isReady = true;
123-
this.emit("ready", { network: this });
124-
}
125-
126136
#announceConnection(peerId: t.PeerId, peerMetadata: t.PeerMetadata) {
127-
this.#setAsReady();
137+
this.#forceReady();
128138
this.emit("peer-candidate", { peerId, peerMetadata });
129139
}
130140
}

yarn.lock

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -345,53 +345,53 @@
345345
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4"
346346
integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==
347347

348-
"@vitest/[email protected].4":
349-
version "2.0.4"
350-
resolved "https://registry.yarnpkg.com/@vitest/expect/-/expect-2.0.4.tgz#d365c106c84f2a3aae96000e95be21956acc099c"
351-
integrity sha512-39jr5EguIoanChvBqe34I8m1hJFI4+jxvdOpD7gslZrVQBKhh8H9eD7J/LJX4zakrw23W+dITQTDqdt43xVcJw==
348+
"@vitest/[email protected].5":
349+
version "2.0.5"
350+
resolved "https://registry.yarnpkg.com/@vitest/expect/-/expect-2.0.5.tgz#f3745a6a2c18acbea4d39f5935e913f40d26fa86"
351+
integrity sha512-yHZtwuP7JZivj65Gxoi8upUN2OzHTi3zVfjwdpu2WrvCZPLwsJ2Ey5ILIPccoW23dd/zQBlJ4/dhi7DWNyXCpA==
352352
dependencies:
353-
"@vitest/spy" "2.0.4"
354-
"@vitest/utils" "2.0.4"
353+
"@vitest/spy" "2.0.5"
354+
"@vitest/utils" "2.0.5"
355355
chai "^5.1.1"
356356
tinyrainbow "^1.2.0"
357357

358-
"@vitest/[email protected].4", "@vitest/pretty-format@^2.0.4":
359-
version "2.0.4"
360-
resolved "https://registry.yarnpkg.com/@vitest/pretty-format/-/pretty-format-2.0.4.tgz#9a3934932e7f8ddd836b38c34ddaeec91bd0f82e"
361-
integrity sha512-RYZl31STbNGqf4l2eQM1nvKPXE0NhC6Eq0suTTePc4mtMQ1Fn8qZmjV4emZdEdG2NOWGKSCrHZjmTqDCDoeFBw==
358+
"@vitest/[email protected].5", "@vitest/pretty-format@^2.0.5":
359+
version "2.0.5"
360+
resolved "https://registry.yarnpkg.com/@vitest/pretty-format/-/pretty-format-2.0.5.tgz#91d2e6d3a7235c742e1a6cc50e7786e2f2979b1e"
361+
integrity sha512-h8k+1oWHfwTkyTkb9egzwNMfJAEx4veaPSnMeKbVSjp4euqGSbQlm5+6VHwTr7u4FJslVVsUG5nopCaAYdOmSQ==
362362
dependencies:
363363
tinyrainbow "^1.2.0"
364364

365-
"@vitest/[email protected].4":
366-
version "2.0.4"
367-
resolved "https://registry.yarnpkg.com/@vitest/runner/-/runner-2.0.4.tgz#0b1edb8ab5f81a1c7dfd50090e5e7e971a117891"
368-
integrity sha512-Gk+9Su/2H2zNfNdeJR124gZckd5st4YoSuhF1Rebi37qTXKnqYyFCd9KP4vl2cQHbtuVKjfEKrNJxHHCW8thbQ==
365+
"@vitest/[email protected].5":
366+
version "2.0.5"
367+
resolved "https://registry.yarnpkg.com/@vitest/runner/-/runner-2.0.5.tgz#89197e712bb93513537d6876995a4843392b2a84"
368+
integrity sha512-TfRfZa6Bkk9ky4tW0z20WKXFEwwvWhRY+84CnSEtq4+3ZvDlJyY32oNTJtM7AW9ihW90tX/1Q78cb6FjoAs+ig==
369369
dependencies:
370-
"@vitest/utils" "2.0.4"
370+
"@vitest/utils" "2.0.5"
371371
pathe "^1.1.2"
372372

373-
"@vitest/[email protected].4":
374-
version "2.0.4"
375-
resolved "https://registry.yarnpkg.com/@vitest/snapshot/-/snapshot-2.0.4.tgz#7d7dea9df17c5c13386f1a7a433b99dc0ffe3c14"
376-
integrity sha512-or6Mzoz/pD7xTvuJMFYEtso1vJo1S5u6zBTinfl+7smGUhqybn6VjzCDMhmTyVOFWwkCMuNjmNNxnyXPgKDoPw==
373+
"@vitest/[email protected].5":
374+
version "2.0.5"
375+
resolved "https://registry.yarnpkg.com/@vitest/snapshot/-/snapshot-2.0.5.tgz#a2346bc5013b73c44670c277c430e0334690a162"
376+
integrity sha512-SgCPUeDFLaM0mIUHfaArq8fD2WbaXG/zVXjRupthYfYGzc8ztbFbu6dUNOblBG7XLMR1kEhS/DNnfCZ2IhdDew==
377377
dependencies:
378-
"@vitest/pretty-format" "2.0.4"
378+
"@vitest/pretty-format" "2.0.5"
379379
magic-string "^0.30.10"
380380
pathe "^1.1.2"
381381

382-
"@vitest/[email protected].4":
383-
version "2.0.4"
384-
resolved "https://registry.yarnpkg.com/@vitest/spy/-/spy-2.0.4.tgz#19083386a741a158c2f142beffe43be68b1375cf"
385-
integrity sha512-uTXU56TNoYrTohb+6CseP8IqNwlNdtPwEO0AWl+5j7NelS6x0xZZtP0bDWaLvOfUbaYwhhWp1guzXUxkC7mW7Q==
382+
"@vitest/[email protected].5":
383+
version "2.0.5"
384+
resolved "https://registry.yarnpkg.com/@vitest/spy/-/spy-2.0.5.tgz#590fc07df84a78b8e9dd976ec2090920084a2b9f"
385+
integrity sha512-c/jdthAhvJdpfVuaexSrnawxZz6pywlTPe84LUB2m/4t3rl2fTo9NFGBG4oWgaD+FTgDDV8hJ/nibT7IfH3JfA==
386386
dependencies:
387387
tinyspy "^3.0.0"
388388

389-
"@vitest/[email protected].4":
390-
version "2.0.4"
391-
resolved "https://registry.yarnpkg.com/@vitest/utils/-/utils-2.0.4.tgz#2db1df35aaeb5caa932770a190df636a68d284d5"
392-
integrity sha512-Zc75QuuoJhOBnlo99ZVUkJIuq4Oj0zAkrQ2VzCqNCx6wAwViHEh5Fnp4fiJTE9rA+sAoXRf00Z9xGgfEzV6fzQ==
389+
"@vitest/[email protected].5":
390+
version "2.0.5"
391+
resolved "https://registry.yarnpkg.com/@vitest/utils/-/utils-2.0.5.tgz#6f8307a4b6bc6ceb9270007f73c67c915944e926"
392+
integrity sha512-d8HKbqIcya+GR67mkZbrzhS5kKhtp8dQLcmRZLGTscGVg7yImT82cIrhtn2L8+VujWcy6KZweApgNmPsTAO/UQ==
393393
dependencies:
394-
"@vitest/pretty-format" "2.0.4"
394+
"@vitest/pretty-format" "2.0.5"
395395
estree-walker "^3.0.3"
396396
loupe "^3.1.1"
397397
tinyrainbow "^1.2.0"
@@ -857,10 +857,10 @@ v8-compile-cache-lib@^3.0.1:
857857
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"
858858
integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==
859859

860-
861-
version "2.0.4"
862-
resolved "https://registry.yarnpkg.com/vite-node/-/vite-node-2.0.4.tgz#5600cc9f0d9c3ff9a64050c6858e7e1b62fb3fcd"
863-
integrity sha512-ZpJVkxcakYtig5iakNeL7N3trufe3M6vGuzYAr4GsbCTwobDeyPJpE4cjDhhPluv8OvQCFzu2LWp6GkoKRITXA==
860+
861+
version "2.0.5"
862+
resolved "https://registry.yarnpkg.com/vite-node/-/vite-node-2.0.5.tgz#36d909188fc6e3aba3da5fc095b3637d0d18e27b"
863+
integrity sha512-LdsW4pxj0Ot69FAoXZ1yTnA9bjGohr2yNBU7QKRxpz8ITSkhuDl6h3zS/tvgz4qrNjeRnvrWeXQ8ZF7Um4W00Q==
864864
dependencies:
865865
cac "^6.7.14"
866866
debug "^4.3.5"
@@ -879,18 +879,18 @@ vite@^5.0.0:
879879
optionalDependencies:
880880
fsevents "~2.3.3"
881881

882-
883-
version "2.0.4"
884-
resolved "https://registry.yarnpkg.com/vitest/-/vitest-2.0.4.tgz#ac6bfbaee53e502cee864b07a5b2edf1fcba793e"
885-
integrity sha512-luNLDpfsnxw5QSW4bISPe6tkxVvv5wn2BBs/PuDRkhXZ319doZyLOBr1sjfB5yCEpTiU7xCAdViM8TNVGPwoog==
882+
883+
version "2.0.5"
884+
resolved "https://registry.yarnpkg.com/vitest/-/vitest-2.0.5.tgz#2f15a532704a7181528e399cc5b754c7f335fd62"
885+
integrity sha512-8GUxONfauuIdeSl5f9GTgVEpg5BTOlplET4WEDaeY2QBiN8wSm68vxN/tb5z405OwppfoCavnwXafiaYBC/xOA==
886886
dependencies:
887887
"@ampproject/remapping" "^2.3.0"
888-
"@vitest/expect" "2.0.4"
889-
"@vitest/pretty-format" "^2.0.4"
890-
"@vitest/runner" "2.0.4"
891-
"@vitest/snapshot" "2.0.4"
892-
"@vitest/spy" "2.0.4"
893-
"@vitest/utils" "2.0.4"
888+
"@vitest/expect" "2.0.5"
889+
"@vitest/pretty-format" "^2.0.5"
890+
"@vitest/runner" "2.0.5"
891+
"@vitest/snapshot" "2.0.5"
892+
"@vitest/spy" "2.0.5"
893+
"@vitest/utils" "2.0.5"
894894
chai "^5.1.1"
895895
debug "^4.3.5"
896896
execa "^8.0.1"
@@ -901,7 +901,7 @@ [email protected]:
901901
tinypool "^1.0.0"
902902
tinyrainbow "^1.2.0"
903903
vite "^5.0.0"
904-
vite-node "2.0.4"
904+
vite-node "2.0.5"
905905
why-is-node-running "^2.3.0"
906906

907907
webrtc-adapter@^9.0.0:

0 commit comments

Comments
 (0)