@mtkruto/node 0.109.0 → 0.110.1
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/esm/client/0_client_abstract.d.ts +3 -3
- package/esm/client/0_client_abstract.d.ts.map +1 -1
- package/esm/client/0_client_abstract.js +6 -6
- package/esm/client/0_html.js +4 -4
- package/esm/client/0_params.d.ts +20 -19
- package/esm/client/0_params.d.ts.map +1 -1
- package/esm/client/1_client_plain.js +1 -1
- package/esm/client/1_types.d.ts +1 -1
- package/esm/client/1_types.d.ts.map +1 -1
- package/esm/client/2_account_manager.js +6 -6
- package/esm/client/2_client_encrypted.js +2 -2
- package/esm/client/2_context.js +19 -19
- package/esm/client/2_file_manager.js +5 -5
- package/esm/client/2_network_statistics_manager.d.ts +1 -1
- package/esm/client/2_network_statistics_manager.d.ts.map +1 -1
- package/esm/client/2_network_statistics_manager.js +3 -3
- package/esm/client/2_sign_in.js +6 -6
- package/esm/client/2_update_manager.js +2 -2
- package/esm/client/3_message_manager.js +38 -38
- package/esm/client/3_video_chat_manager.js +3 -3
- package/esm/client/4_callback_query_manager.js +1 -1
- package/esm/client/4_chat_list_manager.js +1 -1
- package/esm/client/4_chat_manager.js +6 -6
- package/esm/client/4_gift_manager.js +1 -1
- package/esm/client/4_story_manager.js +1 -1
- package/esm/client/5_client.d.ts +2 -2
- package/esm/client/5_client.d.ts.map +1 -1
- package/esm/client/5_client.js +33 -33
- package/esm/connection/0_connection.d.ts +2 -2
- package/esm/connection/0_connection.d.ts.map +1 -1
- package/esm/connection/1_connection_tcp.node.d.ts +1 -1
- package/esm/connection/1_connection_tcp.node.d.ts.map +1 -1
- package/esm/connection/1_connection_tcp.node.js +4 -4
- package/esm/connection/1_connection_web_socket.d.ts +1 -1
- package/esm/connection/1_connection_web_socket.d.ts.map +1 -1
- package/esm/connection/1_connection_web_socket.js +3 -3
- package/esm/session/1_session.d.ts +4 -4
- package/esm/session/1_session.d.ts.map +1 -1
- package/esm/session/1_session.js +21 -21
- package/esm/session/2_session_encrypted.js +5 -5
- package/esm/session/2_session_plain.js +2 -2
- package/esm/transport/1_transport_provider.d.ts +2 -2
- package/esm/transport/1_transport_provider.d.ts.map +1 -1
- package/esm/transport/1_transport_provider.js +2 -2
- package/esm/transport/2_transport_provider_tcp.js +1 -1
- package/esm/transport/2_transport_provider_web_socket.js +3 -3
- package/esm/types/0_bot_token_check_result.d.ts +2 -2
- package/esm/types/0_bot_token_check_result.d.ts.map +1 -1
- package/esm/types/0_code_check_result.d.ts +3 -3
- package/esm/types/0_code_check_result.d.ts.map +1 -1
- package/esm/types/0_password_check_result.d.ts +3 -3
- package/esm/types/0_password_check_result.d.ts.map +1 -1
- package/esm/types/0_video_chat.d.ts +1 -1
- package/esm/types/0_video_chat.d.ts.map +1 -1
- package/esm/types/0_video_chat.js +1 -1
- package/esm/types/0_voice_transcription.d.ts +1 -1
- package/esm/types/0_voice_transcription.d.ts.map +1 -1
- package/esm/types/0_voice_transcription.js +1 -1
- package/esm/types/1_chat_p.d.ts +1 -1
- package/esm/types/1_chat_p.d.ts.map +1 -1
- package/esm/types/1_chat_p.js +1 -1
- package/esm/types/1_input_story_content.d.ts +1 -1
- package/esm/types/1_input_story_content.d.ts.map +1 -1
- package/esm/types/1_keyboard_button.d.ts +7 -7
- package/esm/types/1_keyboard_button.d.ts.map +1 -1
- package/esm/types/1_keyboard_button.js +12 -12
- package/esm/types/1_message_reaction.d.ts +1 -1
- package/esm/types/1_message_reaction.d.ts.map +1 -1
- package/esm/types/1_message_reaction.js +1 -1
- package/esm/types/2_message_reaction_list_item.d.ts +2 -2
- package/esm/types/2_message_reaction_list_item.d.ts.map +1 -1
- package/esm/types/2_message_reaction_list_item.js +4 -4
- package/esm/types/2_reply_markup.d.ts +5 -5
- package/esm/types/2_reply_markup.d.ts.map +1 -1
- package/esm/types/2_reply_markup.js +7 -7
- package/esm/types/2_user.d.ts +1 -1
- package/esm/types/2_user.d.ts.map +1 -1
- package/esm/types/2_user.js +2 -2
- package/esm/types/3_chat_settings.d.ts +9 -9
- package/esm/types/3_chat_settings.d.ts.map +1 -1
- package/esm/types/3_chat_settings.js +9 -9
- package/esm/types/3_story.d.ts +3 -3
- package/esm/types/3_story.d.ts.map +1 -1
- package/esm/types/3_story.js +4 -4
- package/esm/types/5_claimed_gift.d.ts +1 -1
- package/esm/types/5_claimed_gift.d.ts.map +1 -1
- package/esm/types/5_claimed_gift.js +2 -2
- package/esm/types/5_link_preview.d.ts +1 -1
- package/esm/types/5_link_preview.d.ts.map +1 -1
- package/esm/types/6_message.d.ts +2 -2
- package/esm/types/6_message.d.ts.map +1 -1
- package/esm/types/6_message.js +2 -2
- package/esm/types/7_inline_query_result.d.ts +1 -1
- package/esm/types/7_inline_query_result.d.ts.map +1 -1
- package/esm/types/7_inline_query_result.js +1 -1
- package/esm/utilities/0_part_stream.d.ts +1 -1
- package/esm/utilities/0_part_stream.d.ts.map +1 -1
- package/esm/utilities/0_part_stream.js +2 -2
- package/package.json +1 -1
- package/script/client/0_client_abstract.d.ts +3 -3
- package/script/client/0_client_abstract.d.ts.map +1 -1
- package/script/client/0_client_abstract.js +6 -6
- package/script/client/0_html.js +4 -4
- package/script/client/0_params.d.ts +20 -19
- package/script/client/0_params.d.ts.map +1 -1
- package/script/client/1_client_plain.js +1 -1
- package/script/client/1_types.d.ts +1 -1
- package/script/client/1_types.d.ts.map +1 -1
- package/script/client/2_account_manager.js +6 -6
- package/script/client/2_client_encrypted.js +2 -2
- package/script/client/2_context.js +19 -19
- package/script/client/2_file_manager.js +5 -5
- package/script/client/2_network_statistics_manager.d.ts +1 -1
- package/script/client/2_network_statistics_manager.d.ts.map +1 -1
- package/script/client/2_network_statistics_manager.js +3 -3
- package/script/client/2_sign_in.js +6 -6
- package/script/client/2_update_manager.js +2 -2
- package/script/client/3_message_manager.js +38 -38
- package/script/client/3_video_chat_manager.js +3 -3
- package/script/client/4_callback_query_manager.js +1 -1
- package/script/client/4_chat_list_manager.js +1 -1
- package/script/client/4_chat_manager.js +6 -6
- package/script/client/4_gift_manager.js +1 -1
- package/script/client/4_story_manager.js +1 -1
- package/script/client/5_client.d.ts +2 -2
- package/script/client/5_client.d.ts.map +1 -1
- package/script/client/5_client.js +33 -33
- package/script/connection/0_connection.d.ts +2 -2
- package/script/connection/0_connection.d.ts.map +1 -1
- package/script/connection/1_connection_tcp.node.d.ts +1 -1
- package/script/connection/1_connection_tcp.node.d.ts.map +1 -1
- package/script/connection/1_connection_tcp.node.js +4 -4
- package/script/connection/1_connection_web_socket.d.ts +1 -1
- package/script/connection/1_connection_web_socket.d.ts.map +1 -1
- package/script/connection/1_connection_web_socket.js +3 -3
- package/script/session/1_session.d.ts +4 -4
- package/script/session/1_session.d.ts.map +1 -1
- package/script/session/1_session.js +21 -21
- package/script/session/2_session_encrypted.js +5 -5
- package/script/session/2_session_plain.js +2 -2
- package/script/transport/1_transport_provider.d.ts +2 -2
- package/script/transport/1_transport_provider.d.ts.map +1 -1
- package/script/transport/1_transport_provider.js +2 -2
- package/script/transport/2_transport_provider_tcp.js +1 -1
- package/script/transport/2_transport_provider_web_socket.js +3 -3
- package/script/types/0_bot_token_check_result.d.ts +2 -2
- package/script/types/0_bot_token_check_result.d.ts.map +1 -1
- package/script/types/0_code_check_result.d.ts +3 -3
- package/script/types/0_code_check_result.d.ts.map +1 -1
- package/script/types/0_password_check_result.d.ts +3 -3
- package/script/types/0_password_check_result.d.ts.map +1 -1
- package/script/types/0_video_chat.d.ts +1 -1
- package/script/types/0_video_chat.d.ts.map +1 -1
- package/script/types/0_video_chat.js +1 -1
- package/script/types/0_voice_transcription.d.ts +1 -1
- package/script/types/0_voice_transcription.d.ts.map +1 -1
- package/script/types/0_voice_transcription.js +1 -1
- package/script/types/1_chat_p.d.ts +1 -1
- package/script/types/1_chat_p.d.ts.map +1 -1
- package/script/types/1_chat_p.js +1 -1
- package/script/types/1_input_story_content.d.ts +1 -1
- package/script/types/1_input_story_content.d.ts.map +1 -1
- package/script/types/1_keyboard_button.d.ts +7 -7
- package/script/types/1_keyboard_button.d.ts.map +1 -1
- package/script/types/1_keyboard_button.js +12 -12
- package/script/types/1_message_reaction.d.ts +1 -1
- package/script/types/1_message_reaction.d.ts.map +1 -1
- package/script/types/1_message_reaction.js +1 -1
- package/script/types/2_message_reaction_list_item.d.ts +2 -2
- package/script/types/2_message_reaction_list_item.d.ts.map +1 -1
- package/script/types/2_message_reaction_list_item.js +4 -4
- package/script/types/2_reply_markup.d.ts +5 -5
- package/script/types/2_reply_markup.d.ts.map +1 -1
- package/script/types/2_reply_markup.js +7 -7
- package/script/types/2_user.d.ts +1 -1
- package/script/types/2_user.d.ts.map +1 -1
- package/script/types/2_user.js +2 -2
- package/script/types/3_chat_settings.d.ts +9 -9
- package/script/types/3_chat_settings.d.ts.map +1 -1
- package/script/types/3_chat_settings.js +9 -9
- package/script/types/3_story.d.ts +3 -3
- package/script/types/3_story.d.ts.map +1 -1
- package/script/types/3_story.js +4 -4
- package/script/types/5_claimed_gift.d.ts +1 -1
- package/script/types/5_claimed_gift.d.ts.map +1 -1
- package/script/types/5_claimed_gift.js +2 -2
- package/script/types/5_link_preview.d.ts +1 -1
- package/script/types/5_link_preview.d.ts.map +1 -1
- package/script/types/6_message.d.ts +2 -2
- package/script/types/6_message.d.ts.map +1 -1
- package/script/types/6_message.js +2 -2
- package/script/types/7_inline_query_result.d.ts +1 -1
- package/script/types/7_inline_query_result.d.ts.map +1 -1
- package/script/types/7_inline_query_result.js +1 -1
- package/script/utilities/0_part_stream.d.ts +1 -1
- package/script/utilities/0_part_stream.d.ts.map +1 -1
- package/script/utilities/0_part_stream.js +2 -2
package/esm/client/5_client.js
CHANGED
|
@@ -203,7 +203,7 @@ export class Client extends Composer {
|
|
|
203
203
|
messageStorage: this.messageStorage,
|
|
204
204
|
guaranteeUpdateDelivery: this.#guaranteeUpdateDelivery,
|
|
205
205
|
setConnectionState: this.#propagateConnectionState.bind(this),
|
|
206
|
-
resetConnectionState: () => this.#stateChangeHandler(this.
|
|
206
|
+
resetConnectionState: () => this.#stateChangeHandler(this.isConnected),
|
|
207
207
|
getSelfId: this.#getSelfId.bind(this),
|
|
208
208
|
getIsPremium: this.#getIsPremium.bind(this),
|
|
209
209
|
getInputPeer: this.getInputPeer.bind(this),
|
|
@@ -215,7 +215,7 @@ export class Client extends Composer {
|
|
|
215
215
|
parseMode: this.#parseMode,
|
|
216
216
|
outgoingMessages: this.#outgoingMessages,
|
|
217
217
|
dropPendingUpdates: params?.dropPendingUpdates,
|
|
218
|
-
|
|
218
|
+
isDisconnected: () => this.isDisconnected,
|
|
219
219
|
langPack: this.platform,
|
|
220
220
|
langCode: this.language,
|
|
221
221
|
};
|
|
@@ -271,7 +271,7 @@ export class Client extends Composer {
|
|
|
271
271
|
};
|
|
272
272
|
client.onConnectionStateChange = this.#onConnectionStateChange.bind(this);
|
|
273
273
|
}
|
|
274
|
-
#newClient(dc, main,
|
|
274
|
+
#newClient(dc, main, isCdn) {
|
|
275
275
|
const client = new ClientEncrypted(dc, this.#apiId, {
|
|
276
276
|
appVersion: this.appVersion,
|
|
277
277
|
deviceModel: this.deviceModel,
|
|
@@ -280,11 +280,11 @@ export class Client extends Composer {
|
|
|
280
280
|
systemLangCode: this.systemLangCode,
|
|
281
281
|
systemVersion: this.systemVersion,
|
|
282
282
|
transportProvider: this.#transportProvider,
|
|
283
|
-
|
|
284
|
-
disableUpdates: !main ||
|
|
283
|
+
isCdn: isCdn,
|
|
284
|
+
disableUpdates: !main || isCdn,
|
|
285
285
|
publicKeys: this.#publicKeys,
|
|
286
286
|
});
|
|
287
|
-
client.connectionCallback = this.#networkStatisticsManager.getTransportReadWriteCallback(
|
|
287
|
+
client.connectionCallback = this.#networkStatisticsManager.getTransportReadWriteCallback(isCdn);
|
|
288
288
|
return client;
|
|
289
289
|
}
|
|
290
290
|
#disconnectAllClients() {
|
|
@@ -302,19 +302,19 @@ export class Client extends Composer {
|
|
|
302
302
|
return this.#clients[0];
|
|
303
303
|
}
|
|
304
304
|
// direct ClientEncrypted property proxies
|
|
305
|
-
get
|
|
306
|
-
return this.#client?.
|
|
305
|
+
get isConnected() {
|
|
306
|
+
return this.#client?.isConnected ?? false;
|
|
307
307
|
}
|
|
308
|
-
get
|
|
309
|
-
return this.#client?.
|
|
308
|
+
get isDisconnected() {
|
|
309
|
+
return this.#client?.isDisconnected ?? true;
|
|
310
310
|
}
|
|
311
311
|
#propagateConnectionState(connectionState) {
|
|
312
312
|
this.#queueHandleCtxUpdate({ connectionState });
|
|
313
313
|
this.#lastPropagatedConnectionState = connectionState;
|
|
314
314
|
}
|
|
315
315
|
#lastPropagatedConnectionState = null;
|
|
316
|
-
#stateChangeHandler = ((
|
|
317
|
-
const connectionState =
|
|
316
|
+
#stateChangeHandler = ((isConnected) => {
|
|
317
|
+
const connectionState = isConnected ? "ready" : "notConnected";
|
|
318
318
|
if (this.#lastPropagatedConnectionState !== connectionState) {
|
|
319
319
|
this.#propagateConnectionState(connectionState);
|
|
320
320
|
}
|
|
@@ -339,7 +339,7 @@ export class Client extends Composer {
|
|
|
339
339
|
async connect() {
|
|
340
340
|
const unlock = await this.#connectMutex.lock();
|
|
341
341
|
try {
|
|
342
|
-
if (this.
|
|
342
|
+
if (this.isConnected) {
|
|
343
343
|
return;
|
|
344
344
|
}
|
|
345
345
|
await this.#initStorage();
|
|
@@ -386,7 +386,7 @@ export class Client extends Composer {
|
|
|
386
386
|
}
|
|
387
387
|
async [handleMigrationError](err) {
|
|
388
388
|
let newDc = String(err.dc);
|
|
389
|
-
if (Math.abs(getDcId(this.#client.dc, this.#client.
|
|
389
|
+
if (Math.abs(getDcId(this.#client.dc, this.#client.isCdn)) >= 10_000) {
|
|
390
390
|
newDc += "-test";
|
|
391
391
|
}
|
|
392
392
|
this.disconnect();
|
|
@@ -430,7 +430,7 @@ export class Client extends Composer {
|
|
|
430
430
|
#lastUpdates = new Date();
|
|
431
431
|
#updateGapRecoveryLoop = new AbortableLoop(async (loop, signal) => {
|
|
432
432
|
await delay(60 * SECOND, { signal });
|
|
433
|
-
if (!this.
|
|
433
|
+
if (!this.isConnected) {
|
|
434
434
|
loop.abort();
|
|
435
435
|
return;
|
|
436
436
|
}
|
|
@@ -440,7 +440,7 @@ export class Client extends Composer {
|
|
|
440
440
|
}));
|
|
441
441
|
}
|
|
442
442
|
}, (loop, err) => {
|
|
443
|
-
if (!this.
|
|
443
|
+
if (!this.isConnected) {
|
|
444
444
|
loop.abort();
|
|
445
445
|
}
|
|
446
446
|
else {
|
|
@@ -449,19 +449,19 @@ export class Client extends Composer {
|
|
|
449
449
|
});
|
|
450
450
|
#clientDisconnectionLoop = new AbortableLoop(async (loop, signal) => {
|
|
451
451
|
await delay(60 * SECOND, { signal });
|
|
452
|
-
if (!this.
|
|
452
|
+
if (!this.isConnected) {
|
|
453
453
|
loop.abort();
|
|
454
454
|
return;
|
|
455
455
|
}
|
|
456
456
|
const now = Date.now();
|
|
457
457
|
const disconnectAfter = 5 * MINUTE;
|
|
458
458
|
for (const [i, client] of this.#clients.entries()) {
|
|
459
|
-
if (i > 0 && !client.
|
|
459
|
+
if (i > 0 && !client.isDisconnected && client.lastRequest && now - client.lastRequest.getTime() >= disconnectAfter) {
|
|
460
460
|
client?.disconnect();
|
|
461
461
|
}
|
|
462
462
|
}
|
|
463
463
|
}, (loop) => {
|
|
464
|
-
if (!this.
|
|
464
|
+
if (!this.isConnected) {
|
|
465
465
|
loop.abort();
|
|
466
466
|
}
|
|
467
467
|
});
|
|
@@ -521,7 +521,7 @@ export class Client extends Composer {
|
|
|
521
521
|
*/
|
|
522
522
|
async checkCode(code) {
|
|
523
523
|
const result = await this.#accountManager.checkCode(code);
|
|
524
|
-
if (result.type === "
|
|
524
|
+
if (result.type === "signedIn") {
|
|
525
525
|
await this.storage.auth.update((v) => {
|
|
526
526
|
v.userId = result.userId;
|
|
527
527
|
v.isBot = false;
|
|
@@ -549,7 +549,7 @@ export class Client extends Composer {
|
|
|
549
549
|
*/
|
|
550
550
|
async checkPassword(password) {
|
|
551
551
|
const result = await this.#accountManager.checkPassword(password);
|
|
552
|
-
if (result.type === "
|
|
552
|
+
if (result.type === "signedIn") {
|
|
553
553
|
await this.storage.auth.update((v) => {
|
|
554
554
|
v.userId = result.userId;
|
|
555
555
|
v.isBot = false;
|
|
@@ -572,14 +572,14 @@ export class Client extends Composer {
|
|
|
572
572
|
const me = await this.#checkAuthorization();
|
|
573
573
|
if (me) {
|
|
574
574
|
return {
|
|
575
|
-
type: "
|
|
575
|
+
type: "signedIn",
|
|
576
576
|
userId: me.id,
|
|
577
577
|
};
|
|
578
578
|
}
|
|
579
579
|
while (true) {
|
|
580
580
|
try {
|
|
581
581
|
const result = await this.#accountManager.checkBotToken(botToken, this.#apiId, this.#apiHash);
|
|
582
|
-
if (result.type === "
|
|
582
|
+
if (result.type === "signedIn") {
|
|
583
583
|
await this.storage.auth.update((v) => {
|
|
584
584
|
v.userId = result.userId;
|
|
585
585
|
v.isBot = true;
|
|
@@ -648,7 +648,7 @@ export class Client extends Composer {
|
|
|
648
648
|
client = await this.#getUploadClient();
|
|
649
649
|
break;
|
|
650
650
|
}
|
|
651
|
-
if (client !== this.#client && !this.
|
|
651
|
+
if (client !== this.#client && !this.isDisconnected && client.isDisconnected) {
|
|
652
652
|
await client.connect();
|
|
653
653
|
}
|
|
654
654
|
return client;
|
|
@@ -715,7 +715,7 @@ export class Client extends Composer {
|
|
|
715
715
|
return client;
|
|
716
716
|
}
|
|
717
717
|
async #setupClient(client) {
|
|
718
|
-
const storage = client.dc === this.#client.dc ? this.storage : new StorageOperations(this.storage.provider.branch(client.dc + (client.
|
|
718
|
+
const storage = client.dc === this.#client.dc ? this.storage : new StorageOperations(this.storage.provider.branch(client.dc + (client.isCdn ? "_cdn" : "")));
|
|
719
719
|
await storage.initialize();
|
|
720
720
|
const auth = storage.auth.mustGet();
|
|
721
721
|
const serverSalt = await storage.getServerSalt();
|
|
@@ -738,7 +738,7 @@ export class Client extends Composer {
|
|
|
738
738
|
}
|
|
739
739
|
}
|
|
740
740
|
async #importAuthorization(client) {
|
|
741
|
-
if (this.#client.dc === client.dc && this.#client.
|
|
741
|
+
if (this.#client.dc === client.dc && this.#client.isCdn === client.isCdn) {
|
|
742
742
|
const auth = this.storage.auth.mustGet();
|
|
743
743
|
const serverSalt = await this.storage.getServerSalt();
|
|
744
744
|
if (auth.authKey !== null) {
|
|
@@ -749,7 +749,7 @@ export class Client extends Composer {
|
|
|
749
749
|
}
|
|
750
750
|
return;
|
|
751
751
|
}
|
|
752
|
-
const exportedAuthorization = await this.#client.invoke({ _: "auth.exportAuthorization", dc_id: getDcId(client.dc, client.
|
|
752
|
+
const exportedAuthorization = await this.#client.invoke({ _: "auth.exportAuthorization", dc_id: getDcId(client.dc, client.isCdn) });
|
|
753
753
|
await client.invoke({ ...exportedAuthorization, _: "auth.importAuthorization" });
|
|
754
754
|
}
|
|
755
755
|
async #invoke(function_, params) {
|
|
@@ -783,7 +783,7 @@ export class Client extends Composer {
|
|
|
783
783
|
await this.#importAuthorization(client);
|
|
784
784
|
continue;
|
|
785
785
|
}
|
|
786
|
-
else if (err instanceof ConnectionError && !main && !this.
|
|
786
|
+
else if (err instanceof ConnectionError && !main && !this.isDisconnected) {
|
|
787
787
|
continue;
|
|
788
788
|
}
|
|
789
789
|
else if (await this.#handleInvokeError(Object.freeze({ client: this, error: err, function: function_, n: n++ }), () => Promise.resolve(false))) {
|
|
@@ -821,7 +821,7 @@ export class Client extends Composer {
|
|
|
821
821
|
}
|
|
822
822
|
#authStringImported = false;
|
|
823
823
|
async importAuthString(authString) {
|
|
824
|
-
if (this.
|
|
824
|
+
if (this.isConnected) {
|
|
825
825
|
throw new Error("Cannot import auth string while the client is connected");
|
|
826
826
|
}
|
|
827
827
|
await this.#initStorage();
|
|
@@ -1138,15 +1138,15 @@ export class Client extends Composer {
|
|
|
1138
1138
|
}
|
|
1139
1139
|
#previouslyConnected = false;
|
|
1140
1140
|
#lastConnectionState = false;
|
|
1141
|
-
#onConnectionStateChange(
|
|
1142
|
-
if (this.#lastConnectionState !==
|
|
1143
|
-
if (
|
|
1141
|
+
#onConnectionStateChange(isConnected) {
|
|
1142
|
+
if (this.#lastConnectionState !== isConnected) {
|
|
1143
|
+
if (isConnected) {
|
|
1144
1144
|
if (this.#previouslyConnected) {
|
|
1145
1145
|
drop(this.#updateManager.recoverUpdateGap("reconnect"));
|
|
1146
1146
|
}
|
|
1147
1147
|
this.#previouslyConnected = true;
|
|
1148
1148
|
}
|
|
1149
|
-
const connectionState =
|
|
1149
|
+
const connectionState = isConnected ? "ready" : "notConnected";
|
|
1150
1150
|
this.#queueHandleCtxUpdate({ connectionState });
|
|
1151
1151
|
}
|
|
1152
1152
|
}
|
|
@@ -23,8 +23,8 @@ export interface ConnectionCallback {
|
|
|
23
23
|
write(count: number): void;
|
|
24
24
|
}
|
|
25
25
|
export interface Connection {
|
|
26
|
-
get
|
|
27
|
-
stateChangeHandler?: (
|
|
26
|
+
get isConnected(): boolean;
|
|
27
|
+
stateChangeHandler?: (isConnected: boolean) => void;
|
|
28
28
|
open(): MaybePromise<void>;
|
|
29
29
|
write(p: Uint8Array): MaybePromise<void>;
|
|
30
30
|
close(): MaybePromise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"0_connection.d.ts","sourceRoot":"","sources":["../../src/connection/0_connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,
|
|
1
|
+
{"version":3,"file":"0_connection.d.ts","sourceRoot":"","sources":["../../src/connection/0_connection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,WAAW,kBAAkB;IACjC,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,WAAW,IAAI,OAAO,CAAC;IAC3B,kBAAkB,CAAC,EAAE,CAAC,WAAW,EAAE,OAAO,KAAK,IAAI,CAAC;IACpD,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IAC3B,KAAK,CAAC,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IACzC,KAAK,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;IAC5B,QAAQ,CAAC,EAAE,kBAAkB,CAAC;IAC9B,IAAI,CAAC,CAAC,EAAE,UAAU,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;CACzC"}
|
|
@@ -23,7 +23,7 @@ export declare class ConnectionTCP implements Connection {
|
|
|
23
23
|
stateChangeHandler?: Connection["stateChangeHandler"];
|
|
24
24
|
constructor(hostname: string, port: number);
|
|
25
25
|
open(): Promise<void> | undefined;
|
|
26
|
-
get
|
|
26
|
+
get isConnected(): boolean;
|
|
27
27
|
read(p: Uint8Array): Promise<void>;
|
|
28
28
|
write(p: Uint8Array): Promise<void>;
|
|
29
29
|
close(): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1_connection_tcp.node.d.ts","sourceRoot":"","sources":["../../src/connection/1_connection_tcp.node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,qBAAa,aAAc,YAAW,UAAU;;IAW9C,kBAAkB,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;gBAE1C,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAY1C,IAAI;IA2CJ,IAAI,
|
|
1
|
+
{"version":3,"file":"1_connection_tcp.node.d.ts","sourceRoot":"","sources":["../../src/connection/1_connection_tcp.node.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAKH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,qBAAa,aAAc,YAAW,UAAU;;IAW9C,kBAAkB,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;gBAE1C,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAY1C,IAAI;IA2CJ,IAAI,WAAW,YAEd;IAQK,IAAI,CAAC,CAAC,EAAE,UAAU;IAclB,KAAK,CAAC,CAAC,EAAE,UAAU;IA0BzB,KAAK;CAKN"}
|
|
@@ -42,7 +42,7 @@ export class ConnectionTCP {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
open() {
|
|
45
|
-
if (this.
|
|
45
|
+
if (this.isConnected) {
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
this.#socket = new Socket();
|
|
@@ -74,11 +74,11 @@ export class ConnectionTCP {
|
|
|
74
74
|
});
|
|
75
75
|
});
|
|
76
76
|
}
|
|
77
|
-
get
|
|
77
|
+
get isConnected() {
|
|
78
78
|
return this.#socket?.readyState === "open";
|
|
79
79
|
}
|
|
80
80
|
#assertConnected() {
|
|
81
|
-
if (!this.
|
|
81
|
+
if (!this.isConnected) {
|
|
82
82
|
throw errConnectionNotOpen;
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -109,7 +109,7 @@ export class ConnectionTCP {
|
|
|
109
109
|
});
|
|
110
110
|
}
|
|
111
111
|
catch (err) {
|
|
112
|
-
if (!this.
|
|
112
|
+
if (!this.isConnected) {
|
|
113
113
|
throw errConnectionNotOpen;
|
|
114
114
|
}
|
|
115
115
|
else {
|
|
@@ -3,7 +3,7 @@ export declare class ConnectionWebSocket implements Connection {
|
|
|
3
3
|
#private;
|
|
4
4
|
stateChangeHandler?: Connection["stateChangeHandler"];
|
|
5
5
|
constructor(url: string);
|
|
6
|
-
get
|
|
6
|
+
get isConnected(): boolean;
|
|
7
7
|
open(): Promise<void>;
|
|
8
8
|
read(p: Uint8Array): Promise<void>;
|
|
9
9
|
write(p: Uint8Array): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1_connection_web_socket.d.ts","sourceRoot":"","sources":["../../src/connection/1_connection_web_socket.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,qBAAa,mBAAoB,YAAW,UAAU;;IAOpD,kBAAkB,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;gBAE1C,GAAG,EAAE,MAAM;IA8CvB,IAAI,
|
|
1
|
+
{"version":3,"file":"1_connection_web_socket.d.ts","sourceRoot":"","sources":["../../src/connection/1_connection_web_socket.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,qBAAa,mBAAoB,YAAW,UAAU;;IAOpD,kBAAkB,CAAC,EAAE,UAAU,CAAC,oBAAoB,CAAC,CAAC;gBAE1C,GAAG,EAAE,MAAM;IA8CvB,IAAI,WAAW,IAAI,OAAO,CAEzB;IAGK,IAAI;IAmBJ,IAAI,CAAC,CAAC,EAAE,UAAU;IAgBlB,KAAK,CAAC,CAAC,EAAE,UAAU;IAkBzB,KAAK;CAMN"}
|
|
@@ -64,13 +64,13 @@ export class ConnectionWebSocket {
|
|
|
64
64
|
if (this.#isConnecting) {
|
|
65
65
|
reject("message" in err ? new ConnectionError(err.message) : new ConnectionError("Failed to connect."));
|
|
66
66
|
}
|
|
67
|
-
if (this.
|
|
67
|
+
if (this.isConnected) {
|
|
68
68
|
L.error(err);
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
get
|
|
73
|
+
get isConnected() {
|
|
74
74
|
return !!this.#webSocket && this.#webSocket.readyState === dntShim.WebSocket.OPEN;
|
|
75
75
|
}
|
|
76
76
|
#isConnecting = false;
|
|
@@ -87,7 +87,7 @@ export class ConnectionWebSocket {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
#assertConnected() {
|
|
90
|
-
if (!this.
|
|
90
|
+
if (!this.isConnected) {
|
|
91
91
|
throw errConnectionNotOpen;
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -9,7 +9,7 @@ export interface SessionParams {
|
|
|
9
9
|
/**
|
|
10
10
|
* Whether the connection is with a CDN server. Defaults to false.
|
|
11
11
|
*/
|
|
12
|
-
|
|
12
|
+
isCdn?: boolean;
|
|
13
13
|
}
|
|
14
14
|
export declare abstract class Session {
|
|
15
15
|
#private;
|
|
@@ -19,13 +19,13 @@ export declare abstract class Session {
|
|
|
19
19
|
set onConnectionStateChange(onConnectionStateChange: Connection["stateChangeHandler"]);
|
|
20
20
|
set connectionCallback(connectionCallback: ConnectionCallback | undefined);
|
|
21
21
|
get dc(): DC;
|
|
22
|
-
get
|
|
22
|
+
get isCdn(): boolean;
|
|
23
23
|
set serverSalt(serverSalt: bigint);
|
|
24
24
|
get serverSalt(): bigint;
|
|
25
|
-
get
|
|
25
|
+
get isConnected(): boolean;
|
|
26
26
|
connect(): Promise<void>;
|
|
27
27
|
protected waitUntilConnected(): Promise<void>;
|
|
28
|
-
get
|
|
28
|
+
get isDisconnected(): boolean;
|
|
29
29
|
disconnect(): void;
|
|
30
30
|
abstract send(body: Uint8Array): Promise<bigint>;
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1_session.d.ts","sourceRoot":"","sources":["../../src/session/1_session.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAoD,MAAM,mBAAmB,CAAC;AACtH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAQpD,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;OAEG;IACH,
|
|
1
|
+
{"version":3,"file":"1_session.d.ts","sourceRoot":"","sources":["../../src/session/1_session.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAoD,MAAM,mBAAmB,CAAC;AACtH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAQpD,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,8BAAsB,OAAO;;IAG3B,SAAS,CAAC,KAAK,EAAE,YAAY,CAAsB;IACnD,SAAS,CAAC,SAAS,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC;gBAMvC,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,aAAa;IAc1C,IAAI,uBAAuB,CAAC,uBAAuB,EAAE,UAAU,CAAC,oBAAoB,CAAC,EAEpF;IAED,IAAI,kBAAkB,CAAC,kBAAkB,EAAE,kBAAkB,GAAG,SAAS,EAExE;IAED,IAAI,EAAE,IAAI,EAAE,CAEX;IAED,IAAI,KAAK,IAAI,OAAO,CAEnB;IAED,IAAI,UAAU,CAAC,UAAU,EAAE,MAAM,EAEhC;IAED,IAAI,UAAU,IAAI,MAAM,CAEvB;IA6BD,IAAI,WAAW,IAAI,OAAO,CAEzB;IAGK,OAAO;cAeG,kBAAkB;IAIlC,IAAI,cAAc,IAAI,OAAO,CAE5B;IAED,UAAU;IAOV,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;CACjD"}
|
package/esm/session/1_session.js
CHANGED
|
@@ -28,18 +28,18 @@ let id = 0;
|
|
|
28
28
|
const defaultTransportProvider = typeof dntShim.Deno === "undefined" ? transportProviderWebSocket : transportProviderTcp;
|
|
29
29
|
export class Session {
|
|
30
30
|
#dc;
|
|
31
|
-
#
|
|
31
|
+
#isCdn;
|
|
32
32
|
state = new SessionState();
|
|
33
33
|
transport;
|
|
34
34
|
#lastConnect;
|
|
35
|
-
#
|
|
35
|
+
#isDisconnected = true;
|
|
36
36
|
#L;
|
|
37
37
|
#onConnectionStateChange;
|
|
38
38
|
constructor(dc, params) {
|
|
39
39
|
this.#dc = dc;
|
|
40
|
-
this.#
|
|
40
|
+
this.#isCdn = params?.isCdn ?? false;
|
|
41
41
|
const transportProvider = params?.transportProvider ?? defaultTransportProvider();
|
|
42
|
-
this.transport = transportProvider({ dc: this.#dc,
|
|
42
|
+
this.transport = transportProvider({ dc: this.#dc, isCdn: this.#isCdn });
|
|
43
43
|
this.transport.connection.stateChangeHandler = (connected) => {
|
|
44
44
|
setTimeout(() => {
|
|
45
45
|
drop(this.#stateChangeHandler(connected));
|
|
@@ -56,8 +56,8 @@ export class Session {
|
|
|
56
56
|
get dc() {
|
|
57
57
|
return this.#dc;
|
|
58
58
|
}
|
|
59
|
-
get
|
|
60
|
-
return this.#
|
|
59
|
+
get isCdn() {
|
|
60
|
+
return this.#isCdn;
|
|
61
61
|
}
|
|
62
62
|
set serverSalt(serverSalt) {
|
|
63
63
|
this.state.serverSalt = serverSalt;
|
|
@@ -66,18 +66,18 @@ export class Session {
|
|
|
66
66
|
return this.state.serverSalt;
|
|
67
67
|
}
|
|
68
68
|
#lastState;
|
|
69
|
-
async #stateChangeHandler(
|
|
70
|
-
if (this.#lastState !==
|
|
69
|
+
async #stateChangeHandler(isConnected) {
|
|
70
|
+
if (this.#lastState !== isConnected) {
|
|
71
71
|
setTimeout(() => {
|
|
72
|
-
this.#onConnectionStateChange?.(
|
|
72
|
+
this.#onConnectionStateChange?.(isConnected);
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
-
if (this.#lastState ===
|
|
75
|
+
if (this.#lastState === isConnected) {
|
|
76
76
|
return;
|
|
77
77
|
}
|
|
78
|
-
this.#lastState =
|
|
79
|
-
if (
|
|
80
|
-
if (this.#
|
|
78
|
+
this.#lastState = isConnected;
|
|
79
|
+
if (isConnected || this.#isDisconnected) {
|
|
80
|
+
if (this.#isDisconnected) {
|
|
81
81
|
this.#L.debug("not reconnecting because explicitly disconnected");
|
|
82
82
|
}
|
|
83
83
|
return;
|
|
@@ -91,20 +91,20 @@ export class Session {
|
|
|
91
91
|
}
|
|
92
92
|
await this.connect();
|
|
93
93
|
}
|
|
94
|
-
get
|
|
95
|
-
return this.transport.connection.
|
|
94
|
+
get isConnected() {
|
|
95
|
+
return this.transport.connection.isConnected;
|
|
96
96
|
}
|
|
97
97
|
#connectMutex = new Mutex();
|
|
98
98
|
async connect() {
|
|
99
99
|
const unlock = await this.#connectMutex.lock();
|
|
100
100
|
try {
|
|
101
|
-
if (this.
|
|
101
|
+
if (this.isConnected) {
|
|
102
102
|
return;
|
|
103
103
|
}
|
|
104
104
|
await this.transport.connection.open();
|
|
105
105
|
await this.transport.transport.initialize();
|
|
106
106
|
this.#lastConnect = new Date();
|
|
107
|
-
this.#
|
|
107
|
+
this.#isDisconnected = false;
|
|
108
108
|
}
|
|
109
109
|
finally {
|
|
110
110
|
unlock();
|
|
@@ -113,12 +113,12 @@ export class Session {
|
|
|
113
113
|
async waitUntilConnected() {
|
|
114
114
|
(await this.#connectMutex.lock())();
|
|
115
115
|
}
|
|
116
|
-
get
|
|
117
|
-
return this.#
|
|
116
|
+
get isDisconnected() {
|
|
117
|
+
return this.#isDisconnected;
|
|
118
118
|
}
|
|
119
119
|
disconnect() {
|
|
120
|
-
this.#
|
|
121
|
-
if (this.transport.connection.
|
|
120
|
+
this.#isDisconnected = true;
|
|
121
|
+
if (this.transport.connection.isConnected) {
|
|
122
122
|
this.transport.connection.close();
|
|
123
123
|
}
|
|
124
124
|
}
|
|
@@ -62,7 +62,7 @@ export class SessionEncrypted extends Session {
|
|
|
62
62
|
return this.#authKey;
|
|
63
63
|
}
|
|
64
64
|
async connect() {
|
|
65
|
-
if (!this.
|
|
65
|
+
if (!this.isConnected) {
|
|
66
66
|
this.#rejectAllPending(new ConnectionError("The connection was closed."));
|
|
67
67
|
}
|
|
68
68
|
await super.connect();
|
|
@@ -84,7 +84,7 @@ export class SessionEncrypted extends Session {
|
|
|
84
84
|
this.#rejectAllPending(new ConnectionError("The connection was disconnected."));
|
|
85
85
|
}
|
|
86
86
|
#assertNotDisconnected() {
|
|
87
|
-
if (this.
|
|
87
|
+
if (this.isDisconnected) {
|
|
88
88
|
throw new ConnectionError("The connection was disconnected.");
|
|
89
89
|
}
|
|
90
90
|
}
|
|
@@ -144,7 +144,7 @@ export class SessionEncrypted extends Session {
|
|
|
144
144
|
this.handlers.onNewServerSalt?.(newServerSalt);
|
|
145
145
|
}
|
|
146
146
|
async send(body) {
|
|
147
|
-
if (!this.
|
|
147
|
+
if (!this.isDisconnected && !this.isConnected) {
|
|
148
148
|
await super.waitUntilConnected();
|
|
149
149
|
}
|
|
150
150
|
this.#assertNotDisconnected();
|
|
@@ -211,7 +211,7 @@ export class SessionEncrypted extends Session {
|
|
|
211
211
|
this.#LsendLoop.error("unhandled receive loop error:", err);
|
|
212
212
|
});
|
|
213
213
|
async #sendLoopBody(loop, signal) {
|
|
214
|
-
if (!this.
|
|
214
|
+
if (!this.isConnected) {
|
|
215
215
|
this.#LsendLoop.debug("aborting as not connected");
|
|
216
216
|
loop.abort();
|
|
217
217
|
return;
|
|
@@ -295,7 +295,7 @@ export class SessionEncrypted extends Session {
|
|
|
295
295
|
}
|
|
296
296
|
catch (err) {
|
|
297
297
|
this.#LreceiveLoop.error("failed to receive message:", err);
|
|
298
|
-
if (!this.
|
|
298
|
+
if (!this.isConnected) {
|
|
299
299
|
this.#LreceiveLoop.debug("aborting as not connected");
|
|
300
300
|
loop.abort();
|
|
301
301
|
return;
|
|
@@ -24,7 +24,7 @@ import { TLWriter } from "../tl/1_tl_writer.js";
|
|
|
24
24
|
import { Session } from "./1_session.js";
|
|
25
25
|
export class SessionPlain extends Session {
|
|
26
26
|
async send(data) {
|
|
27
|
-
if (!this.
|
|
27
|
+
if (!this.isConnected) {
|
|
28
28
|
throw new ConnectionError("The connection is not open.");
|
|
29
29
|
}
|
|
30
30
|
const messageId = this.state.nextMessageId();
|
|
@@ -38,7 +38,7 @@ export class SessionPlain extends Session {
|
|
|
38
38
|
return messageId;
|
|
39
39
|
}
|
|
40
40
|
async receive() {
|
|
41
|
-
if (!this.
|
|
41
|
+
if (!this.isConnected) {
|
|
42
42
|
throw new ConnectionError("The connection is not open.");
|
|
43
43
|
}
|
|
44
44
|
const buffer = await this.transport.transport.receive();
|
|
@@ -23,13 +23,13 @@ export type DC = "1" | "2" | "3" | "4" | "5" | "1-test" | "2-test" | "3-test";
|
|
|
23
23
|
export declare function getDcIps(dc: DC, version: "ipv4" | "ipv6"): [string, ...string[]];
|
|
24
24
|
export interface TransportProviderParams {
|
|
25
25
|
dc: DC;
|
|
26
|
-
|
|
26
|
+
isCdn: boolean;
|
|
27
27
|
}
|
|
28
28
|
export type TransportProvider = (params: TransportProviderParams) => {
|
|
29
29
|
connection: Connection;
|
|
30
30
|
transport: Transport;
|
|
31
31
|
dcId: number;
|
|
32
32
|
};
|
|
33
|
-
export declare function getDcId(dc: DC,
|
|
33
|
+
export declare function getDcId(dc: DC, isCdn: boolean): number;
|
|
34
34
|
export declare function getDc(dcId: number): DC;
|
|
35
35
|
//# sourceMappingURL=1_transport_provider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"1_transport_provider.d.ts","sourceRoot":"","sources":["../../src/transport/1_transport_provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC9E,wBAAgB,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAiDhF;AAED,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,EAAE,CAAC;IACP,
|
|
1
|
+
{"version":3,"file":"1_transport_provider.d.ts","sourceRoot":"","sources":["../../src/transport/1_transport_provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAC9E,wBAAgB,QAAQ,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,CAAC,CAiDhF;AAED,MAAM,WAAW,uBAAuB;IACtC,EAAE,EAAE,EAAE,CAAC;IACP,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,MAAM,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,uBAAuB,KAAK;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEpI,wBAAgB,OAAO,CAAC,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAEtD;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAOtC"}
|
|
@@ -68,8 +68,8 @@ export function getDcIps(dc, version) {
|
|
|
68
68
|
unreachable();
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
|
-
export function getDcId(dc,
|
|
72
|
-
return Number(dc[0]) + (dc.endsWith("-test") ? 10_000 : 0) * (
|
|
71
|
+
export function getDcId(dc, isCdn) {
|
|
72
|
+
return Number(dc[0]) + (dc.endsWith("-test") ? 10_000 : 0) * (isCdn ? -1 : 1);
|
|
73
73
|
}
|
|
74
74
|
export function getDc(dcId) {
|
|
75
75
|
dcId = Math.abs(dcId);
|
|
@@ -21,7 +21,7 @@ import { ConnectionTCP } from "../connection/1_connection_tcp.node.js";
|
|
|
21
21
|
import { TransportAbridged } from "./1_transport_abridged.js";
|
|
22
22
|
import { getDcId, getDcIps } from "./1_transport_provider.js";
|
|
23
23
|
export function transportProviderTcp(params) {
|
|
24
|
-
return ({ dc, cdn }) => {
|
|
24
|
+
return ({ dc, isCdn: cdn }) => {
|
|
25
25
|
const connection = new ConnectionTCP(getDcIps(dc, params?.ipv6 ? "ipv6" : "ipv4")[0], 80);
|
|
26
26
|
const transport = new TransportAbridged(connection, params?.obfuscated);
|
|
27
27
|
return { connection, transport, dcId: getDcId(dc, cdn) };
|
|
@@ -31,13 +31,13 @@ const dcToNameMap = {
|
|
|
31
31
|
"5": "flora",
|
|
32
32
|
};
|
|
33
33
|
export const transportProviderWebSocket = (params) => {
|
|
34
|
-
return ({ dc,
|
|
34
|
+
return ({ dc, isCdn }) => {
|
|
35
35
|
params ??= {};
|
|
36
36
|
params.wss ??= typeof location !== "undefined" && location.protocol === "http:" && location.hostname !== "localhost" ? false : true;
|
|
37
|
-
const url = `${params.wss ? "wss" : "ws"}://${dcToNameMap[dc]}${
|
|
37
|
+
const url = `${params.wss ? "wss" : "ws"}://${dcToNameMap[dc]}${isCdn ? "-1" : ""}.web.telegram.org/${dc.endsWith("-test") ? "apiws_test" : "apiws"}`;
|
|
38
38
|
const connection = new ConnectionWebSocket(url);
|
|
39
39
|
const transport = new TransportIntermediate(connection, true);
|
|
40
|
-
const dcId = getDcId(dc,
|
|
40
|
+
const dcId = getDcId(dc, isCdn);
|
|
41
41
|
return { connection, transport, dcId };
|
|
42
42
|
};
|
|
43
43
|
};
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
*/
|
|
24
24
|
export interface BotTokenCheckResultSignedIn {
|
|
25
25
|
/** @discriminator */
|
|
26
|
-
type: "
|
|
26
|
+
type: "signedIn";
|
|
27
27
|
userId: number;
|
|
28
28
|
}
|
|
29
|
-
/** A result after checking a
|
|
29
|
+
/** A result after checking a bot token. */
|
|
30
30
|
export type BotTokenCheckResult = BotTokenCheckResultSignedIn;
|
|
31
31
|
//# sourceMappingURL=0_bot_token_check_result.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"0_bot_token_check_result.d.ts","sourceRoot":"","sources":["../../src/types/0_bot_token_check_result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C,qBAAqB;IACrB,IAAI,EAAE,
|
|
1
|
+
{"version":3,"file":"0_bot_token_check_result.d.ts","sourceRoot":"","sources":["../../src/types/0_bot_token_check_result.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;;;GAGG;AACH,MAAM,WAAW,2BAA2B;IAC1C,qBAAqB;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,2CAA2C;AAC3C,MAAM,MAAM,mBAAmB,GAAG,2BAA2B,CAAC"}
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
export interface CodeCheckResultPasswordRequired {
|
|
25
25
|
/** @discriminator */
|
|
26
|
-
type: "
|
|
26
|
+
type: "passwordRequired";
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* The code entered was incorrect.
|
|
@@ -31,7 +31,7 @@ export interface CodeCheckResultPasswordRequired {
|
|
|
31
31
|
*/
|
|
32
32
|
export interface CodeCheckResultInvalidCode {
|
|
33
33
|
/** @discriminator */
|
|
34
|
-
type: "
|
|
34
|
+
type: "invalidCode";
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* The code was correct. The user was signed in.
|
|
@@ -39,7 +39,7 @@ export interface CodeCheckResultInvalidCode {
|
|
|
39
39
|
*/
|
|
40
40
|
export interface CodeCheckResultSignedIn {
|
|
41
41
|
/** @discriminator */
|
|
42
|
-
type: "
|
|
42
|
+
type: "signedIn";
|
|
43
43
|
userId: number;
|
|
44
44
|
}
|
|
45
45
|
/** The result after checking a sent code. */
|