@konemono/nostr-login 1.10.14 → 1.10.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@konemono/nostr-login",
3
- "version": "1.10.14",
3
+ "version": "1.10.16",
4
4
  "description": "",
5
5
  "main": "./dist/index.esm.js",
6
6
  "types": "./dist/index.d.ts",
@@ -718,6 +718,7 @@ class AuthNostrService extends EventEmitter implements Signer {
718
718
  if (!this.signer && this.params.userInfo) {
719
719
  console.log('Signer was destroyed, reinitializing...');
720
720
  await this.initSigner(this.params.userInfo);
721
+ return; // initSignerで接続も行われるので終了
721
722
  }
722
723
 
723
724
  if (!this.signer) {
@@ -725,9 +726,32 @@ class AuthNostrService extends EventEmitter implements Signer {
725
726
  }
726
727
 
727
728
  // リレー接続を確認・再接続
728
- if (this.ndk.pool.stats().connected === 0) {
729
- console.log('NDK relays disconnected, reconnecting...');
730
- await this.ndk.connect();
729
+ const stats = this.ndk.pool.stats();
730
+ console.log('NDK pool stats:', stats);
731
+
732
+ if (stats.connected === 0) {
733
+ console.log('NDK relays disconnected, reinitializing signer...');
734
+
735
+ // リレーが完全に切断されている場合、signerも再初期化する必要がある
736
+ // (RPCサブスクリプションも切断されているため)
737
+ if (this.params.userInfo) {
738
+ // 古いsignerを破棄
739
+ this.signer = null;
740
+
741
+ // 既存のリレーを一度切断
742
+ for (const relay of this.ndk.pool.relays.values()) {
743
+ try {
744
+ relay.disconnect();
745
+ } catch (e) {
746
+ console.log('Error disconnecting relay:', e);
747
+ }
748
+ }
749
+
750
+ // signerを再初期化(リレー接続も含む)
751
+ await this.initSigner(this.params.userInfo);
752
+ } else {
753
+ throw new Error('Cannot reconnect: no user info');
754
+ }
731
755
  }
732
756
  }
733
757