teleproto 1.221.4 → 1.222.0

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/Version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "1.221.4";
1
+ export declare const version = "1.222.0";
package/Version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
- exports.version = "1.221.4";
4
+ exports.version = "1.222.0";
@@ -1137,6 +1137,12 @@ class TelegramClient extends telegramBaseClient_1.TelegramBaseClient {
1137
1137
  console.error(e);
1138
1138
  }
1139
1139
  }
1140
+ // Restart update loop if it was stopped during reconnect
1141
+ if (!this._loopStarted && !this._destroyed) {
1142
+ this._log.info("Restarting update loop after reconnect");
1143
+ (0, updates_1._updateLoop)(this);
1144
+ this._loopStarted = true;
1145
+ }
1140
1146
  }
1141
1147
  //region base methods
1142
1148
  async connect() {
@@ -179,7 +179,7 @@ export declare abstract class TelegramBaseClient {
179
179
  /** @hidden */
180
180
  private _exportedSenderReleaseTimeouts;
181
181
  /** @hidden */
182
- protected _loopStarted: boolean;
182
+ _loopStarted: boolean;
183
183
  /** @hidden */
184
184
  _updateState?: {
185
185
  pts: number;
@@ -31,6 +31,7 @@ const clientParamsDefault = {
31
31
  timeout: 10,
32
32
  requestRetries: 5,
33
33
  connectionRetries: Infinity,
34
+ reconnectRetries: Infinity,
34
35
  retryDelay: 1000,
35
36
  downloadRetries: 5,
36
37
  autoReconnect: true,
package/client/updates.js CHANGED
@@ -292,31 +292,21 @@ async function _dispatchUpdate(client, args) {
292
292
  }
293
293
  /** @hidden */
294
294
  async function _updateLoop(client) {
295
- // Initialize update state on first run
296
- if (!client._updateState) {
297
- try {
298
- const state = await client.invoke(new tl_1.Api.updates.GetState());
299
- client._updateState = {
300
- pts: state.pts,
301
- qts: state.qts,
302
- date: state.date,
303
- seq: state.seq,
304
- };
305
- client._log.debug("Initialized update state");
306
- }
307
- catch (e) {
308
- client._log.error(`Failed to get initial update state: ${e}`);
309
- }
310
- }
295
+ var _a, _b;
311
296
  let lastPongAt;
312
297
  while (!client._destroyed) {
313
298
  await (0, Helpers_1.sleep)(PING_INTERVAL, true);
314
- if (client._destroyed || client.disconnected)
299
+ if (client._destroyed)
315
300
  break;
316
- if (client._sender.isReconnecting || client._isSwitchingDc) {
301
+ // Check reconnecting state first - if reconnecting, skip this iteration
302
+ // but don't exit the loop
303
+ if (((_a = client._sender) === null || _a === void 0 ? void 0 : _a.isReconnecting) || client._isSwitchingDc) {
317
304
  lastPongAt = undefined;
318
305
  continue;
319
306
  }
307
+ // Only exit if truly disconnected (not reconnecting)
308
+ if (client.disconnected)
309
+ break;
320
310
  try {
321
311
  const ping = () => {
322
312
  return client._sender.send(new tl_1.Api.PingDelayDisconnect({
@@ -349,12 +339,17 @@ async function _updateLoop(client) {
349
339
  }
350
340
  client._log.error(`Ping failed: ${err}`);
351
341
  lastPongAt = undefined;
352
- if (client.disconnected || client._destroyed) {
342
+ if (client._destroyed) {
353
343
  break;
354
344
  }
355
- if (client._sender.isReconnecting || client._isSwitchingDc) {
345
+ // Check reconnecting state first - if reconnecting, skip this iteration
346
+ if (((_b = client._sender) === null || _b === void 0 ? void 0 : _b.isReconnecting) || client._isSwitchingDc) {
356
347
  continue;
357
348
  }
349
+ // Only exit if truly disconnected (not reconnecting)
350
+ if (client.disconnected) {
351
+ break;
352
+ }
358
353
  client._sender.reconnect();
359
354
  }
360
355
  // We need to send some content-related request at least hourly
@@ -370,14 +365,28 @@ async function _updateLoop(client) {
370
365
  client._updateState.date = state.date;
371
366
  client._updateState.seq = state.seq;
372
367
  }
368
+ else {
369
+ // Initialize update state if not yet set
370
+ client._updateState = {
371
+ pts: state.pts,
372
+ qts: state.qts,
373
+ date: state.date,
374
+ seq: state.seq,
375
+ };
376
+ }
373
377
  }
374
378
  catch (e) {
375
- // we don't care about errors here
379
+ // Ignore auth errors - user might not be logged in yet
376
380
  }
377
381
  lastPongAt = undefined;
378
382
  }
379
383
  }
380
- await client.disconnect();
384
+ // Mark loop as stopped so it can be restarted if needed
385
+ client._loopStarted = false;
386
+ // Only call disconnect if client was explicitly destroyed
387
+ if (client._destroyed) {
388
+ await client.disconnect();
389
+ }
381
390
  }
382
391
  /** @hidden */
383
392
  async function attempts(cb, times, pause) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "teleproto",
3
- "version": "1.221.4",
3
+ "version": "1.222.0",
4
4
  "description": "NodeJS MTProto API Telegram client library,",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -1,3 +1,3 @@
1
- export declare const LAYER = 221;
1
+ export declare const LAYER = 222;
2
2
  declare const tlobjects: any;
3
3
  export { tlobjects };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.tlobjects = exports.LAYER = void 0;
4
- exports.LAYER = 221;
4
+ exports.LAYER = 222;
5
5
  const _1 = require(".");
6
6
  const tlobjects = {};
7
7
  exports.tlobjects = tlobjects;