@leofcoin/peernet 1.1.100 → 1.1.102

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 { L as LittlePubSub } from './peernet-CP4375lb.js';
1
+ import { L as LittlePubSub } from './peernet-sNy5OxPV.js';
2
2
  import './identity-Cn0iQbY3.js';
3
3
  import './value-C3vAp-wb.js';
4
4
 
@@ -428,7 +428,6 @@ class Client {
428
428
  #connections = {};
429
429
  #stars = {};
430
430
  #starListeners = {};
431
- #handlersSetup = false;
432
431
  #reinitLock = null;
433
432
  #connectEvent = 'peer:connected';
434
433
  #retryOptions = { retries: 5, factor: 2, minTimeout: 1000, maxTimeout: 30000 };
@@ -451,15 +450,6 @@ class Client {
451
450
  getPeer(peerId) {
452
451
  return this.#connections[peerId];
453
452
  }
454
- /**
455
- *
456
- * @param options {object}
457
- * @param options.peerId {string}
458
- * @param options.networkVersion {string}
459
- * @param options.version {string}
460
- * @param options.stars {string[]}
461
- * @param options.connectEvent {string} defaults to peer:connected, can be renamed to handle different protocols, like peer:discovered (setup peer props before fireing the connect event)
462
- */
463
453
  constructor(options) {
464
454
  const { peerId, networkVersion, version, connectEvent, stars } = {
465
455
  ...defaultOptions,
@@ -486,7 +476,6 @@ class Client {
486
476
  debug('reinit: start');
487
477
  try {
488
478
  await this.close();
489
- // clear internal maps so setupStar starts fresh
490
479
  this.#stars = {};
491
480
  this.#connections = {};
492
481
  for (const star of this.starsConfig) {
@@ -495,8 +484,7 @@ class Client {
495
484
  }
496
485
  catch (e) {
497
486
  // If last star fails and none connected, surface error
498
- if (this.starsConfig.indexOf(star) === this.starsConfig.length - 1 &&
499
- Object.keys(this.#stars).length === 0)
487
+ if (Object.keys(this.#stars).length === 0)
500
488
  throw new Error(`No star available to connect`);
501
489
  }
502
490
  }
@@ -538,7 +526,6 @@ class Client {
538
526
  throw lastErr;
539
527
  }
540
528
  async _init() {
541
- // reconnectJob()
542
529
  if (!globalThis.RTCPeerConnection)
543
530
  globalThis.wrtc = (await import('./browser-Cjcx-T47.js').then(function (n) { return n.b; })).default;
544
531
  for (const star of this.starsConfig) {
@@ -561,8 +548,6 @@ class Client {
561
548
  else {
562
549
  globalThis.addEventListener('beforeunload', this.close.bind(this));
563
550
  }
564
- // Setup resume/sleep detection so we can reinit connections after wake
565
- this._setupResumeHandler();
566
551
  }
567
552
  setupStarListeners(starConnection, starId) {
568
553
  // create stable references to handlers so we can unsubscribe later
@@ -584,46 +569,6 @@ class Client {
584
569
  { topic: 'signal', handler: onSignal }
585
570
  ];
586
571
  }
587
- _setupResumeHandler() {
588
- if (this.#handlersSetup)
589
- return;
590
- this.#handlersSetup = true;
591
- const THRESHOLD = 10 * 1000; // 10s gap indicates sleep/wake
592
- let last = Date.now();
593
- const check = () => {
594
- const now = Date.now();
595
- const delta = now - last;
596
- last = now;
597
- if (delta > THRESHOLD) {
598
- debug(`resume detected (gap ${delta}ms)`);
599
- this.reinit().catch((e) => debug('reinit error', e));
600
- }
601
- };
602
- // Start interval checker
603
- const iv = setInterval(check, 2000);
604
- // Browser specific events
605
- if (typeof document !== 'undefined' && document.addEventListener) {
606
- document.addEventListener('visibilitychange', () => {
607
- if (document.visibilityState === 'visible') {
608
- // small delay to let timers update
609
- setTimeout(() => check(), 50);
610
- }
611
- });
612
- window.addEventListener('online', () => setTimeout(() => check(), 50));
613
- }
614
- // Node: listen for SIGCONT (process continued) as well
615
- if (globalThis.process?.on) {
616
- try {
617
- process.on('SIGCONT', () => setTimeout(() => check(), 50));
618
- }
619
- catch (e) {
620
- // ignore
621
- }
622
- }
623
- // keep reference so it can be cleared on close
624
- // @ts-ignore
625
- this._resumeInterval = iv;
626
- }
627
572
  #starJoined = (id) => {
628
573
  if (this.#stars[id]) {
629
574
  this.#stars[id].close(0);
@@ -719,6 +664,7 @@ class Client {
719
664
  debug(`peer ${from} already connected`);
720
665
  return;
721
666
  }
667
+ // peer.channels[channelName]
722
668
  if (String(peer.channelName) !== String(channelName)) {
723
669
  console.warn(`channelNames don't match: got ${peer.channelName}, expected: ${channelName}.`);
724
670
  // Destroy the existing peer connection
@@ -742,7 +688,8 @@ class Client {
742
688
  to: peer.peerId,
743
689
  channelName: peer.channelName,
744
690
  version,
745
- signal
691
+ signal,
692
+ initiator: peer.initiator
746
693
  }
747
694
  });
748
695
  };
@@ -799,35 +746,30 @@ class Client {
799
746
  peer.destroy();
800
747
  };
801
748
  async close() {
802
- // clear resume interval if set
803
- // @ts-ignore
804
- if (this._resumeInterval) {
805
- // @ts-ignore
806
- clearInterval(this._resumeInterval);
807
- // @ts-ignore
808
- this._resumeInterval = null;
749
+ for (const peerId in this.#connections) {
750
+ const peer = this.#connections[peerId];
751
+ if (peer) {
752
+ peer.destroy();
753
+ delete this.#connections[peerId];
754
+ }
809
755
  }
810
756
  for (const star in this.#stars) {
811
- if (this.#stars[star].connectionState() === 'open') {
812
- await this.#stars[star].send({ url: 'leave', params: this.peerId });
813
- // unsubscribe handlers we registered earlier
814
- const listeners = this.#starListeners[star];
815
- if (listeners && listeners.length) {
816
- for (const { topic, handler } of listeners) {
817
- try {
818
- this.#stars[star].pubsub.unsubscribe(topic, handler);
819
- }
820
- catch (e) {
821
- // ignore
822
- }
757
+ // unsubscribe handlers we registered earlier
758
+ const listeners = this.#starListeners[star];
759
+ if (listeners && listeners.length) {
760
+ for (const { topic, handler } of listeners) {
761
+ try {
762
+ this.#stars[star].pubsub.unsubscribe(topic, handler);
763
+ }
764
+ catch (e) {
765
+ // ignore
823
766
  }
824
767
  }
825
768
  }
769
+ if (this.#stars[star].connectionState() === 'open') {
770
+ await this.#stars[star].send({ url: 'leave', params: this.peerId });
771
+ }
826
772
  }
827
- // Ensure we wait for all peer and star close/destroy operations.
828
- // Previous code passed an array of arrays to Promise.allSettled which
829
- // resolves immediately; flatten into a single array of promises (or
830
- // values) so we actually wait for async close operations.
831
773
  const peerClosers = Object.values(this.#connections).map((connection) => {
832
774
  try {
833
775
  // destroy() may be sync or return a promise
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './peernet-CP4375lb.js';
1
+ import { F as FormatInterface } from './peernet-sNy5OxPV.js';
2
2
  import './identity-Cn0iQbY3.js';
3
3
  import './value-C3vAp-wb.js';
4
4
 
@@ -8366,7 +8366,7 @@ class Peernet {
8366
8366
  this.root = options.root;
8367
8367
  const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile
8368
8368
  // FolderMessageResponse
8369
- } = await import(/* webpackChunkName: "messages" */ './messages-Bx4w-Pqo.js');
8369
+ } = await import(/* webpackChunkName: "messages" */ './messages-C3VxYRj3.js');
8370
8370
  /**
8371
8371
  * proto Object containing protos
8372
8372
  * @type {Object}
@@ -8460,7 +8460,7 @@ class Peernet {
8460
8460
  if (this.#starting || this.#started)
8461
8461
  return;
8462
8462
  this.#starting = true;
8463
- const importee = await import('./client-DgmVTCEc.js');
8463
+ const importee = await import('./client-bgSiSUVr.js');
8464
8464
  /**
8465
8465
  * @access public
8466
8466
  * @type {PeernetClient}
@@ -1,3 +1,3 @@
1
- export { P as default } from './peernet-CP4375lb.js';
1
+ export { P as default } from './peernet-sNy5OxPV.js';
2
2
  import './identity-Cn0iQbY3.js';
3
3
  import './value-C3vAp-wb.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "1.1.100",
3
+ "version": "1.1.102",
4
4
  "description": "",
5
5
  "browser": "./exports/browser/peernet.js",
6
6
  "exports": {
@@ -37,7 +37,7 @@
37
37
  "@leofcoin/identity-utils": "^1.0.2",
38
38
  "@leofcoin/multi-wallet": "^3.1.8",
39
39
  "@leofcoin/storage": "^3.5.38",
40
- "@netpeer/swarm": "^0.8.30",
40
+ "@netpeer/swarm": "^0.8.32",
41
41
  "@vandeurenglenn/base32": "^1.2.4",
42
42
  "@vandeurenglenn/base58": "^1.1.9",
43
43
  "@vandeurenglenn/debug": "^1.2.6",
@@ -52,14 +52,14 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "@jest/globals": "^30.2.0",
55
- "@rollup/plugin-commonjs": "^28.0.8",
55
+ "@rollup/plugin-commonjs": "^29.0.0",
56
56
  "@rollup/plugin-json": "^6.1.0",
57
57
  "@rollup/plugin-node-resolve": "^16.0.3",
58
- "@rollup/plugin-typescript": "^12.2.0",
58
+ "@rollup/plugin-typescript": "^12.3.0",
59
59
  "@rollup/plugin-wasm": "^6.2.2",
60
60
  "@types/bs58check": "^3.0.1",
61
- "@types/node": "^24.9.1",
62
- "@types/qrcode": "^1.5.5",
61
+ "@types/node": "^24.9.2",
62
+ "@types/qrcode": "^1.5.6",
63
63
  "@types/secp256k1": "^4.0.7",
64
64
  "@types/varint": "^6.0.3",
65
65
  "chai": "^6.2.0",