@mtkruto/node 0.67.2 → 0.68.0
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/0_errors.js +2 -6
- package/esm/3_errors.js +2 -12
- package/esm/3_types.d.ts +1 -0
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +1 -0
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +99 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +127 -1
- package/esm/_dnt.test_polyfills.d.ts.map +1 -0
- package/esm/client/0_filters_test.d.ts.map +1 -1
- package/esm/client/0_markdown_test.d.ts.map +1 -1
- package/esm/client/0_params.d.ts +2 -0
- package/esm/client/0_params.d.ts.map +1 -1
- package/esm/client/0_password.d.ts +5 -5
- package/esm/client/0_password.d.ts.map +1 -1
- package/esm/client/0_password_test.d.ts.map +1 -1
- package/esm/client/0_storage_operations.js +143 -155
- package/esm/client/0_storage_operations_test.d.ts.map +1 -1
- package/esm/client/0_utilities.d.ts +1 -1
- package/esm/client/0_utilities_test.d.ts.map +1 -1
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/1_composer.js +8 -21
- package/esm/client/2_account_manager.js +85 -97
- package/esm/client/2_bot_info_manager.js +26 -38
- package/esm/client/2_business_connection_manager.js +10 -23
- package/esm/client/2_client_encrypted.js +194 -211
- package/esm/client/2_file_manager.d.ts +4 -3
- package/esm/client/2_file_manager.d.ts.map +1 -1
- package/esm/client/2_file_manager.js +268 -224
- package/esm/client/2_file_manager_test.d.ts.map +1 -1
- package/esm/client/2_network_statistics_manager.js +8 -21
- package/esm/client/2_payment_manager.js +7 -20
- package/esm/client/2_reaction_manager.js +7 -20
- package/esm/client/2_translations_manager.js +97 -107
- package/esm/client/2_update_manager.js +764 -759
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_client_encrypted_pool_test.d.ts.map +1 -1
- package/esm/client/3_message_manager.d.ts +1 -1
- package/esm/client/3_message_manager.js +441 -448
- package/esm/client/3_message_manager_test.d.ts.map +1 -1
- package/esm/client/3_video_chat_manager.d.ts +1 -1
- package/esm/client/3_video_chat_manager.js +57 -68
- package/esm/client/4_callback_query_manager.js +18 -30
- package/esm/client/4_chat_list_manager.js +322 -318
- package/esm/client/4_chat_manager.js +118 -131
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +16 -29
- package/esm/client/4_inline_query_manager.js +16 -28
- package/esm/client/4_link_preview_manager.js +6 -19
- package/esm/client/4_poll_manager.js +44 -57
- package/esm/client/4_story_manager.js +41 -53
- package/esm/client/5_client.d.ts +7 -0
- package/esm/client/5_client.d.ts.map +1 -1
- package/esm/client/5_client.js +1269 -1288
- package/esm/connection/1_connection_tcp.node.js +48 -65
- package/esm/connection/1_connection_web_socket.js +75 -91
- package/esm/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/esm/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
- package/esm/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
- package/esm/mod.js +2 -12
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +324 -320
- package/esm/storage/1_utilities_test.d.ts.map +1 -1
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.node.js +12 -25
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/0_utilities_test.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +80 -88
- package/esm/tl/1_tl_reader_test.d.ts.map +1 -1
- package/esm/tl/1_tl_writer.js +155 -164
- package/esm/tl/1_tl_writer_test.d.ts.map +1 -1
- package/esm/transport/0_transport.js +1 -8
- package/esm/transport/1_transport_abridged.js +11 -24
- package/esm/transport/1_transport_intermediate.js +10 -23
- package/esm/transport/2_transport_provider_web_socket.d.ts.map +1 -1
- package/esm/types/0_upload_progress.d.ts +29 -0
- package/esm/types/0_upload_progress.d.ts.map +1 -0
- package/esm/types/0_upload_progress.js +20 -0
- package/esm/types/1_sticker.d.ts +1 -1
- package/esm/types/1_sticker.d.ts.map +1 -1
- package/esm/types/2_poll_answer.d.ts +19 -0
- package/esm/types/2_poll_answer.d.ts.map +1 -1
- package/esm/types/2_poll_answer.js +19 -0
- package/esm/types/7_update.d.ts +21 -2
- package/esm/types/7_update.d.ts.map +1 -1
- package/esm/utilities/0_bigint_test.d.ts.map +1 -1
- package/esm/utilities/0_buffer.d.ts +1 -1
- package/esm/utilities/0_buffer.d.ts.map +1 -1
- package/esm/utilities/0_buffer_test.d.ts.map +1 -1
- package/esm/utilities/0_hash.d.ts +2 -2
- package/esm/utilities/0_hash.d.ts.map +1 -1
- package/esm/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/0_part_stream_test.d.ts.map +1 -1
- package/esm/utilities/0_rle.d.ts +2 -2
- package/esm/utilities/0_rle.d.ts.map +1 -1
- package/esm/utilities/0_rle_test.d.ts.map +1 -1
- package/esm/utilities/0_text.d.ts +20 -1
- package/esm/utilities/0_text.d.ts.map +1 -1
- package/esm/utilities/0_text.js +19 -0
- package/esm/utilities/1_auth.d.ts +1 -1
- package/esm/utilities/1_auth.d.ts.map +1 -1
- package/esm/utilities/1_base64.d.ts +1 -1
- package/esm/utilities/1_base64.d.ts.map +1 -1
- package/esm/utilities/1_base64_test.d.ts.map +1 -1
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/1_crypto_test.d.ts.map +1 -1
- package/esm/utilities/1_logger.d.ts +2 -2
- package/esm/utilities/1_math_test.d.ts.map +1 -1
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.js +2 -6
- package/script/2_tl.js +17 -7
- package/script/3_errors.js +2 -12
- package/script/3_types.d.ts +1 -0
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +1 -0
- package/script/4_constants.js +17 -7
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +99 -0
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +128 -0
- package/script/_dnt.test_polyfills.d.ts.map +1 -0
- package/script/client/0_filters_test.d.ts.map +1 -1
- package/script/client/0_markdown_test.d.ts.map +1 -1
- package/script/client/0_params.d.ts +2 -0
- package/script/client/0_params.d.ts.map +1 -1
- package/script/client/0_password.d.ts +5 -5
- package/script/client/0_password.d.ts.map +1 -1
- package/script/client/0_password.js +17 -7
- package/script/client/0_password_test.d.ts.map +1 -1
- package/script/client/0_storage_operations.js +143 -155
- package/script/client/0_storage_operations_test.d.ts.map +1 -1
- package/script/client/0_utilities.d.ts +1 -1
- package/script/client/0_utilities_test.d.ts.map +1 -1
- package/script/client/1_client_plain.js +4 -22
- package/script/client/1_composer.js +8 -21
- package/script/client/2_account_manager.js +85 -97
- package/script/client/2_bot_info_manager.js +26 -38
- package/script/client/2_business_connection_manager.js +10 -23
- package/script/client/2_client_encrypted.js +195 -212
- package/script/client/2_file_manager.d.ts +4 -3
- package/script/client/2_file_manager.d.ts.map +1 -1
- package/script/client/2_file_manager.js +285 -231
- package/script/client/2_file_manager_test.d.ts.map +1 -1
- package/script/client/2_network_statistics_manager.js +8 -21
- package/script/client/2_payment_manager.js +7 -20
- package/script/client/2_reaction_manager.js +7 -20
- package/script/client/2_translations_manager.js +98 -108
- package/script/client/2_update_manager.js +764 -759
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_client_encrypted_pool_test.d.ts.map +1 -1
- package/script/client/3_message_manager.d.ts +1 -1
- package/script/client/3_message_manager.js +441 -448
- package/script/client/3_message_manager_test.d.ts.map +1 -1
- package/script/client/3_video_chat_manager.d.ts +1 -1
- package/script/client/3_video_chat_manager.js +57 -68
- package/script/client/4_callback_query_manager.js +18 -30
- package/script/client/4_chat_list_manager.js +322 -318
- package/script/client/4_chat_manager.js +118 -131
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +16 -29
- package/script/client/4_inline_query_manager.js +16 -28
- package/script/client/4_link_preview_manager.js +6 -19
- package/script/client/4_poll_manager.js +44 -57
- package/script/client/4_story_manager.js +41 -53
- package/script/client/5_client.d.ts +7 -0
- package/script/client/5_client.d.ts.map +1 -1
- package/script/client/5_client.js +1269 -1288
- package/script/connection/1_connection_tcp.node.js +48 -65
- package/script/connection/1_connection_web_socket.js +92 -98
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/assert/1.0.13/equal.js +17 -7
- package/script/deps/jsr.io/@std/async/1.0.13/delay.js +17 -7
- package/script/deps/jsr.io/@std/async/1.0.13/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.0.13/tee.js +11 -34
- package/script/deps/jsr.io/@std/datetime/0.225.5/_date_time_formatter.js +4 -17
- package/script/deps/jsr.io/@std/internal/1.0.10/format.js +17 -7
- package/script/deps/jsr.io/@std/internal/1.0.10/styles.js +17 -7
- package/script/deps/jsr.io/@std/path/1.1.0/_os.js +17 -7
- package/script/mod.js +19 -19
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +66 -79
- package/script/session/2_session_encrypted.js +325 -321
- package/script/storage/1_utilities_test.d.ts.map +1 -1
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.node.js +12 -25
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/0_utilities_test.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +81 -89
- package/script/tl/1_tl_reader_test.d.ts.map +1 -1
- package/script/tl/1_tl_writer.js +156 -165
- package/script/tl/1_tl_writer_test.d.ts.map +1 -1
- package/script/tl/2_telegram.js +17 -7
- package/script/transport/0_obfuscation.js +17 -7
- package/script/transport/0_transport.js +1 -8
- package/script/transport/1_transport_abridged.js +11 -24
- package/script/transport/1_transport_intermediate.js +10 -23
- package/script/transport/2_transport_provider_web_socket.d.ts.map +1 -1
- package/script/types/0_upload_progress.d.ts +29 -0
- package/script/types/0_upload_progress.d.ts.map +1 -0
- package/script/types/0_upload_progress.js +21 -0
- package/script/types/1_sticker.d.ts +1 -1
- package/script/types/1_sticker.d.ts.map +1 -1
- package/script/types/2_poll_answer.d.ts +19 -0
- package/script/types/2_poll_answer.d.ts.map +1 -1
- package/script/types/2_poll_answer.js +19 -0
- package/script/types/7_update.d.ts +21 -2
- package/script/types/7_update.d.ts.map +1 -1
- package/script/utilities/0_bigint.js +17 -7
- package/script/utilities/0_bigint_test.d.ts.map +1 -1
- package/script/utilities/0_buffer.d.ts +1 -1
- package/script/utilities/0_buffer.d.ts.map +1 -1
- package/script/utilities/0_buffer_test.d.ts.map +1 -1
- package/script/utilities/0_env.js +17 -7
- package/script/utilities/0_hash.d.ts +2 -2
- package/script/utilities/0_hash.d.ts.map +1 -1
- package/script/utilities/0_hash.js +17 -7
- package/script/utilities/0_misc.js +17 -7
- package/script/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/0_part_stream_test.d.ts.map +1 -1
- package/script/utilities/0_rle.d.ts +2 -2
- package/script/utilities/0_rle.d.ts.map +1 -1
- package/script/utilities/0_rle_test.d.ts.map +1 -1
- package/script/utilities/0_text.d.ts +20 -1
- package/script/utilities/0_text.d.ts.map +1 -1
- package/script/utilities/0_text.js +19 -0
- package/script/utilities/1_auth.d.ts +1 -1
- package/script/utilities/1_auth.d.ts.map +1 -1
- package/script/utilities/1_auth.js +17 -7
- package/script/utilities/1_base64.d.ts +1 -1
- package/script/utilities/1_base64.d.ts.map +1 -1
- package/script/utilities/1_base64_test.d.ts.map +1 -1
- package/script/utilities/1_crypto.js +60 -61
- package/script/utilities/1_crypto_test.d.ts.map +1 -1
- package/script/utilities/1_logger.d.ts +2 -2
- package/script/utilities/1_math_test.d.ts.map +1 -1
- package/script/utilities/2_queue.js +30 -48
package/esm/mod.js
CHANGED
|
@@ -35,19 +35,9 @@ if (!("CompressionStream" in dntShim.dntGlobalThis)) {
|
|
|
35
35
|
// original idea: MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource>
|
|
36
36
|
// @see https://github.com/oven-sh/bun/issues/1723#issuecomment-1774174194
|
|
37
37
|
class Stream {
|
|
38
|
+
readable;
|
|
39
|
+
writable;
|
|
38
40
|
constructor(compress, format) {
|
|
39
|
-
Object.defineProperty(this, "readable", {
|
|
40
|
-
enumerable: true,
|
|
41
|
-
configurable: true,
|
|
42
|
-
writable: true,
|
|
43
|
-
value: void 0
|
|
44
|
-
});
|
|
45
|
-
Object.defineProperty(this, "writable", {
|
|
46
|
-
enumerable: true,
|
|
47
|
-
configurable: true,
|
|
48
|
-
writable: true,
|
|
49
|
-
value: void 0
|
|
50
|
-
});
|
|
51
41
|
let handler;
|
|
52
42
|
if (format === "gzip") {
|
|
53
43
|
handler = compress ? createGzip() : createGunzip();
|
|
@@ -17,61 +17,35 @@
|
|
|
17
17
|
* You should have received a copy of the GNU Lesser General Public License
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
21
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
22
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
23
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
24
|
-
};
|
|
25
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
26
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
27
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
28
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
29
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
30
|
-
};
|
|
31
|
-
var _SessionState_seqNo, _SessionState_messageId;
|
|
32
20
|
import { toUnixTimestamp } from "../1_utilities.js";
|
|
33
21
|
export class SessionState {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
writable: true,
|
|
39
|
-
value: 0
|
|
40
|
-
});
|
|
41
|
-
Object.defineProperty(this, "serverSalt", {
|
|
42
|
-
enumerable: true,
|
|
43
|
-
configurable: true,
|
|
44
|
-
writable: true,
|
|
45
|
-
value: 0n
|
|
46
|
-
});
|
|
47
|
-
_SessionState_seqNo.set(this, 0);
|
|
48
|
-
_SessionState_messageId.set(this, 0n);
|
|
49
|
-
}
|
|
22
|
+
timeDifference = 0;
|
|
23
|
+
serverSalt = 0n;
|
|
24
|
+
#seqNo = 0;
|
|
25
|
+
#messageId = 0n;
|
|
50
26
|
nextMessageId() {
|
|
51
27
|
const now = toUnixTimestamp(new Date()) + this.timeDifference;
|
|
52
28
|
const nanoseconds = Math.floor((now - Math.floor(now)) * 1e9);
|
|
53
29
|
const newMessageId = (BigInt(Math.floor(now)) << 32n) || (BigInt(nanoseconds) << 2n);
|
|
54
|
-
if (
|
|
55
|
-
|
|
30
|
+
if (this.#messageId >= newMessageId) {
|
|
31
|
+
this.#messageId += 4n;
|
|
56
32
|
}
|
|
57
33
|
else {
|
|
58
|
-
|
|
34
|
+
this.#messageId = newMessageId;
|
|
59
35
|
}
|
|
60
|
-
return
|
|
36
|
+
return this.#messageId;
|
|
61
37
|
}
|
|
62
38
|
nextSeqNo(contentRelated) {
|
|
63
|
-
|
|
64
|
-
let seqNo = __classPrivateFieldGet(this, _SessionState_seqNo, "f") * 2;
|
|
39
|
+
let seqNo = this.#seqNo * 2;
|
|
65
40
|
if (contentRelated) {
|
|
66
41
|
seqNo++;
|
|
67
|
-
|
|
42
|
+
this.#seqNo++;
|
|
68
43
|
}
|
|
69
44
|
return seqNo;
|
|
70
45
|
}
|
|
71
46
|
reset() {
|
|
72
47
|
this.serverSalt = 0n;
|
|
73
|
-
|
|
74
|
-
|
|
48
|
+
this.#seqNo = 0;
|
|
49
|
+
this.#messageId = 0n;
|
|
75
50
|
}
|
|
76
51
|
}
|
|
77
|
-
_SessionState_seqNo = new WeakMap(), _SessionState_messageId = new WeakMap();
|
package/esm/session/1_session.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _Session_instances, _Session_dc, _Session_cdn, _Session_lastConnect, _Session_disconnected, _Session_L, _Session_onConnectionStateChange, _Session_lastState, _Session_stateChangeHandler, _Session_connectMutex;
|
|
13
1
|
/**
|
|
14
2
|
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
15
3
|
* Copyright (C) 2023-2025 Roj <https://roj.im/>
|
|
@@ -39,107 +27,96 @@ let id = 0;
|
|
|
39
27
|
// @ts-ignore: lib
|
|
40
28
|
const defaultTransportProvider = typeof dntShim.Deno === "undefined" ? transportProviderWebSocket : transportProviderTcp;
|
|
41
29
|
export class Session {
|
|
30
|
+
#dc;
|
|
31
|
+
#cdn;
|
|
32
|
+
state = new SessionState();
|
|
33
|
+
transport;
|
|
34
|
+
#lastConnect;
|
|
35
|
+
#disconnected = true;
|
|
36
|
+
#L;
|
|
37
|
+
#onConnectionStateChange;
|
|
42
38
|
constructor(dc, params) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
_Session_cdn.set(this, void 0);
|
|
46
|
-
Object.defineProperty(this, "state", {
|
|
47
|
-
enumerable: true,
|
|
48
|
-
configurable: true,
|
|
49
|
-
writable: true,
|
|
50
|
-
value: new SessionState()
|
|
51
|
-
});
|
|
52
|
-
Object.defineProperty(this, "transport", {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
configurable: true,
|
|
55
|
-
writable: true,
|
|
56
|
-
value: void 0
|
|
57
|
-
});
|
|
58
|
-
_Session_lastConnect.set(this, void 0);
|
|
59
|
-
_Session_disconnected.set(this, true);
|
|
60
|
-
_Session_L.set(this, void 0);
|
|
61
|
-
_Session_onConnectionStateChange.set(this, void 0);
|
|
62
|
-
_Session_lastState.set(this, void 0);
|
|
63
|
-
_Session_connectMutex.set(this, new Mutex());
|
|
64
|
-
__classPrivateFieldSet(this, _Session_dc, dc, "f");
|
|
65
|
-
__classPrivateFieldSet(this, _Session_cdn, params?.cdn ?? false, "f");
|
|
39
|
+
this.#dc = dc;
|
|
40
|
+
this.#cdn = params?.cdn ?? false;
|
|
66
41
|
const transportProvider = params?.transportProvider ?? defaultTransportProvider();
|
|
67
|
-
this.transport = transportProvider({ dc:
|
|
42
|
+
this.transport = transportProvider({ dc: this.#dc, cdn: this.#cdn });
|
|
68
43
|
this.transport.connection.stateChangeHandler = (connected) => {
|
|
69
44
|
setTimeout(() => {
|
|
70
|
-
drop(
|
|
45
|
+
drop(this.#stateChangeHandler(connected));
|
|
71
46
|
});
|
|
72
47
|
};
|
|
73
|
-
|
|
48
|
+
this.#L = getLogger("Session").client(id++);
|
|
74
49
|
}
|
|
75
50
|
set onConnectionStateChange(onConnectionStateChange) {
|
|
76
|
-
|
|
51
|
+
this.#onConnectionStateChange = onConnectionStateChange;
|
|
77
52
|
}
|
|
78
53
|
set connectionCallback(connectionCallback) {
|
|
79
54
|
this.transport.connection.callback = connectionCallback;
|
|
80
55
|
}
|
|
81
56
|
get dc() {
|
|
82
|
-
return
|
|
57
|
+
return this.#dc;
|
|
83
58
|
}
|
|
84
59
|
get cdn() {
|
|
85
|
-
return
|
|
60
|
+
return this.#cdn;
|
|
86
61
|
}
|
|
87
62
|
set serverSalt(serverSalt) {
|
|
88
63
|
this.state.serverSalt = serverSalt;
|
|
89
64
|
}
|
|
65
|
+
#lastState;
|
|
66
|
+
async #stateChangeHandler(connected) {
|
|
67
|
+
if (this.#lastState !== connected) {
|
|
68
|
+
setTimeout(() => {
|
|
69
|
+
this.#onConnectionStateChange?.(connected);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (this.#lastState === connected) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
this.#lastState = connected;
|
|
76
|
+
if (connected || this.#disconnected) {
|
|
77
|
+
if (this.#disconnected) {
|
|
78
|
+
this.#L.debug("not reconnecting because explicitly disconnected");
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (this.#lastConnect && Date.now() - this.#lastConnect.getTime() <= 10 * SECOND) {
|
|
83
|
+
this.#L.debug("reconnecting after a delay");
|
|
84
|
+
await delay(3 * SECOND);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
this.#L.debug("reconnecting");
|
|
88
|
+
}
|
|
89
|
+
await this.connect();
|
|
90
|
+
}
|
|
90
91
|
get connected() {
|
|
91
92
|
return this.transport.connection.connected;
|
|
92
93
|
}
|
|
94
|
+
#connectMutex = new Mutex();
|
|
93
95
|
async connect() {
|
|
94
|
-
const unlock = await
|
|
96
|
+
const unlock = await this.#connectMutex.lock();
|
|
95
97
|
try {
|
|
96
98
|
if (this.connected) {
|
|
97
99
|
return;
|
|
98
100
|
}
|
|
99
101
|
await this.transport.connection.open();
|
|
100
102
|
await this.transport.transport.initialize();
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
this.#lastConnect = new Date();
|
|
104
|
+
this.#disconnected = false;
|
|
103
105
|
}
|
|
104
106
|
finally {
|
|
105
107
|
unlock();
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
110
|
async waitUntilConnected() {
|
|
109
|
-
(await
|
|
111
|
+
(await this.#connectMutex.lock())();
|
|
110
112
|
}
|
|
111
113
|
get disconnected() {
|
|
112
|
-
return
|
|
114
|
+
return this.#disconnected;
|
|
113
115
|
}
|
|
114
116
|
disconnect() {
|
|
115
|
-
|
|
117
|
+
this.#disconnected = true;
|
|
116
118
|
if (this.transport.connection.connected) {
|
|
117
119
|
this.transport.connection.close();
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
|
-
_Session_dc = new WeakMap(), _Session_cdn = new WeakMap(), _Session_lastConnect = new WeakMap(), _Session_disconnected = new WeakMap(), _Session_L = new WeakMap(), _Session_onConnectionStateChange = new WeakMap(), _Session_lastState = new WeakMap(), _Session_connectMutex = new WeakMap(), _Session_instances = new WeakSet(), _Session_stateChangeHandler = async function _Session_stateChangeHandler(connected) {
|
|
122
|
-
if (__classPrivateFieldGet(this, _Session_lastState, "f") !== connected) {
|
|
123
|
-
setTimeout(() => {
|
|
124
|
-
__classPrivateFieldGet(this, _Session_onConnectionStateChange, "f")?.call(this, connected);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
if (__classPrivateFieldGet(this, _Session_lastState, "f") === connected) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
__classPrivateFieldSet(this, _Session_lastState, connected, "f");
|
|
131
|
-
if (connected || __classPrivateFieldGet(this, _Session_disconnected, "f")) {
|
|
132
|
-
if (__classPrivateFieldGet(this, _Session_disconnected, "f")) {
|
|
133
|
-
__classPrivateFieldGet(this, _Session_L, "f").debug("not reconnecting because explicitly disconnected");
|
|
134
|
-
}
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
if (__classPrivateFieldGet(this, _Session_lastConnect, "f") && Date.now() - __classPrivateFieldGet(this, _Session_lastConnect, "f").getTime() <= 10 * SECOND) {
|
|
138
|
-
__classPrivateFieldGet(this, _Session_L, "f").debug("reconnecting after a delay");
|
|
139
|
-
await delay(3 * SECOND);
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
__classPrivateFieldGet(this, _Session_L, "f").debug("reconnecting");
|
|
143
|
-
}
|
|
144
|
-
await this.connect();
|
|
145
|
-
};
|