@konemono/nostr-login 1.7.34 → 1.7.36
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 +1 -1
- package/src/const/index.ts +1 -1
- package/src/modules/Nip46.ts +2 -0
- package/src/modules/ProcessManager.ts +26 -26
package/package.json
CHANGED
package/src/const/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const CALL_TIMEOUT =
|
|
1
|
+
export const CALL_TIMEOUT = 10000;
|
|
2
2
|
export const NIP46_TIMEOUT = 30000;
|
package/src/modules/Nip46.ts
CHANGED
|
@@ -218,6 +218,7 @@ class NostrRpc extends NDKNostrRpc {
|
|
|
218
218
|
try {
|
|
219
219
|
this.processManager?.pause();
|
|
220
220
|
await this.ensureConnected();
|
|
221
|
+
this.processManager?.resetTimer();
|
|
221
222
|
} catch (e) {
|
|
222
223
|
console.error('Failed to ensure connection:', e);
|
|
223
224
|
if (cb) {
|
|
@@ -401,6 +402,7 @@ export class IframeNostrRpc extends NostrRpc {
|
|
|
401
402
|
|
|
402
403
|
if (!this.iframePort) {
|
|
403
404
|
try {
|
|
405
|
+
console.log(this.processManager);
|
|
404
406
|
this.processManager?.pause();
|
|
405
407
|
await this.ensureConnected();
|
|
406
408
|
} catch (e) {
|
|
@@ -20,14 +20,19 @@ class ProcessManager extends EventEmitter {
|
|
|
20
20
|
this.resetTimer();
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
public resetTimer() {
|
|
24
|
+
// 既存のタイマーがあればクリア
|
|
24
25
|
if (this.callTimer) {
|
|
25
26
|
clearTimeout(this.callTimer);
|
|
27
|
+
this.callTimer = undefined; // IDをクリア
|
|
26
28
|
console.log('ProcessManager: timer reset');
|
|
27
29
|
}
|
|
28
|
-
|
|
30
|
+
|
|
31
|
+
// 監視対象が残っていて、かつ一時停止中でなければ、新しいタイマーを設定
|
|
32
|
+
if (this.callCount > 0 && !this.paused) {
|
|
29
33
|
this.callTimer = setTimeout(() => {
|
|
30
34
|
console.log('ProcessManager: timeout reached, emitting onCallTimeout');
|
|
35
|
+
this.callTimer = undefined; // タイムアウト時にIDをクリア
|
|
31
36
|
this.emit('onCallTimeout');
|
|
32
37
|
}, CALL_TIMEOUT);
|
|
33
38
|
console.log(`ProcessManager: new timer set for ${CALL_TIMEOUT} ms`);
|
|
@@ -37,13 +42,10 @@ class ProcessManager extends EventEmitter {
|
|
|
37
42
|
public async wait<T>(cb: () => Promise<T>): Promise<T> {
|
|
38
43
|
console.log('ProcessManager.wait called, callTimer exists:', !!this.callTimer, 'callCount:', this.callCount);
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
this.emit('onCallTimeout');
|
|
45
|
-
}, CALL_TIMEOUT);
|
|
46
|
-
console.log(`Setting up timeout timer for ${CALL_TIMEOUT} ms`);
|
|
45
|
+
// ★ 修正点: タイマーの初期設定を resetTimer に任せる
|
|
46
|
+
if (!this.callTimer && this.callCount === 0) {
|
|
47
|
+
// waitの最初の呼び出し時のみ、タイマーを初期設定
|
|
48
|
+
this.resetTimer();
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
if (!this.callCount) {
|
|
@@ -52,7 +54,7 @@ class ProcessManager extends EventEmitter {
|
|
|
52
54
|
|
|
53
55
|
this.callCount++;
|
|
54
56
|
|
|
55
|
-
let error: any;
|
|
57
|
+
let error: any;
|
|
56
58
|
let result: any;
|
|
57
59
|
|
|
58
60
|
// 非同期処理の実行
|
|
@@ -62,21 +64,13 @@ class ProcessManager extends EventEmitter {
|
|
|
62
64
|
error = e;
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
// ★
|
|
66
|
-
// ----------------------------------------------------
|
|
67
|
-
|
|
67
|
+
// ★ 修正点: クリーンアップロジックを resetTimer に置き換え
|
|
68
68
|
// ProcessManagerの呼び出しカウントをデクリメント
|
|
69
69
|
this.callCount--;
|
|
70
70
|
this.emit('onCallEnd');
|
|
71
71
|
|
|
72
|
-
//
|
|
73
|
-
|
|
74
|
-
if (this.callTimer) {
|
|
75
|
-
clearTimeout(this.callTimer);
|
|
76
|
-
}
|
|
77
|
-
this.callTimer = undefined; // ProcessManager のタイマーIDもここでクリア
|
|
78
|
-
|
|
79
|
-
// ----------------------------------------------------
|
|
72
|
+
// リクエスト完了後、タイマーをリセットし、callCountに応じて再設定
|
|
73
|
+
this.resetTimer();
|
|
80
74
|
|
|
81
75
|
// エラーがあればスローし、呼び出し元に伝播させる
|
|
82
76
|
if (error) {
|
|
@@ -88,18 +82,24 @@ class ProcessManager extends EventEmitter {
|
|
|
88
82
|
}
|
|
89
83
|
|
|
90
84
|
public pause() {
|
|
91
|
-
|
|
92
|
-
this.callTimer
|
|
85
|
+
console.log('ProcessManager: PAUSING timer...');
|
|
86
|
+
if (this.callTimer) {
|
|
87
|
+
clearTimeout(this.callTimer);
|
|
88
|
+
}
|
|
89
|
+
this.callTimer = undefined; // タイマーをクリア
|
|
93
90
|
this.paused = true;
|
|
91
|
+
this.emit('onCallPause');
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
public resume() {
|
|
95
|
+
console.log('ProcessManager: RESUMING timer...');
|
|
97
96
|
this.paused = false;
|
|
97
|
+
|
|
98
|
+
// ★ 修正点: pause解除後、監視対象が残っていればタイマーを再設定 (resetTimerを呼び出す)
|
|
98
99
|
if (this.callCount > 0 && !this.callTimer) {
|
|
99
|
-
this.
|
|
100
|
-
this.emit('onCallTimeout');
|
|
101
|
-
}, CALL_TIMEOUT);
|
|
100
|
+
this.resetTimer();
|
|
102
101
|
}
|
|
102
|
+
this.emit('onCallResume');
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|