Răsfoiți Sursa

Experimental fix for disconnects

painor 3 ani în urmă
părinte
comite
f4dbd2bce2
3 a modificat fișierele cu 10 adăugiri și 11 ștergeri
  1. 6 7
      gramjs/client/updates.ts
  2. 2 2
      package-lock.json
  3. 2 2
      package.json

+ 6 - 7
gramjs/client/updates.ts

@@ -122,6 +122,9 @@ export async function _dispatchUpdate(
     args: { update: UpdateConnectionState | any }
 ): Promise<void> {
     for (const [builder, callback] of client._eventBuilders) {
+        if (!builder || !callback){
+            continue;
+        }
         if (!builder.resolved) {
             await builder.resolve(client);
         }
@@ -172,7 +175,7 @@ export async function _dispatchUpdate(
 export async function _updateLoop(client: TelegramClient): Promise<void> {
     while (!client._destroyed) {
         await sleep(PING_INTERVAL);
-        if (client._reconnecting) {
+        if (client._reconnecting || client._sender!.userDisconnected) {
             continue;
         }
         if (client._destroyed) {
@@ -202,16 +205,12 @@ export async function _updateLoop(client: TelegramClient): Promise<void> {
             );
         } catch (err: any) {
             // eslint-disable-next-line no-console
-            client._log.error(err);
-            if (client._log.canSend(LogLevel.ERROR)) {
-                console.error(err);
-            }
-
-            if (client._reconnecting) {
+            if (client._reconnecting || client._sender!.userDisconnected) {
                 continue;
             }
 
             await client.disconnect();
+
             await client.connect();
         }
 

+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "telegram",
-  "version": "2.6.11",
+  "version": "2.6.13",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "telegram",
-      "version": "2.6.11",
+      "version": "2.6.13",
       "license": "MIT",
       "dependencies": {
         "@cryptography/aes": "^0.1.1",

+ 2 - 2
package.json

@@ -1,6 +1,6 @@
 {
   "name": "telegram",
-  "version": "2.6.11",
+  "version": "2.6.13",
   "description": "NodeJS/Browser MTProto API Telegram client library,",
   "main": "index.js",
   "types": "index.d.ts",
@@ -67,4 +67,4 @@
     "node-localstorage": "^2.2.1",
     "socks": "^2.6.2"
   }
-}
+}