ソースを参照

Try to support ipv6

painor 4 年 前
コミット
d7d30c1d7d
3 ファイル変更10 行追加9 行削除
  1. 2 1
      gramjs/client/TelegramClient.ts
  2. 7 7
      gramjs/client/telegramBaseClient.ts
  3. 1 1
      package.json

+ 2 - 1
gramjs/client/TelegramClient.ts

@@ -159,6 +159,7 @@ export class TelegramClient extends TelegramBaseClient {
     iterParticipants(entity: EntityLike, params: chatMethods.IterParticipantsParams) {
         return chatMethods.iterParticipants(this, entity, params);
     }
+
     getParticipants(entity: EntityLike, params: chatMethods.IterParticipantsParams) {
         return chatMethods.getParticipants(this, entity, params);
     }
@@ -407,7 +408,7 @@ export class TelegramClient extends TelegramBaseClient {
             this._config = await this.invoke(new Api.help.GetConfig())
         }
         for (const DC of this._config.dcOptions) {
-            if (DC.id === dcId) {
+            if (DC.id === dcId && !!DC.ipv6 === this._useIPV6) {
                 return {
                     id: DC.id,
                     ipAddress: DC.ipAddress,

+ 7 - 7
gramjs/client/telegramBaseClient.ts

@@ -15,11 +15,11 @@ import type {EventBuilder} from "../events/common";
 
 const DEFAULT_DC_ID = 1;
 const DEFAULT_IPV4_IP = IS_NODE ? '149.154.167.51' : 'pluto.web.telegram.org';
-const DEFAULT_IPV6_IP = '[2001:67c:4e8:f002::a]';
+const DEFAULT_IPV6_IP = '2001:67c:4e8:f002::a';
 
 export interface TelegramClientParams {
     connection?: any,
-    useIPV6?: false,
+    useIPV6?: boolean,
     timeout?: number,
     requestRetries?: number,
     connectionRetries?: number,
@@ -57,9 +57,10 @@ export class TelegramBaseClient {
     public _floodWaitedRequests: any;
     public _borrowedSenderPromises: any;
     public _bot?: boolean;
+    public _useIPV6: boolean;
     public _selfInputPeer?: Api.InputPeerUser;
     public useWSS: boolean;
-    public _eventBuilders: [EventBuilder,CallableFunction][];
+    public _eventBuilders: [EventBuilder, CallableFunction][];
     public _entityCache: EntityCache;
     public _lastRequest?: number;
     public _parseMode?: ParseInterface;
@@ -97,6 +98,7 @@ export class TelegramBaseClient {
         this.session = session;
         this.apiId = apiId;
         this.apiHash = apiHash;
+        this._useIPV6 = useIPV6;
         this._requestRetries = requestRetries;
         this._connectionRetries = connectionRetries;
         this._retryDelay = retryDelay || 0;
@@ -142,13 +144,12 @@ export class TelegramBaseClient {
     async _initSession() {
         await this.session.load();
 
-        if (!this.session.serverAddress) {
-            this.session.setDC(DEFAULT_DC_ID, DEFAULT_IPV4_IP, this.useWSS ? 443 : 80)
+        if (!this.session.serverAddress || this.session.serverAddress.includes(":") !== this._useIPV6) {
+            this.session.setDC(DEFAULT_DC_ID, this._useIPV6 ? DEFAULT_IPV6_IP : DEFAULT_IPV4_IP, this.useWSS ? 443 : 80)
         }
     }
 
 
-
     get connected() {
         return this._sender && this._sender.isConnected();
     }
@@ -185,5 +186,4 @@ export class TelegramBaseClient {
     // endregion
 
 
-
 }

+ 1 - 1
package.json

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