@konemono/nostr-login 1.7.26 → 1.7.27
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/modules/ProcessManager.ts +31 -52
package/package.json
CHANGED
|
@@ -3,92 +3,71 @@ import { CALL_TIMEOUT } from '../const';
|
|
|
3
3
|
|
|
4
4
|
class ProcessManager extends EventEmitter {
|
|
5
5
|
private paused = false;
|
|
6
|
-
private callCount
|
|
7
|
-
private callTimer
|
|
6
|
+
private callCount = 0;
|
|
7
|
+
private callTimer?: NodeJS.Timeout;
|
|
8
8
|
|
|
9
9
|
constructor() {
|
|
10
10
|
super();
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
public onAuthUrl() {
|
|
14
|
-
console.log('ProcessManager.onAuthUrl called, resetting timer');
|
|
15
14
|
this.resetTimer();
|
|
16
15
|
}
|
|
17
16
|
|
|
18
17
|
public onIframeUrl() {
|
|
19
|
-
console.log('ProcessManager.onIframeUrl called, resetting timer');
|
|
20
18
|
this.resetTimer();
|
|
21
19
|
}
|
|
22
20
|
|
|
21
|
+
private startTimer() {
|
|
22
|
+
if (this.paused) return;
|
|
23
|
+
if (this.callTimer) clearTimeout(this.callTimer);
|
|
24
|
+
|
|
25
|
+
this.callTimer = setTimeout(() => {
|
|
26
|
+
this.emit('onCallTimeout');
|
|
27
|
+
}, CALL_TIMEOUT);
|
|
28
|
+
}
|
|
29
|
+
|
|
23
30
|
private resetTimer() {
|
|
24
|
-
if (this.callTimer) {
|
|
25
|
-
clearTimeout(this.callTimer);
|
|
26
|
-
console.log('ProcessManager: timer reset');
|
|
27
|
-
}
|
|
28
31
|
if (this.callCount > 0) {
|
|
29
|
-
this.
|
|
30
|
-
console.log('ProcessManager: timeout reached, emitting onCallTimeout');
|
|
31
|
-
this.emit('onCallTimeout');
|
|
32
|
-
}, CALL_TIMEOUT);
|
|
33
|
-
console.log(`ProcessManager: new timer set for ${CALL_TIMEOUT} ms`);
|
|
32
|
+
this.startTimer();
|
|
34
33
|
}
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
public async wait<T>(cb: () => Promise<T>): Promise<T> {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (!this.callTimer) {
|
|
41
|
-
this.callTimer = setTimeout(() => {
|
|
42
|
-
console.log('ProcessManager: timeout reached, emitting onCallTimeout');
|
|
43
|
-
this.emit('onCallTimeout');
|
|
44
|
-
}, CALL_TIMEOUT);
|
|
45
|
-
console.log(`Setting up timeout timer for ${CALL_TIMEOUT} ms`);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!this.callCount) {
|
|
37
|
+
if (this.callCount === 0) {
|
|
49
38
|
this.emit('onCallStart');
|
|
50
39
|
}
|
|
51
40
|
|
|
52
41
|
this.callCount++;
|
|
53
|
-
|
|
54
|
-
let error;
|
|
55
|
-
let result;
|
|
42
|
+
this.startTimer();
|
|
56
43
|
|
|
57
44
|
try {
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
45
|
+
return await cb();
|
|
46
|
+
} finally {
|
|
47
|
+
this.callCount--;
|
|
48
|
+
|
|
49
|
+
if (this.callCount === 0) {
|
|
50
|
+
if (this.callTimer) {
|
|
51
|
+
clearTimeout(this.callTimer);
|
|
52
|
+
this.callTimer = undefined;
|
|
53
|
+
}
|
|
54
|
+
this.emit('onCallEnd');
|
|
55
|
+
}
|
|
61
56
|
}
|
|
57
|
+
}
|
|
62
58
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
this.emit('onCallEnd');
|
|
66
|
-
|
|
59
|
+
public pause() {
|
|
60
|
+
this.paused = true;
|
|
67
61
|
if (this.callTimer) {
|
|
68
62
|
clearTimeout(this.callTimer);
|
|
63
|
+
this.callTimer = undefined;
|
|
69
64
|
}
|
|
70
|
-
|
|
71
|
-
this.callTimer = undefined;
|
|
72
|
-
|
|
73
|
-
if (error) {
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// @ts-ignore
|
|
78
|
-
return result;
|
|
79
|
-
}
|
|
80
|
-
public pause() {
|
|
81
|
-
if (this.callTimer) clearTimeout(this.callTimer);
|
|
82
|
-
this.callTimer = undefined;
|
|
83
|
-
this.paused = true;
|
|
84
65
|
}
|
|
85
66
|
|
|
86
67
|
public resume() {
|
|
87
68
|
this.paused = false;
|
|
88
|
-
if (this.callCount > 0
|
|
89
|
-
this.
|
|
90
|
-
this.emit('onCallTimeout');
|
|
91
|
-
}, CALL_TIMEOUT);
|
|
69
|
+
if (this.callCount > 0) {
|
|
70
|
+
this.startTimer();
|
|
92
71
|
}
|
|
93
72
|
}
|
|
94
73
|
}
|