Browse Source

Reconnect when connection breaks while sending data.

Painor 7 months ago
parent
commit
097d1b3716
4 changed files with 14 additions and 7 deletions
  1. 1 1
      gramjs/Version.ts
  2. 10 3
      gramjs/network/MTProtoSender.ts
  3. 2 2
      package-lock.json
  4. 1 1
      package.json

+ 1 - 1
gramjs/Version.ts

@@ -1 +1 @@
-export const version = "2.25.0";
+export const version = "2.25.7";

+ 10 - 3
gramjs/network/MTProtoSender.ts

@@ -513,9 +513,16 @@ export class MTProtoSender {
             try {
                 await this._connection!.send(data);
             } catch (e) {
-                this._log.debug(`Connection closed while sending data ${e}`);
-                if (this._log.canSend(LogLevel.DEBUG)) {
-                    console.error(e);
+                /** when the server disconnects us we want to reconnect */
+                if (!this.userDisconnected) {
+                    this._log.debug(
+                        `Connection closed while sending data ${e}`
+                    );
+
+                    if (this._log.canSend(LogLevel.DEBUG)) {
+                        console.error(e);
+                    }
+                    this.reconnect();
                 }
                 this._sendLoopHandle = undefined;
                 return;

+ 2 - 2
package-lock.json

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

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "telegram",
-  "version": "2.25.0",
+  "version": "2.25.7",
   "description": "NodeJS/Browser MTProto API Telegram client library,",
   "main": "index.js",
   "types": "index.d.ts",