@mtcute/core 0.23.0 → 0.23.1
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/highlevel/types/premium/stars-gift-unique.cjs +23 -3
- package/highlevel/types/premium/stars-gift-unique.d.cts +16 -2
- package/highlevel/types/premium/stars-gift-unique.d.ts +16 -2
- package/highlevel/types/premium/stars-gift-unique.js +23 -3
- package/highlevel/updates/manager.cjs +4 -4
- package/highlevel/updates/manager.js +4 -4
- package/network/authorization.cjs +1 -1
- package/network/authorization.js +1 -1
- package/network/middlewares/flood-waiter.cjs +2 -2
- package/network/middlewares/flood-waiter.js +2 -2
- package/network/mtproto-session.cjs +3 -4
- package/network/mtproto-session.d.cts +1 -1
- package/network/mtproto-session.d.ts +1 -1
- package/network/mtproto-session.js +3 -4
- package/network/network-manager.cjs +3 -3
- package/network/network-manager.js +3 -3
- package/network/persistent-connection.cjs +1 -0
- package/network/persistent-connection.js +1 -0
- package/network/session-connection.cjs +4 -4
- package/network/session-connection.js +4 -4
- package/package.json +2 -2
- package/utils/early-timer.cjs +6 -6
- package/utils/early-timer.d.cts +3 -3
- package/utils/early-timer.d.ts +3 -3
- package/utils/early-timer.js +6 -6
|
@@ -63,14 +63,34 @@ class StarGiftUniqueOriginalDetails {
|
|
|
63
63
|
this.raw = raw;
|
|
64
64
|
this._peers = _peers;
|
|
65
65
|
}
|
|
66
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Peer who sent the original star gift, if available
|
|
68
|
+
*
|
|
69
|
+
* > Note: in some cases, {@link senderId} might be available, but not this field.
|
|
70
|
+
* > In such cases, you should try fetching the peer manually using {@link getPeer})
|
|
71
|
+
*/
|
|
67
72
|
get sender() {
|
|
68
|
-
|
|
73
|
+
if (!this.raw.senderId) return null;
|
|
74
|
+
if (!this._peers.has(this.raw.senderId)) return null;
|
|
75
|
+
return peer.parsePeer(this.raw.senderId, this._peers);
|
|
76
|
+
}
|
|
77
|
+
/** ID of the peer who sent the original star gift */
|
|
78
|
+
get senderId() {
|
|
79
|
+
return this.raw.senderId ? peerUtils.getMarkedPeerId(this.raw.senderId) : null;
|
|
69
80
|
}
|
|
70
|
-
/**
|
|
81
|
+
/**
|
|
82
|
+
* Peer who received the original star gift, if available
|
|
83
|
+
*
|
|
84
|
+
* > Note: {@link recipientId} is always available. If ID is available, but this field throws an error,
|
|
85
|
+
* > you should try fetching the peer manually using {@link getPeer})
|
|
86
|
+
*/
|
|
71
87
|
get recipient() {
|
|
72
88
|
return peer.parsePeer(this.raw.recipientId, this._peers);
|
|
73
89
|
}
|
|
90
|
+
/** ID of the peer who received the original star gift */
|
|
91
|
+
get recipientId() {
|
|
92
|
+
return peerUtils.getMarkedPeerId(this.raw.recipientId);
|
|
93
|
+
}
|
|
74
94
|
/** Date when the original star gift was sent */
|
|
75
95
|
get date() {
|
|
76
96
|
return new Date(this.raw.date * 1e3);
|
|
@@ -31,10 +31,24 @@ export declare class StarGiftUniqueOriginalDetails {
|
|
|
31
31
|
readonly raw: tl.RawStarGiftAttributeOriginalDetails;
|
|
32
32
|
readonly _peers: PeersIndex;
|
|
33
33
|
constructor(raw: tl.RawStarGiftAttributeOriginalDetails, _peers: PeersIndex);
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Peer who sent the original star gift, if available
|
|
36
|
+
*
|
|
37
|
+
* > Note: in some cases, {@link senderId} might be available, but not this field.
|
|
38
|
+
* > In such cases, you should try fetching the peer manually using {@link getPeer})
|
|
39
|
+
*/
|
|
35
40
|
get sender(): Peer | null;
|
|
36
|
-
/** ID of the
|
|
41
|
+
/** ID of the peer who sent the original star gift */
|
|
42
|
+
get senderId(): number | null;
|
|
43
|
+
/**
|
|
44
|
+
* Peer who received the original star gift, if available
|
|
45
|
+
*
|
|
46
|
+
* > Note: {@link recipientId} is always available. If ID is available, but this field throws an error,
|
|
47
|
+
* > you should try fetching the peer manually using {@link getPeer})
|
|
48
|
+
*/
|
|
37
49
|
get recipient(): Peer;
|
|
50
|
+
/** ID of the peer who received the original star gift */
|
|
51
|
+
get recipientId(): number;
|
|
38
52
|
/** Date when the original star gift was sent */
|
|
39
53
|
get date(): Date;
|
|
40
54
|
/** Message attached to the original star gift */
|
|
@@ -31,10 +31,24 @@ export declare class StarGiftUniqueOriginalDetails {
|
|
|
31
31
|
readonly raw: tl.RawStarGiftAttributeOriginalDetails;
|
|
32
32
|
readonly _peers: PeersIndex;
|
|
33
33
|
constructor(raw: tl.RawStarGiftAttributeOriginalDetails, _peers: PeersIndex);
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Peer who sent the original star gift, if available
|
|
36
|
+
*
|
|
37
|
+
* > Note: in some cases, {@link senderId} might be available, but not this field.
|
|
38
|
+
* > In such cases, you should try fetching the peer manually using {@link getPeer})
|
|
39
|
+
*/
|
|
35
40
|
get sender(): Peer | null;
|
|
36
|
-
/** ID of the
|
|
41
|
+
/** ID of the peer who sent the original star gift */
|
|
42
|
+
get senderId(): number | null;
|
|
43
|
+
/**
|
|
44
|
+
* Peer who received the original star gift, if available
|
|
45
|
+
*
|
|
46
|
+
* > Note: {@link recipientId} is always available. If ID is available, but this field throws an error,
|
|
47
|
+
* > you should try fetching the peer manually using {@link getPeer})
|
|
48
|
+
*/
|
|
37
49
|
get recipient(): Peer;
|
|
50
|
+
/** ID of the peer who received the original star gift */
|
|
51
|
+
get recipientId(): number;
|
|
38
52
|
/** Date when the original star gift was sent */
|
|
39
53
|
get date(): Date;
|
|
40
54
|
/** Message attached to the original star gift */
|
|
@@ -56,14 +56,34 @@ class StarGiftUniqueOriginalDetails {
|
|
|
56
56
|
this.raw = raw;
|
|
57
57
|
this._peers = _peers;
|
|
58
58
|
}
|
|
59
|
-
/**
|
|
59
|
+
/**
|
|
60
|
+
* Peer who sent the original star gift, if available
|
|
61
|
+
*
|
|
62
|
+
* > Note: in some cases, {@link senderId} might be available, but not this field.
|
|
63
|
+
* > In such cases, you should try fetching the peer manually using {@link getPeer})
|
|
64
|
+
*/
|
|
60
65
|
get sender() {
|
|
61
|
-
|
|
66
|
+
if (!this.raw.senderId) return null;
|
|
67
|
+
if (!this._peers.has(this.raw.senderId)) return null;
|
|
68
|
+
return parsePeer(this.raw.senderId, this._peers);
|
|
69
|
+
}
|
|
70
|
+
/** ID of the peer who sent the original star gift */
|
|
71
|
+
get senderId() {
|
|
72
|
+
return this.raw.senderId ? getMarkedPeerId(this.raw.senderId) : null;
|
|
62
73
|
}
|
|
63
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Peer who received the original star gift, if available
|
|
76
|
+
*
|
|
77
|
+
* > Note: {@link recipientId} is always available. If ID is available, but this field throws an error,
|
|
78
|
+
* > you should try fetching the peer manually using {@link getPeer})
|
|
79
|
+
*/
|
|
64
80
|
get recipient() {
|
|
65
81
|
return parsePeer(this.raw.recipientId, this._peers);
|
|
66
82
|
}
|
|
83
|
+
/** ID of the peer who received the original star gift */
|
|
84
|
+
get recipientId() {
|
|
85
|
+
return getMarkedPeerId(this.raw.recipientId);
|
|
86
|
+
}
|
|
67
87
|
/** Date when the original star gift was sent */
|
|
68
88
|
get date() {
|
|
69
89
|
return new Date(this.raw.date * 1e3);
|
|
@@ -1225,7 +1225,7 @@ class UpdatesManager {
|
|
|
1225
1225
|
pending.ptsBefore,
|
|
1226
1226
|
diff
|
|
1227
1227
|
);
|
|
1228
|
-
pending.timeout =
|
|
1228
|
+
pending.timeout = performance.now() + 500;
|
|
1229
1229
|
pendingPtsUpdatesPostponed.add(pending);
|
|
1230
1230
|
postponedTimer.emitBefore(pending.timeout);
|
|
1231
1231
|
} else if (diff > -1e6) {
|
|
@@ -1294,7 +1294,7 @@ class UpdatesManager {
|
|
|
1294
1294
|
continue;
|
|
1295
1295
|
}
|
|
1296
1296
|
if (localPts < pending.ptsBefore) {
|
|
1297
|
-
const now =
|
|
1297
|
+
const now = performance.now();
|
|
1298
1298
|
if (now < pending.timeout) {
|
|
1299
1299
|
log.debug(
|
|
1300
1300
|
"postponed %s (cid = %d) is still waiting (%dms left) (current pts %d, need %d)",
|
|
@@ -1348,7 +1348,7 @@ class UpdatesManager {
|
|
|
1348
1348
|
pending.qtsBefore,
|
|
1349
1349
|
diff
|
|
1350
1350
|
);
|
|
1351
|
-
pending.timeout =
|
|
1351
|
+
pending.timeout = performance.now() + 500;
|
|
1352
1352
|
pendingQtsUpdatesPostponed.add(pending);
|
|
1353
1353
|
postponedTimer.emitBefore(pending.timeout);
|
|
1354
1354
|
} else {
|
|
@@ -1382,7 +1382,7 @@ class UpdatesManager {
|
|
|
1382
1382
|
continue;
|
|
1383
1383
|
}
|
|
1384
1384
|
if (this.qts < pending.qtsBefore) {
|
|
1385
|
-
const now =
|
|
1385
|
+
const now = performance.now();
|
|
1386
1386
|
if (now < pending.timeout) {
|
|
1387
1387
|
log.debug(
|
|
1388
1388
|
"postponed %s is still waiting (%dms left) (current qts %d, need %d)",
|
|
@@ -1218,7 +1218,7 @@ class UpdatesManager {
|
|
|
1218
1218
|
pending.ptsBefore,
|
|
1219
1219
|
diff
|
|
1220
1220
|
);
|
|
1221
|
-
pending.timeout =
|
|
1221
|
+
pending.timeout = performance.now() + 500;
|
|
1222
1222
|
pendingPtsUpdatesPostponed.add(pending);
|
|
1223
1223
|
postponedTimer.emitBefore(pending.timeout);
|
|
1224
1224
|
} else if (diff > -1e6) {
|
|
@@ -1287,7 +1287,7 @@ class UpdatesManager {
|
|
|
1287
1287
|
continue;
|
|
1288
1288
|
}
|
|
1289
1289
|
if (localPts < pending.ptsBefore) {
|
|
1290
|
-
const now =
|
|
1290
|
+
const now = performance.now();
|
|
1291
1291
|
if (now < pending.timeout) {
|
|
1292
1292
|
log.debug(
|
|
1293
1293
|
"postponed %s (cid = %d) is still waiting (%dms left) (current pts %d, need %d)",
|
|
@@ -1341,7 +1341,7 @@ class UpdatesManager {
|
|
|
1341
1341
|
pending.qtsBefore,
|
|
1342
1342
|
diff
|
|
1343
1343
|
);
|
|
1344
|
-
pending.timeout =
|
|
1344
|
+
pending.timeout = performance.now() + 500;
|
|
1345
1345
|
pendingQtsUpdatesPostponed.add(pending);
|
|
1346
1346
|
postponedTimer.emitBefore(pending.timeout);
|
|
1347
1347
|
} else {
|
|
@@ -1375,7 +1375,7 @@ class UpdatesManager {
|
|
|
1375
1375
|
continue;
|
|
1376
1376
|
}
|
|
1377
1377
|
if (this.qts < pending.qtsBefore) {
|
|
1378
|
-
const now =
|
|
1378
|
+
const now = performance.now();
|
|
1379
1379
|
if (now < pending.timeout) {
|
|
1380
1380
|
log.debug(
|
|
1381
1381
|
"postponed %s is still waiting (%dms left) (current qts %d, need %d)",
|
|
@@ -239,7 +239,7 @@ async function doAuthorization(connection, crypto, expiresIn) {
|
|
|
239
239
|
throw new Error("Step 3: invalid server nonce from server");
|
|
240
240
|
}
|
|
241
241
|
const dhPrime = utils.bigint.fromBytes(serverDhInner.dhPrime);
|
|
242
|
-
const timeOffset = Math.floor(
|
|
242
|
+
const timeOffset = serverDhInner.serverTime - Math.floor(performance.now() / 1e3);
|
|
243
243
|
session.updateTimeOffset(timeOffset);
|
|
244
244
|
const g = BigInt(serverDhInner.g);
|
|
245
245
|
const gA = utils.bigint.fromBytes(serverDhInner.gA);
|
package/network/authorization.js
CHANGED
|
@@ -232,7 +232,7 @@ async function doAuthorization(connection, crypto, expiresIn) {
|
|
|
232
232
|
throw new Error("Step 3: invalid server nonce from server");
|
|
233
233
|
}
|
|
234
234
|
const dhPrime = bigint.fromBytes(serverDhInner.dhPrime);
|
|
235
|
-
const timeOffset = Math.floor(
|
|
235
|
+
const timeOffset = serverDhInner.serverTime - Math.floor(performance.now() / 1e3);
|
|
236
236
|
session.updateTimeOffset(timeOffset);
|
|
237
237
|
const g = BigInt(serverDhInner.g);
|
|
238
238
|
const gA = bigint.fromBytes(serverDhInner.gA);
|
|
@@ -30,7 +30,7 @@ function floodWaiter(options) {
|
|
|
30
30
|
const storedWaitUntil = store ? storage.get(method) : void 0;
|
|
31
31
|
const floodSleepThreshold = ctx.params?.floodSleepThreshold ?? maxWait;
|
|
32
32
|
if (storedWaitUntil !== void 0) {
|
|
33
|
-
const delta = storedWaitUntil -
|
|
33
|
+
const delta = storedWaitUntil - performance.now();
|
|
34
34
|
if (delta <= minStoredWait) {
|
|
35
35
|
storage.delete(method);
|
|
36
36
|
} else if (delta <= floodSleepThreshold) {
|
|
@@ -59,7 +59,7 @@ function floodWaiter(options) {
|
|
|
59
59
|
return res;
|
|
60
60
|
}
|
|
61
61
|
if (store && !err.startsWith("SLOWMODE_WAIT_")) {
|
|
62
|
-
storage.set(method,
|
|
62
|
+
storage.set(method, performance.now() + seconds * 1e3);
|
|
63
63
|
}
|
|
64
64
|
if (seconds === 0) {
|
|
65
65
|
seconds = 1;
|
|
@@ -23,7 +23,7 @@ function floodWaiter(options) {
|
|
|
23
23
|
const storedWaitUntil = store ? storage.get(method) : void 0;
|
|
24
24
|
const floodSleepThreshold = ctx.params?.floodSleepThreshold ?? maxWait;
|
|
25
25
|
if (storedWaitUntil !== void 0) {
|
|
26
|
-
const delta = storedWaitUntil -
|
|
26
|
+
const delta = storedWaitUntil - performance.now();
|
|
27
27
|
if (delta <= minStoredWait) {
|
|
28
28
|
storage.delete(method);
|
|
29
29
|
} else if (delta <= floodSleepThreshold) {
|
|
@@ -52,7 +52,7 @@ function floodWaiter(options) {
|
|
|
52
52
|
return res;
|
|
53
53
|
}
|
|
54
54
|
if (store && !err.startsWith("SLOWMODE_WAIT_")) {
|
|
55
|
-
storage.set(method,
|
|
55
|
+
storage.set(method, performance.now() + seconds * 1e3);
|
|
56
56
|
}
|
|
57
57
|
if (seconds === 0) {
|
|
58
58
|
seconds = 1;
|
|
@@ -29,7 +29,7 @@ class MtprotoSession {
|
|
|
29
29
|
_authKey;
|
|
30
30
|
_authKeyTemp;
|
|
31
31
|
_authKeyTempSecondary;
|
|
32
|
-
_timeOffset =
|
|
32
|
+
_timeOffset = performance.timeOrigin;
|
|
33
33
|
_lastMessageId = Long.ZERO;
|
|
34
34
|
_seqNo = 0;
|
|
35
35
|
/// state ///
|
|
@@ -132,8 +132,8 @@ class MtprotoSession {
|
|
|
132
132
|
return true;
|
|
133
133
|
}
|
|
134
134
|
getMessageId() {
|
|
135
|
-
const timeTicks =
|
|
136
|
-
const timeSec = Math.floor(timeTicks / 1e3)
|
|
135
|
+
const timeTicks = performance.now();
|
|
136
|
+
const timeSec = Math.floor(timeTicks / 1e3) + this._timeOffset;
|
|
137
137
|
const timeMSec = timeTicks % 1e3;
|
|
138
138
|
const random = miscUtils.getRandomInt(65535);
|
|
139
139
|
let messageId = new Long(timeMSec << 21 | random << 3 | 4, timeSec);
|
|
@@ -206,7 +206,6 @@ class MtprotoSession {
|
|
|
206
206
|
this.next429Timeout = 1e3;
|
|
207
207
|
}, 6e4);
|
|
208
208
|
this.log.debug("transport flood, waiting for %d ms before proceeding", timeout);
|
|
209
|
-
return Date.now() + timeout;
|
|
210
209
|
}
|
|
211
210
|
resetLastPing(withTime = false) {
|
|
212
211
|
if (withTime) this.lastPingTime = 0;
|
|
@@ -119,7 +119,7 @@ export declare class MtprotoSession {
|
|
|
119
119
|
/** Decrypt a single MTProto message using session's keys */
|
|
120
120
|
decryptMessage(data: Uint8Array, callback: Parameters<AuthKey['decryptMessage']>[2]): void;
|
|
121
121
|
writeMessage(writer: TlBinaryWriter, content: tl.TlObject | mtp.TlObject | Uint8Array, isContentRelated?: boolean): Long;
|
|
122
|
-
onTransportFlood(callback: () => void):
|
|
122
|
+
onTransportFlood(callback: () => void): void;
|
|
123
123
|
resetLastPing(withTime?: boolean): void;
|
|
124
124
|
addToChain(chainId: string | number, msgId: Long): Long | undefined;
|
|
125
125
|
removeFromChain(chainId: string | number, msgId: Long): void;
|
|
@@ -119,7 +119,7 @@ export declare class MtprotoSession {
|
|
|
119
119
|
/** Decrypt a single MTProto message using session's keys */
|
|
120
120
|
decryptMessage(data: Uint8Array, callback: Parameters<AuthKey['decryptMessage']>[2]): void;
|
|
121
121
|
writeMessage(writer: TlBinaryWriter, content: tl.TlObject | mtp.TlObject | Uint8Array, isContentRelated?: boolean): Long;
|
|
122
|
-
onTransportFlood(callback: () => void):
|
|
122
|
+
onTransportFlood(callback: () => void): void;
|
|
123
123
|
resetLastPing(withTime?: boolean): void;
|
|
124
124
|
addToChain(chainId: string | number, msgId: Long): Long | undefined;
|
|
125
125
|
removeFromChain(chainId: string | number, msgId: Long): void;
|
|
@@ -22,7 +22,7 @@ class MtprotoSession {
|
|
|
22
22
|
_authKey;
|
|
23
23
|
_authKeyTemp;
|
|
24
24
|
_authKeyTempSecondary;
|
|
25
|
-
_timeOffset =
|
|
25
|
+
_timeOffset = performance.timeOrigin;
|
|
26
26
|
_lastMessageId = Long.ZERO;
|
|
27
27
|
_seqNo = 0;
|
|
28
28
|
/// state ///
|
|
@@ -125,8 +125,8 @@ class MtprotoSession {
|
|
|
125
125
|
return true;
|
|
126
126
|
}
|
|
127
127
|
getMessageId() {
|
|
128
|
-
const timeTicks =
|
|
129
|
-
const timeSec = Math.floor(timeTicks / 1e3)
|
|
128
|
+
const timeTicks = performance.now();
|
|
129
|
+
const timeSec = Math.floor(timeTicks / 1e3) + this._timeOffset;
|
|
130
130
|
const timeMSec = timeTicks % 1e3;
|
|
131
131
|
const random = getRandomInt(65535);
|
|
132
132
|
let messageId = new Long(timeMSec << 21 | random << 3 | 4, timeSec);
|
|
@@ -199,7 +199,6 @@ class MtprotoSession {
|
|
|
199
199
|
this.next429Timeout = 1e3;
|
|
200
200
|
}, 6e4);
|
|
201
201
|
this.log.debug("transport flood, waiting for %d ms before proceeding", timeout);
|
|
202
|
-
return Date.now() + timeout;
|
|
203
202
|
}
|
|
204
203
|
resetLastPing(withTime = false) {
|
|
205
204
|
if (withTime) this.lastPingTime = 0;
|
|
@@ -189,7 +189,7 @@ class DcConnectionManager {
|
|
|
189
189
|
return false;
|
|
190
190
|
}
|
|
191
191
|
if (this.manager.params.usePfs || forcePfs) {
|
|
192
|
-
const now =
|
|
192
|
+
const now = performance.now();
|
|
193
193
|
await Promise.all(
|
|
194
194
|
Array.from({ length: this.main.getCount() }, async (_, i) => {
|
|
195
195
|
const temp = await this.manager._storage.provider.authKeys.getTemp(this.dcId, i, now);
|
|
@@ -220,7 +220,7 @@ class NetworkManager {
|
|
|
220
220
|
_: "initConnection",
|
|
221
221
|
deviceModel,
|
|
222
222
|
systemVersion: "1.0",
|
|
223
|
-
appVersion: "0.23.
|
|
223
|
+
appVersion: "0.23.1",
|
|
224
224
|
systemLangCode: "en",
|
|
225
225
|
langPack: "",
|
|
226
226
|
// "langPacks are for official apps only"
|
|
@@ -501,7 +501,7 @@ class NetworkManager {
|
|
|
501
501
|
res = await multi.sendRpc(message, params?.timeout, params?.abortSignal, params?.chainId);
|
|
502
502
|
}
|
|
503
503
|
} else if (err === "AUTH_KEY_UNREGISTERED") {
|
|
504
|
-
this._log.
|
|
504
|
+
this._log.debug("exported auth key error, trying re-exporting..");
|
|
505
505
|
await this._exportAuthTo(manager);
|
|
506
506
|
res = await multi.sendRpc(message, params?.timeout, params?.abortSignal, params?.chainId);
|
|
507
507
|
}
|
|
@@ -182,7 +182,7 @@ class DcConnectionManager {
|
|
|
182
182
|
return false;
|
|
183
183
|
}
|
|
184
184
|
if (this.manager.params.usePfs || forcePfs) {
|
|
185
|
-
const now =
|
|
185
|
+
const now = performance.now();
|
|
186
186
|
await Promise.all(
|
|
187
187
|
Array.from({ length: this.main.getCount() }, async (_, i) => {
|
|
188
188
|
const temp = await this.manager._storage.provider.authKeys.getTemp(this.dcId, i, now);
|
|
@@ -213,7 +213,7 @@ class NetworkManager {
|
|
|
213
213
|
_: "initConnection",
|
|
214
214
|
deviceModel,
|
|
215
215
|
systemVersion: "1.0",
|
|
216
|
-
appVersion: "0.23.
|
|
216
|
+
appVersion: "0.23.1",
|
|
217
217
|
systemLangCode: "en",
|
|
218
218
|
langPack: "",
|
|
219
219
|
// "langPacks are for official apps only"
|
|
@@ -494,7 +494,7 @@ class NetworkManager {
|
|
|
494
494
|
res = await multi.sendRpc(message, params?.timeout, params?.abortSignal, params?.chainId);
|
|
495
495
|
}
|
|
496
496
|
} else if (err === "AUTH_KEY_UNREGISTERED") {
|
|
497
|
-
this._log.
|
|
497
|
+
this._log.debug("exported auth key error, trying re-exporting..");
|
|
498
498
|
await this._exportAuthTo(manager);
|
|
499
499
|
res = await multi.sendRpc(message, params?.timeout, params?.abortSignal, params?.chainId);
|
|
500
500
|
}
|
|
@@ -23,6 +23,7 @@ class PersistentConnection {
|
|
|
23
23
|
this.log.debug("connecting to %j", dc);
|
|
24
24
|
return params.transport.connect(dc);
|
|
25
25
|
},
|
|
26
|
+
strategy: params.reconnectionStrategy,
|
|
26
27
|
onOpen: this._onOpen.bind(this),
|
|
27
28
|
onClose: this._onClose.bind(this),
|
|
28
29
|
onError: this._onError.bind(this),
|
|
@@ -16,6 +16,7 @@ class PersistentConnection {
|
|
|
16
16
|
this.log.debug("connecting to %j", dc);
|
|
17
17
|
return params.transport.connect(dc);
|
|
18
18
|
},
|
|
19
|
+
strategy: params.reconnectionStrategy,
|
|
19
20
|
onOpen: this._onOpen.bind(this),
|
|
20
21
|
onClose: this._onClose.bind(this),
|
|
21
22
|
onError: this._onError.bind(this),
|
|
@@ -762,7 +762,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
|
|
|
762
762
|
if (info.pingId.neq(pingId)) {
|
|
763
763
|
this.log.warn("received pong to %l, but expected ping_id = %l (got %l)", msgId, info.pingId, pingId);
|
|
764
764
|
}
|
|
765
|
-
const rtt =
|
|
765
|
+
const rtt = performance.now() - this._session.lastPingTime;
|
|
766
766
|
this._session.lastPingRtt = rtt;
|
|
767
767
|
if (info.containerId.neq(msgId)) {
|
|
768
768
|
this._onMessageAcked(info.containerId);
|
|
@@ -781,7 +781,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
|
|
|
781
781
|
case 20: {
|
|
782
782
|
if (msg.errorCode !== 20) {
|
|
783
783
|
const serverTime = msgId.high >>> 0;
|
|
784
|
-
const timeOffset = Math.floor(
|
|
784
|
+
const timeOffset = serverTime - Math.floor(performance.now() / 1e3);
|
|
785
785
|
this._session.updateTimeOffset(timeOffset);
|
|
786
786
|
this.log.debug("server time: %d, corrected offset to %d", serverTime, timeOffset);
|
|
787
787
|
}
|
|
@@ -1130,7 +1130,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
|
|
|
1130
1130
|
let cancelRpcs = null;
|
|
1131
1131
|
let destroySessions = null;
|
|
1132
1132
|
let rootMsgId = null;
|
|
1133
|
-
const now =
|
|
1133
|
+
const now = performance.now();
|
|
1134
1134
|
if (this._session.queuedAcks.length) {
|
|
1135
1135
|
let acks = this._session.queuedAcks;
|
|
1136
1136
|
if (acks.length > 8192) {
|
|
@@ -1163,7 +1163,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
|
|
|
1163
1163
|
// ÷ 1000 * 1.25
|
|
1164
1164
|
disconnectDelay: Math.round(this._pingInterval * 125e-5)
|
|
1165
1165
|
};
|
|
1166
|
-
this._session.lastPingTime =
|
|
1166
|
+
this._session.lastPingTime = now;
|
|
1167
1167
|
pingRequest = tlRuntime.TlBinaryWriter.serializeObject(this._writerMap, obj);
|
|
1168
1168
|
containerSize += pingRequest.length + 16;
|
|
1169
1169
|
containerMessageCount += 1;
|
|
@@ -755,7 +755,7 @@ class SessionConnection extends PersistentConnection {
|
|
|
755
755
|
if (info.pingId.neq(pingId)) {
|
|
756
756
|
this.log.warn("received pong to %l, but expected ping_id = %l (got %l)", msgId, info.pingId, pingId);
|
|
757
757
|
}
|
|
758
|
-
const rtt =
|
|
758
|
+
const rtt = performance.now() - this._session.lastPingTime;
|
|
759
759
|
this._session.lastPingRtt = rtt;
|
|
760
760
|
if (info.containerId.neq(msgId)) {
|
|
761
761
|
this._onMessageAcked(info.containerId);
|
|
@@ -774,7 +774,7 @@ class SessionConnection extends PersistentConnection {
|
|
|
774
774
|
case 20: {
|
|
775
775
|
if (msg.errorCode !== 20) {
|
|
776
776
|
const serverTime = msgId.high >>> 0;
|
|
777
|
-
const timeOffset = Math.floor(
|
|
777
|
+
const timeOffset = serverTime - Math.floor(performance.now() / 1e3);
|
|
778
778
|
this._session.updateTimeOffset(timeOffset);
|
|
779
779
|
this.log.debug("server time: %d, corrected offset to %d", serverTime, timeOffset);
|
|
780
780
|
}
|
|
@@ -1123,7 +1123,7 @@ class SessionConnection extends PersistentConnection {
|
|
|
1123
1123
|
let cancelRpcs = null;
|
|
1124
1124
|
let destroySessions = null;
|
|
1125
1125
|
let rootMsgId = null;
|
|
1126
|
-
const now =
|
|
1126
|
+
const now = performance.now();
|
|
1127
1127
|
if (this._session.queuedAcks.length) {
|
|
1128
1128
|
let acks = this._session.queuedAcks;
|
|
1129
1129
|
if (acks.length > 8192) {
|
|
@@ -1156,7 +1156,7 @@ class SessionConnection extends PersistentConnection {
|
|
|
1156
1156
|
// ÷ 1000 * 1.25
|
|
1157
1157
|
disconnectDelay: Math.round(this._pingInterval * 125e-5)
|
|
1158
1158
|
};
|
|
1159
|
-
this._session.lastPingTime =
|
|
1159
|
+
this._session.lastPingTime = now;
|
|
1160
1160
|
pingRequest = TlBinaryWriter.serializeObject(this._writerMap, obj);
|
|
1161
1161
|
containerSize += pingRequest.length + 16;
|
|
1162
1162
|
containerMessageCount += 1;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mtcute/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.23.
|
|
4
|
+
"version": "0.23.1",
|
|
5
5
|
"description": "Type-safe library for MTProto (Telegram API)",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {},
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"@fuman/net": "0.0.14",
|
|
11
11
|
"@fuman/utils": "0.0.14",
|
|
12
12
|
"@mtcute/file-id": "^0.23.0",
|
|
13
|
-
"@mtcute/tl": "^
|
|
13
|
+
"@mtcute/tl": "^202.0.0",
|
|
14
14
|
"@mtcute/tl-runtime": "^0.23.0",
|
|
15
15
|
"@types/events": "3.0.0",
|
|
16
16
|
"long": "5.2.3"
|
package/utils/early-timer.cjs
CHANGED
|
@@ -16,11 +16,11 @@ class EarlyTimer {
|
|
|
16
16
|
}
|
|
17
17
|
/**
|
|
18
18
|
* Emit the timer when the event loop is idle
|
|
19
|
-
* (basically `
|
|
19
|
+
* (basically `queueMicrotask()`)
|
|
20
20
|
*/
|
|
21
21
|
emitWhenIdle() {
|
|
22
22
|
utils.timers.clearTimeout(this._timeout);
|
|
23
|
-
this._timeoutTs =
|
|
23
|
+
this._timeoutTs = performance.now();
|
|
24
24
|
if (typeof queueMicrotask !== "undefined") {
|
|
25
25
|
queueMicrotask(this.emitNow);
|
|
26
26
|
} else {
|
|
@@ -30,22 +30,22 @@ class EarlyTimer {
|
|
|
30
30
|
/**
|
|
31
31
|
* Emit the timer before the next given milliseconds
|
|
32
32
|
*
|
|
33
|
-
* Shorthand for `emitBefore(
|
|
33
|
+
* Shorthand for `emitBefore(performance.now() + ms)`
|
|
34
34
|
*
|
|
35
35
|
* @param ms Milliseconds to schedule for
|
|
36
36
|
*/
|
|
37
37
|
emitBeforeNext(ms) {
|
|
38
|
-
return this.emitBefore(
|
|
38
|
+
return this.emitBefore(performance.now() + ms);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
41
41
|
* Emit the timer before the given time
|
|
42
42
|
*
|
|
43
|
-
* @param ts
|
|
43
|
+
* @param ts timestamp in ms relative to `performance.timeOrigin`
|
|
44
44
|
*/
|
|
45
45
|
emitBefore(ts) {
|
|
46
46
|
if (!this._timeoutTs || ts < this._timeoutTs) {
|
|
47
47
|
this.reset();
|
|
48
|
-
const diff = ts -
|
|
48
|
+
const diff = ts - performance.now();
|
|
49
49
|
if (diff > 0) {
|
|
50
50
|
this._timeout = utils.timers.setTimeout(this.emitNow, diff);
|
|
51
51
|
this._timeoutTs = ts;
|
package/utils/early-timer.d.cts
CHANGED
|
@@ -9,13 +9,13 @@ export declare class EarlyTimer {
|
|
|
9
9
|
constructor();
|
|
10
10
|
/**
|
|
11
11
|
* Emit the timer when the event loop is idle
|
|
12
|
-
* (basically `
|
|
12
|
+
* (basically `queueMicrotask()`)
|
|
13
13
|
*/
|
|
14
14
|
emitWhenIdle(): void;
|
|
15
15
|
/**
|
|
16
16
|
* Emit the timer before the next given milliseconds
|
|
17
17
|
*
|
|
18
|
-
* Shorthand for `emitBefore(
|
|
18
|
+
* Shorthand for `emitBefore(performance.now() + ms)`
|
|
19
19
|
*
|
|
20
20
|
* @param ms Milliseconds to schedule for
|
|
21
21
|
*/
|
|
@@ -23,7 +23,7 @@ export declare class EarlyTimer {
|
|
|
23
23
|
/**
|
|
24
24
|
* Emit the timer before the given time
|
|
25
25
|
*
|
|
26
|
-
* @param ts
|
|
26
|
+
* @param ts timestamp in ms relative to `performance.timeOrigin`
|
|
27
27
|
*/
|
|
28
28
|
emitBefore(ts: number): void;
|
|
29
29
|
/**
|
package/utils/early-timer.d.ts
CHANGED
|
@@ -9,13 +9,13 @@ export declare class EarlyTimer {
|
|
|
9
9
|
constructor();
|
|
10
10
|
/**
|
|
11
11
|
* Emit the timer when the event loop is idle
|
|
12
|
-
* (basically `
|
|
12
|
+
* (basically `queueMicrotask()`)
|
|
13
13
|
*/
|
|
14
14
|
emitWhenIdle(): void;
|
|
15
15
|
/**
|
|
16
16
|
* Emit the timer before the next given milliseconds
|
|
17
17
|
*
|
|
18
|
-
* Shorthand for `emitBefore(
|
|
18
|
+
* Shorthand for `emitBefore(performance.now() + ms)`
|
|
19
19
|
*
|
|
20
20
|
* @param ms Milliseconds to schedule for
|
|
21
21
|
*/
|
|
@@ -23,7 +23,7 @@ export declare class EarlyTimer {
|
|
|
23
23
|
/**
|
|
24
24
|
* Emit the timer before the given time
|
|
25
25
|
*
|
|
26
|
-
* @param ts
|
|
26
|
+
* @param ts timestamp in ms relative to `performance.timeOrigin`
|
|
27
27
|
*/
|
|
28
28
|
emitBefore(ts: number): void;
|
|
29
29
|
/**
|
package/utils/early-timer.js
CHANGED
|
@@ -9,11 +9,11 @@ class EarlyTimer {
|
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Emit the timer when the event loop is idle
|
|
12
|
-
* (basically `
|
|
12
|
+
* (basically `queueMicrotask()`)
|
|
13
13
|
*/
|
|
14
14
|
emitWhenIdle() {
|
|
15
15
|
timers.clearTimeout(this._timeout);
|
|
16
|
-
this._timeoutTs =
|
|
16
|
+
this._timeoutTs = performance.now();
|
|
17
17
|
if (typeof queueMicrotask !== "undefined") {
|
|
18
18
|
queueMicrotask(this.emitNow);
|
|
19
19
|
} else {
|
|
@@ -23,22 +23,22 @@ class EarlyTimer {
|
|
|
23
23
|
/**
|
|
24
24
|
* Emit the timer before the next given milliseconds
|
|
25
25
|
*
|
|
26
|
-
* Shorthand for `emitBefore(
|
|
26
|
+
* Shorthand for `emitBefore(performance.now() + ms)`
|
|
27
27
|
*
|
|
28
28
|
* @param ms Milliseconds to schedule for
|
|
29
29
|
*/
|
|
30
30
|
emitBeforeNext(ms) {
|
|
31
|
-
return this.emitBefore(
|
|
31
|
+
return this.emitBefore(performance.now() + ms);
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Emit the timer before the given time
|
|
35
35
|
*
|
|
36
|
-
* @param ts
|
|
36
|
+
* @param ts timestamp in ms relative to `performance.timeOrigin`
|
|
37
37
|
*/
|
|
38
38
|
emitBefore(ts) {
|
|
39
39
|
if (!this._timeoutTs || ts < this._timeoutTs) {
|
|
40
40
|
this.reset();
|
|
41
|
-
const diff = ts -
|
|
41
|
+
const diff = ts - performance.now();
|
|
42
42
|
if (diff > 0) {
|
|
43
43
|
this._timeout = timers.setTimeout(this.emitNow, diff);
|
|
44
44
|
this._timeoutTs = ts;
|