@leofcoin/peernet 1.2.21 → 1.2.23

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.
@@ -1,4 +1,4 @@
1
- import { i as getDefaultExportFromCjs } from './identity-BeVZQ2Dp.js';
1
+ import { m as getDefaultExportFromCjs } from './identity-BS_eDrwh.js';
2
2
 
3
3
  function _mergeNamespaces(n, m) {
4
4
  m.forEach(function (e) {
@@ -1,4 +1,4 @@
1
- import { i as getDefaultExportFromCjs } from './identity-BeVZQ2Dp.js';
1
+ import { m as getDefaultExportFromCjs } from './identity-BS_eDrwh.js';
2
2
 
3
3
  function _mergeNamespaces(n, m) {
4
4
  m.forEach(function (e) {
@@ -1,5 +1,5 @@
1
- import { L as LittlePubSub, d as deflate_1, i as inflate_1, c as createDebugger } from './peernet-DFiLLjUD.js';
2
- import './identity-BeVZQ2Dp.js';
1
+ import { L as LittlePubSub, d as deflate_1, i as inflate_1, c as createDebugger } from './peernet-CgU-ZdIe.js';
2
+ import './identity-BS_eDrwh.js';
3
3
  import 'crypto';
4
4
  import './value-C3vAp-wb.js';
5
5
 
@@ -232,7 +232,7 @@ class SocketRequestClient {
232
232
  const init = async () => {
233
233
  // @ts-ignore
234
234
  if (!globalThis.WebSocket && !this.#experimentalWebsocket)
235
- globalThis.WebSocket = (await import('./browser-8BFql6K9.js').then(function (n) { return n.b; })).default.w3cwebsocket;
235
+ globalThis.WebSocket = (await import('./browser-BKlRwB0A.js').then(function (n) { return n.b; })).default.w3cwebsocket;
236
236
  const client = new WebSocket(this.#url, this.#protocol);
237
237
  if (this.#experimentalWebsocket) {
238
238
  client.addEventListener('error', this.onerror);
@@ -1303,7 +1303,7 @@ class Client {
1303
1303
  }
1304
1304
  }
1305
1305
  async #loadNodeWebrtcImplementation() {
1306
- const koushWrtcModule = await import('./browser-FVp_QbaL.js').then(function (n) { return n.b; });
1306
+ const koushWrtcModule = await import('./browser-Dx3X9MHO.js').then(function (n) { return n.b; });
1307
1307
  const koushWrtc = koushWrtcModule.default;
1308
1308
  if (!isWrtcImplementation(koushWrtc)) {
1309
1309
  throw new Error('@koush/wrtc does not match required wrtc contract');
@@ -1854,14 +1854,15 @@ class Client {
1854
1854
  return peer;
1855
1855
  };
1856
1856
  #peerJoined = async ({ peerId, version, transport }, star) => {
1857
- // check if peer rejoined before the previous connection closed
1858
- if (this.#connections[peerId]) {
1859
- this.#connections[peerId].destroy();
1860
- delete this.#connections[peerId];
1861
- }
1862
1857
  if (this.peerId === peerId)
1863
1858
  return;
1864
- this.#startPeerTransportAttempt(peerId, star, version, true, transport);
1859
+ // Stars can announce the same peer more than once while its transport is
1860
+ // still negotiating. Keep that connection/attempt alive; destroying it
1861
+ // here makes simultaneous joins continually reset each other.
1862
+ // Both sides receive the discovery event. Elect exactly one offerer so
1863
+ // simultaneous joins do not create competing channels/SDP negotiations.
1864
+ const initiator = String(this.peerId) < String(peerId);
1865
+ this.#startPeerTransportAttempt(peerId, star, version, initiator, transport);
1865
1866
  debug(`peer ${peerId} joined`);
1866
1867
  };
1867
1868
  #inComingSignal = async ({ from, signal, channelName, version }, star) => {
@@ -1927,12 +1928,16 @@ class Client {
1927
1928
  });
1928
1929
  };
1929
1930
  #peerClose = (peer) => {
1931
+ // A failed transport can finish closing after fallback has already placed a
1932
+ // replacement in the connection map. Never let that stale close delete or
1933
+ // advance the replacement's active attempt.
1934
+ if (this.#connections[peer.peerId] !== peer) {
1935
+ debug(`ignored stale close for ${peer.peerId}`);
1936
+ return;
1937
+ }
1930
1938
  const wasConnected = peer.connected;
1931
1939
  this.#peerTransportKinds.delete(peer.peerId);
1932
- if (this.#connections[peer.peerId]) {
1933
- peer.destroy();
1934
- delete this.#connections[peer.peerId];
1935
- }
1940
+ delete this.#connections[peer.peerId];
1936
1941
  if (!wasConnected && this.#peerTransportAttempts.has(peer.peerId)) {
1937
1942
  this.#advanceTransportAttempt(peer.peerId);
1938
1943
  }