@mtcute/core 0.23.0 → 0.23.2

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.
@@ -63,14 +63,34 @@ class StarGiftUniqueOriginalDetails {
63
63
  this.raw = raw;
64
64
  this._peers = _peers;
65
65
  }
66
- /** ID of the user who sent the original star gift */
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
- return this.raw.senderId ? peer.parsePeer(this.raw.senderId, this._peers) : null;
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
- /** ID of the user who received the original star gift */
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
- /** ID of the user who sent the original star gift */
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 user who received the original star gift */
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
- /** ID of the user who sent the original star gift */
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 user who received the original star gift */
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
- /** ID of the user who sent the original star gift */
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
- return this.raw.senderId ? parsePeer(this.raw.senderId, this._peers) : null;
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
- /** ID of the user who received the original star gift */
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 = Date.now() + 500;
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 = Date.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 = Date.now() + 500;
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 = Date.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 = Date.now() + 500;
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 = Date.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 = Date.now() + 500;
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 = Date.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(Date.now() / 1e3) - serverDhInner.serverTime;
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);
@@ -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(Date.now() / 1e3) - serverDhInner.serverTime;
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 - Date.now();
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, Date.now() + seconds * 1e3);
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 - Date.now();
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, Date.now() + seconds * 1e3);
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 = 0;
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 = Date.now();
136
- const timeSec = Math.floor(timeTicks / 1e3) - this._timeOffset;
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): number | undefined;
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): number | undefined;
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 = 0;
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 = Date.now();
129
- const timeSec = Math.floor(timeTicks / 1e3) - this._timeOffset;
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 = Date.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.0",
223
+ appVersion: "0.23.2",
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.warn("exported auth key error, trying re-exporting..");
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 = Date.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.0",
216
+ appVersion: "0.23.2",
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.warn("exported auth key error, trying re-exporting..");
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),
@@ -542,15 +542,20 @@ class SessionConnection extends persistentConnection.PersistentConnection {
542
542
  const customReader = this._readerMap._results[rpc.method];
543
543
  if (resultConstructorId === RPC_ERROR_ID) {
544
544
  result = message.object();
545
- } else if (customReader) {
546
- result = customReader(message);
547
545
  } else {
548
- const objectId = message.uint();
546
+ const objectId = message.peekUint();
549
547
  if (objectId === GZIP_PACKED_ID) {
548
+ message.pos += 4;
550
549
  const inner = this._crypto.gunzip(message.bytes());
551
- result = tlRuntime.TlBinaryReader.deserializeObject(this._readerMap, inner);
550
+ if (customReader) {
551
+ result = customReader(new tlRuntime.TlBinaryReader(this._readerMap, inner));
552
+ } else {
553
+ result = tlRuntime.TlBinaryReader.deserializeObject(this._readerMap, inner);
554
+ }
555
+ } else if (customReader) {
556
+ result = customReader(message);
552
557
  } else {
553
- result = message.object(objectId);
558
+ result = message.object();
554
559
  }
555
560
  }
556
561
  if (rpc.initConn) {
@@ -762,7 +767,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
762
767
  if (info.pingId.neq(pingId)) {
763
768
  this.log.warn("received pong to %l, but expected ping_id = %l (got %l)", msgId, info.pingId, pingId);
764
769
  }
765
- const rtt = Date.now() - this._session.lastPingTime;
770
+ const rtt = performance.now() - this._session.lastPingTime;
766
771
  this._session.lastPingRtt = rtt;
767
772
  if (info.containerId.neq(msgId)) {
768
773
  this._onMessageAcked(info.containerId);
@@ -781,7 +786,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
781
786
  case 20: {
782
787
  if (msg.errorCode !== 20) {
783
788
  const serverTime = msgId.high >>> 0;
784
- const timeOffset = Math.floor(Date.now() / 1e3) - serverTime;
789
+ const timeOffset = serverTime - Math.floor(performance.now() / 1e3);
785
790
  this._session.updateTimeOffset(timeOffset);
786
791
  this.log.debug("server time: %d, corrected offset to %d", serverTime, timeOffset);
787
792
  }
@@ -1130,7 +1135,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
1130
1135
  let cancelRpcs = null;
1131
1136
  let destroySessions = null;
1132
1137
  let rootMsgId = null;
1133
- const now = Date.now();
1138
+ const now = performance.now();
1134
1139
  if (this._session.queuedAcks.length) {
1135
1140
  let acks = this._session.queuedAcks;
1136
1141
  if (acks.length > 8192) {
@@ -1163,7 +1168,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
1163
1168
  // ÷ 1000 * 1.25
1164
1169
  disconnectDelay: Math.round(this._pingInterval * 125e-5)
1165
1170
  };
1166
- this._session.lastPingTime = Date.now();
1171
+ this._session.lastPingTime = now;
1167
1172
  pingRequest = tlRuntime.TlBinaryWriter.serializeObject(this._writerMap, obj);
1168
1173
  containerSize += pingRequest.length + 16;
1169
1174
  containerMessageCount += 1;
@@ -535,15 +535,20 @@ class SessionConnection extends PersistentConnection {
535
535
  const customReader = this._readerMap._results[rpc.method];
536
536
  if (resultConstructorId === RPC_ERROR_ID) {
537
537
  result = message.object();
538
- } else if (customReader) {
539
- result = customReader(message);
540
538
  } else {
541
- const objectId = message.uint();
539
+ const objectId = message.peekUint();
542
540
  if (objectId === GZIP_PACKED_ID) {
541
+ message.pos += 4;
543
542
  const inner = this._crypto.gunzip(message.bytes());
544
- result = TlBinaryReader.deserializeObject(this._readerMap, inner);
543
+ if (customReader) {
544
+ result = customReader(new TlBinaryReader(this._readerMap, inner));
545
+ } else {
546
+ result = TlBinaryReader.deserializeObject(this._readerMap, inner);
547
+ }
548
+ } else if (customReader) {
549
+ result = customReader(message);
545
550
  } else {
546
- result = message.object(objectId);
551
+ result = message.object();
547
552
  }
548
553
  }
549
554
  if (rpc.initConn) {
@@ -755,7 +760,7 @@ class SessionConnection extends PersistentConnection {
755
760
  if (info.pingId.neq(pingId)) {
756
761
  this.log.warn("received pong to %l, but expected ping_id = %l (got %l)", msgId, info.pingId, pingId);
757
762
  }
758
- const rtt = Date.now() - this._session.lastPingTime;
763
+ const rtt = performance.now() - this._session.lastPingTime;
759
764
  this._session.lastPingRtt = rtt;
760
765
  if (info.containerId.neq(msgId)) {
761
766
  this._onMessageAcked(info.containerId);
@@ -774,7 +779,7 @@ class SessionConnection extends PersistentConnection {
774
779
  case 20: {
775
780
  if (msg.errorCode !== 20) {
776
781
  const serverTime = msgId.high >>> 0;
777
- const timeOffset = Math.floor(Date.now() / 1e3) - serverTime;
782
+ const timeOffset = serverTime - Math.floor(performance.now() / 1e3);
778
783
  this._session.updateTimeOffset(timeOffset);
779
784
  this.log.debug("server time: %d, corrected offset to %d", serverTime, timeOffset);
780
785
  }
@@ -1123,7 +1128,7 @@ class SessionConnection extends PersistentConnection {
1123
1128
  let cancelRpcs = null;
1124
1129
  let destroySessions = null;
1125
1130
  let rootMsgId = null;
1126
- const now = Date.now();
1131
+ const now = performance.now();
1127
1132
  if (this._session.queuedAcks.length) {
1128
1133
  let acks = this._session.queuedAcks;
1129
1134
  if (acks.length > 8192) {
@@ -1156,7 +1161,7 @@ class SessionConnection extends PersistentConnection {
1156
1161
  // ÷ 1000 * 1.25
1157
1162
  disconnectDelay: Math.round(this._pingInterval * 125e-5)
1158
1163
  };
1159
- this._session.lastPingTime = Date.now();
1164
+ this._session.lastPingTime = now;
1160
1165
  pingRequest = TlBinaryWriter.serializeObject(this._writerMap, obj);
1161
1166
  containerSize += pingRequest.length + 16;
1162
1167
  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.0",
4
+ "version": "0.23.2",
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": "^201.0.0",
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"
@@ -16,11 +16,11 @@ class EarlyTimer {
16
16
  }
17
17
  /**
18
18
  * Emit the timer when the event loop is idle
19
- * (basically `setImmediate()`)
19
+ * (basically `queueMicrotask()`)
20
20
  */
21
21
  emitWhenIdle() {
22
22
  utils.timers.clearTimeout(this._timeout);
23
- this._timeoutTs = Date.now();
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(Date.now() + ms)`
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(Date.now() + ms);
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 Unix time in MS
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 - Date.now();
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;
@@ -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 `setImmediate()`)
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(Date.now() + ms)`
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 Unix time in MS
26
+ * @param ts timestamp in ms relative to `performance.timeOrigin`
27
27
  */
28
28
  emitBefore(ts: number): void;
29
29
  /**
@@ -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 `setImmediate()`)
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(Date.now() + ms)`
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 Unix time in MS
26
+ * @param ts timestamp in ms relative to `performance.timeOrigin`
27
27
  */
28
28
  emitBefore(ts: number): void;
29
29
  /**
@@ -9,11 +9,11 @@ class EarlyTimer {
9
9
  }
10
10
  /**
11
11
  * Emit the timer when the event loop is idle
12
- * (basically `setImmediate()`)
12
+ * (basically `queueMicrotask()`)
13
13
  */
14
14
  emitWhenIdle() {
15
15
  timers.clearTimeout(this._timeout);
16
- this._timeoutTs = Date.now();
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(Date.now() + ms)`
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(Date.now() + ms);
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 Unix time in MS
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 - Date.now();
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;