@fairfox/polly 0.73.1 → 0.74.1

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/src/mesh.js CHANGED
@@ -1563,10 +1563,9 @@ class MeshSignalingClient {
1563
1563
 
1564
1564
  // src/shared/lib/mesh-state.ts
1565
1565
  import {
1566
- Automerge as Automerge3,
1567
- interpretAsDocumentId
1566
+ Automerge as Automerge3
1568
1567
  } from "@automerge/automerge-repo/slim";
1569
- import nacl3 from "tweetnacl";
1568
+ import nacl4 from "tweetnacl";
1570
1569
 
1571
1570
  // src/shared/lib/crdt-specialised.ts
1572
1571
  import { Automerge, Counter, updateText } from "@automerge/automerge-repo/slim";
@@ -2041,6 +2040,19 @@ function fieldEquals(a, b) {
2041
2040
  }
2042
2041
  }
2043
2042
 
2043
+ // src/shared/lib/derive-document-id.ts
2044
+ import {
2045
+ interpretAsDocumentId
2046
+ } from "@automerge/automerge-repo/slim";
2047
+ import nacl3 from "tweetnacl";
2048
+ var DOC_ID_DOMAIN = "polly/meshState/v1";
2049
+ var keyEncoder = new TextEncoder;
2050
+ function deriveDocumentId(key) {
2051
+ const digest = nacl3.hash(keyEncoder.encode(`${DOC_ID_DOMAIN}:${key}`));
2052
+ const bytes = digest.slice(0, 16);
2053
+ return interpretAsDocumentId(bytes);
2054
+ }
2055
+
2044
2056
  // src/shared/lib/mesh-state.ts
2045
2057
  var defaultRepo;
2046
2058
  var MESH_STATE_MODULE_ID = `mesh-state-${typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : Math.random().toString(36).slice(2) + Date.now().toString(36)}`;
@@ -2163,13 +2175,7 @@ function resolveRepo(option) {
2163
2175
  }
2164
2176
  return repo;
2165
2177
  }
2166
- var DOC_ID_DOMAIN = "polly/meshState/v1";
2167
- var keyEncoder = new TextEncoder;
2168
- function deriveDocumentId(key) {
2169
- const digest = nacl3.hash(keyEncoder.encode(`${DOC_ID_DOMAIN}:${key}`));
2170
- const bytes = digest.slice(0, 16);
2171
- return interpretAsDocumentId(bytes);
2172
- }
2178
+ var keyEncoder2 = new TextEncoder;
2173
2179
  var docIdResolver;
2174
2180
  function registerDocIdResolver(resolver) {
2175
2181
  docIdResolver = resolver;
@@ -2235,7 +2241,7 @@ function buildHandleFactory(repo, key, initialDoc) {
2235
2241
  var SEED_ACTOR_DOMAIN = "polly/meshState/seedActor/v1";
2236
2242
  function deriveSeedActor(documentId) {
2237
2243
  const docIdString = documentId;
2238
- const digest = nacl3.hash(keyEncoder.encode(`${SEED_ACTOR_DOMAIN}:${docIdString}`));
2244
+ const digest = nacl4.hash(keyEncoder2.encode(`${SEED_ACTOR_DOMAIN}:${docIdString}`));
2239
2245
  let hex = "";
2240
2246
  for (let i = 0;i < 16; i++) {
2241
2247
  hex += (digest[i] ?? 0).toString(16).padStart(2, "0");
@@ -2696,6 +2702,7 @@ class MeshWebRTCAdapter extends NetworkAdapter2 {
2696
2702
  }
2697
2703
  handlePeerJoined(remotePeerId) {
2698
2704
  this.presentPeers.add(remotePeerId);
2705
+ this.evictStaleSlotForRejoin(remotePeerId);
2699
2706
  if (!this.shouldInitiateTo(remotePeerId))
2700
2707
  return;
2701
2708
  this.tryCreateInitiatingSlot(remotePeerId);
@@ -2703,11 +2710,24 @@ class MeshWebRTCAdapter extends NetworkAdapter2 {
2703
2710
  handlePeersPresent(peerIds) {
2704
2711
  for (const remotePeerId of peerIds) {
2705
2712
  this.presentPeers.add(remotePeerId);
2713
+ this.evictStaleSlotForRejoin(remotePeerId);
2706
2714
  if (!this.shouldInitiateTo(remotePeerId))
2707
2715
  continue;
2708
2716
  this.tryCreateInitiatingSlot(remotePeerId);
2709
2717
  }
2710
2718
  }
2719
+ evictStaleSlotForRejoin(remotePeerId) {
2720
+ const slot = this.slots.get(remotePeerId);
2721
+ if (!slot)
2722
+ return;
2723
+ const state = slot.connection.connectionState;
2724
+ if (state === "connected" && slot.channel?.readyState === "open")
2725
+ return;
2726
+ if (this.slotNeverConnectedTimeoutMs > 0 && (state === "new" || state === "connecting") && performance.now() - slot.createdAt < this.slotNeverConnectedTimeoutMs) {
2727
+ return;
2728
+ }
2729
+ this.tearDownWedgedSlot(remotePeerId);
2730
+ }
2711
2731
  tryCreateInitiatingSlot(remotePeerId) {
2712
2732
  try {
2713
2733
  this.createInitiatingSlot(remotePeerId);
@@ -4290,4 +4310,4 @@ export {
4290
4310
  $meshCounter
4291
4311
  };
4292
4312
 
4293
- //# debugId=E57D210FDE704BCC64756E2164756E21
4313
+ //# debugId=0D84EA4EDCC2765464756E2164756E21