Browse Source

Add passwords and usernames for proxies

painor 3 years ago
parent
commit
baa2cb7b89

+ 1 - 1
gramjs/Version.ts

@@ -1 +1 @@
-export const version = "2.0.15";
+export const version = "2.1.0";

+ 9 - 1
gramjs/client/updates.ts

@@ -12,7 +12,12 @@ const PING_TIMEOUT = 10000; // 10 sec
 const PING_FAIL_ATTEMPTS = 3;
 const PING_FAIL_INTERVAL = 100; // ms
 const PING_DISCONNECT_DELAY = 60000; // 1 min
-
+/**
+ If this exception is raised in any of the handlers for a given event,
+ it will stop the execution of all other registered event handlers.
+ It can be seen as the ``StopIteration`` in a for loop but for events.
+ */
+export class StopPropagation extends Error {}
 /** @hidden */
 export function on(client: TelegramClient, event?: EventBuilder) {
     return (f: { (event: any): void }) => {
@@ -150,6 +155,9 @@ export async function _dispatchUpdate(
                 try {
                     await callback(event);
                 } catch (e) {
+                    if (e instanceof StopPropagation) {
+                        break;
+                    }
                     console.error(e);
                 }
             }

+ 6 - 1
gramjs/extensions/PromisedNetSockets.ts

@@ -90,7 +90,12 @@ export class PromisedNetSockets {
                 proxy: {
                     host: this.proxy.ip,
                     port: this.proxy.port,
-                    type: this.proxy.socksType!, // Proxy version (4 or 5)
+                    type:
+                        this.proxy.socksType != undefined
+                            ? this.proxy.socksType
+                            : 5, // Proxy version (4 or 5)
+                    userId: this.proxy.username,
+                    password: this.proxy.password,
                 },
 
                 command: "connect",

+ 2 - 0
gramjs/network/connection/TCPMTProxy.ts

@@ -15,6 +15,8 @@ export interface ProxyInterface {
     secret?: string;
     MTProxy?: boolean;
     timeout?: number;
+    username?: string;
+    password?: string;
 }
 
 class MTProxyIO {

+ 2 - 2
package-lock.json

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

+ 1 - 1
package.json

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