@mtkruto/browser 0.119.0 → 0.119.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/0_errors.d.ts.map +1 -1
- package/esm/0_errors.js +9 -31
- package/esm/3_errors.js +2 -12
- package/esm/4_errors.js +2 -12
- package/esm/_dnt.polyfills.d.ts +0 -99
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +1 -127
- package/esm/client/0_abortable_loop.js +26 -39
- package/esm/client/0_storage_operations.js +179 -218
- package/esm/client/1_client_plain.js +4 -22
- package/esm/client/2_account_manager.js +140 -149
- 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 +198 -215
- package/esm/client/2_file_manager.js +255 -262
- package/esm/client/2_network_statistics_manager.js +31 -44
- 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 +101 -111
- package/esm/client/2_update_manager.js +750 -745
- package/esm/client/3_client_encrypted_pool.js +10 -26
- package/esm/client/3_message_manager.js +503 -508
- 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 +140 -146
- package/esm/client/4_chat_manager.js +161 -169
- package/esm/client/4_checklist_manager.js +26 -39
- package/esm/client/4_context.js +244 -259
- package/esm/client/4_forum_manager.js +67 -73
- package/esm/client/4_gift_manager.js +22 -35
- 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_composer.js +13 -26
- package/esm/client/6_client.js +866 -896
- package/esm/client/6_client_dispatcher.js +308 -325
- package/esm/client/7_client_worker.js +16 -29
- package/esm/connection/1_connection_tcp.js +55 -82
- 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.2.0/mux_async_iterator.js +31 -47
- package/esm/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/esm/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/esm/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/esm/session/0_session_state.js +12 -38
- package/esm/session/1_session.js +49 -72
- package/esm/session/2_session_encrypted.js +422 -420
- package/esm/storage/2_storage_indexed_db.js +26 -44
- package/esm/storage/2_storage_local_storage.js +3 -16
- package/esm/storage/2_storage_memory.js +24 -41
- package/esm/storage/2_storage_session_storage.js +3 -16
- package/esm/tl/1_tl_reader.d.ts +1 -1
- package/esm/tl/1_tl_reader.d.ts.map +1 -1
- package/esm/tl/1_tl_reader.js +95 -103
- package/esm/tl/1_tl_writer.js +169 -178
- 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/utilities/0_mutex.js +4 -19
- package/esm/utilities/0_part_stream.js +11 -25
- package/esm/utilities/1_crypto.js +42 -53
- package/esm/utilities/2_queue.js +29 -47
- package/package.json +1 -1
- package/script/0_errors.d.ts.map +1 -1
- package/script/0_errors.js +9 -31
- package/script/3_errors.js +2 -12
- package/script/4_errors.js +2 -12
- package/script/_dnt.polyfills.d.ts +0 -99
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +0 -128
- package/script/client/0_abortable_loop.js +27 -40
- package/script/client/0_storage_operations.js +179 -218
- package/script/client/1_client_plain.js +4 -22
- package/script/client/2_account_manager.js +140 -149
- 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 +199 -216
- package/script/client/2_file_manager.js +255 -262
- package/script/client/2_network_statistics_manager.js +32 -45
- 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 +102 -112
- package/script/client/2_update_manager.js +750 -745
- package/script/client/3_client_encrypted_pool.js +10 -26
- package/script/client/3_message_manager.js +503 -508
- 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 +140 -146
- package/script/client/4_chat_manager.js +161 -169
- package/script/client/4_checklist_manager.js +26 -39
- package/script/client/4_context.js +244 -259
- package/script/client/4_forum_manager.js +67 -73
- package/script/client/4_gift_manager.js +22 -35
- 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_composer.js +13 -26
- package/script/client/6_client.js +866 -896
- package/script/client/6_client_dispatcher.js +308 -325
- package/script/client/7_client_worker.js +16 -29
- package/script/connection/1_connection_tcp.js +55 -82
- package/script/connection/1_connection_web_socket.js +75 -91
- package/script/deps/jsr.io/@roj/tgcrypto/1.0.1/dist/tgcrypto.js +3 -11
- package/script/deps/jsr.io/@std/async/1.2.0/mux_async_iterator.js +31 -47
- package/script/deps/jsr.io/@std/async/1.2.0/tee.js +11 -34
- package/script/deps/jsr.io/@std/cache/0.2.2/lru_cache.js +30 -47
- package/script/deps/jsr.io/@std/datetime/0.225.7/_date_time_formatter.js +4 -17
- package/script/session/0_session_state.js +12 -38
- package/script/session/1_session.js +49 -72
- package/script/session/2_session_encrypted.js +423 -421
- package/script/storage/2_storage_indexed_db.js +26 -44
- package/script/storage/2_storage_local_storage.js +3 -16
- package/script/storage/2_storage_memory.js +24 -41
- package/script/storage/2_storage_session_storage.js +3 -16
- package/script/tl/1_tl_reader.d.ts +1 -1
- package/script/tl/1_tl_reader.d.ts.map +1 -1
- package/script/tl/1_tl_reader.js +96 -104
- package/script/tl/1_tl_writer.js +170 -179
- 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/utilities/0_mutex.js +4 -19
- package/script/utilities/0_part_stream.js +11 -25
- package/script/utilities/1_crypto.js +43 -54
- package/script/utilities/2_queue.js +30 -48
|
@@ -18,18 +18,7 @@
|
|
|
18
18
|
* You should have received a copy of the GNU Lesser General Public License
|
|
19
19
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
20
|
*/
|
|
21
|
-
var
|
|
22
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
23
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
24
|
-
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");
|
|
25
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
26
|
-
};
|
|
27
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
28
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
29
|
-
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");
|
|
30
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
31
|
-
};
|
|
32
|
-
var _ClientEncrypted_instances, _a, _ClientEncrypted_SEND_MAX_TRIES, _ClientEncrypted_AUTH_KEY_CREATION_MAX_TRIES, _ClientEncrypted_L, _ClientEncrypted_plain, _ClientEncrypted_sentRequests, _ClientEncrypted_apiId, _ClientEncrypted_appVersion, _ClientEncrypted_deviceModel, _ClientEncrypted_langCode, _ClientEncrypted_langPack, _ClientEncrypted_systemLangCode, _ClientEncrypted_systemVersion, _ClientEncrypted_disableUpdates, _ClientEncrypted_createAuthKeyPromise, _ClientEncrypted_createAuthKey, _ClientEncrypted_createAuthKeyInner, _ClientEncrypted_connectionInited, _ClientEncrypted_send, _ClientEncrypted_resend, _ClientEncrypted_onUpdate, _ClientEncrypted_onNewServerSalt, _ClientEncrypted_onMessageFailed, _ClientEncrypted_onRpcError, _ClientEncrypted_onRpcResult, _ClientEncrypted_onPong;
|
|
21
|
+
var _a;
|
|
33
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
34
23
|
exports.ClientEncrypted = void 0;
|
|
35
24
|
const _0_errors_js_1 = require("../0_errors.js");
|
|
@@ -45,61 +34,44 @@ const _1_client_plain_js_1 = require("./1_client_plain.js");
|
|
|
45
34
|
// global ClientEncrypted ID counter for logs
|
|
46
35
|
let id = 0;
|
|
47
36
|
class ClientEncrypted extends _0_client_abstract_js_1.ClientAbstract {
|
|
37
|
+
static #SEND_MAX_TRIES = 10;
|
|
38
|
+
static #AUTH_KEY_CREATION_MAX_TRIES = 10;
|
|
39
|
+
handlers = {};
|
|
40
|
+
#L;
|
|
41
|
+
#plain;
|
|
42
|
+
session;
|
|
43
|
+
#sentRequests = new Map();
|
|
44
|
+
#apiId;
|
|
45
|
+
#appVersion;
|
|
46
|
+
#deviceModel;
|
|
47
|
+
#langCode;
|
|
48
|
+
#langPack;
|
|
49
|
+
#systemLangCode;
|
|
50
|
+
#systemVersion;
|
|
51
|
+
#disableUpdates;
|
|
48
52
|
constructor(dc, apiId, params) {
|
|
49
53
|
super();
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
enumerable: true,
|
|
53
|
-
configurable: true,
|
|
54
|
-
writable: true,
|
|
55
|
-
value: {}
|
|
56
|
-
});
|
|
57
|
-
_ClientEncrypted_L.set(this, void 0);
|
|
58
|
-
_ClientEncrypted_plain.set(this, void 0);
|
|
59
|
-
Object.defineProperty(this, "session", {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
configurable: true,
|
|
62
|
-
writable: true,
|
|
63
|
-
value: void 0
|
|
64
|
-
});
|
|
65
|
-
_ClientEncrypted_sentRequests.set(this, new Map());
|
|
66
|
-
_ClientEncrypted_apiId.set(this, void 0);
|
|
67
|
-
_ClientEncrypted_appVersion.set(this, void 0);
|
|
68
|
-
_ClientEncrypted_deviceModel.set(this, void 0);
|
|
69
|
-
_ClientEncrypted_langCode.set(this, void 0);
|
|
70
|
-
_ClientEncrypted_langPack.set(this, void 0);
|
|
71
|
-
_ClientEncrypted_systemLangCode.set(this, void 0);
|
|
72
|
-
_ClientEncrypted_systemVersion.set(this, void 0);
|
|
73
|
-
_ClientEncrypted_disableUpdates.set(this, void 0);
|
|
74
|
-
_ClientEncrypted_createAuthKeyPromise.set(this, void 0);
|
|
75
|
-
_ClientEncrypted_connectionInited.set(this, false);
|
|
76
|
-
Object.defineProperty(this, "lastRequest", {
|
|
77
|
-
enumerable: true,
|
|
78
|
-
configurable: true,
|
|
79
|
-
writable: true,
|
|
80
|
-
value: void 0
|
|
81
|
-
});
|
|
82
|
-
__classPrivateFieldSet(this, _ClientEncrypted_L, (0, _1_utilities_js_1.getLogger)("ClientEncrypted").client(id++), "f");
|
|
83
|
-
__classPrivateFieldSet(this, _ClientEncrypted_plain, new _1_client_plain_js_1.ClientPlain(dc, params), "f");
|
|
54
|
+
this.#L = (0, _1_utilities_js_1.getLogger)("ClientEncrypted").client(id++);
|
|
55
|
+
this.#plain = new _1_client_plain_js_1.ClientPlain(dc, params);
|
|
84
56
|
this.session = new _4_session_js_1.SessionEncrypted(dc, params);
|
|
85
|
-
this.session.handlers.onUpdate =
|
|
86
|
-
this.session.handlers.onNewServerSalt =
|
|
87
|
-
this.session.handlers.onMessageFailed =
|
|
88
|
-
this.session.handlers.onRpcError =
|
|
89
|
-
this.session.handlers.onRpcResult =
|
|
90
|
-
this.session.handlers.onPong =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
57
|
+
this.session.handlers.onUpdate = this.#onUpdate.bind(this);
|
|
58
|
+
this.session.handlers.onNewServerSalt = this.#onNewServerSalt.bind(this);
|
|
59
|
+
this.session.handlers.onMessageFailed = this.#onMessageFailed.bind(this);
|
|
60
|
+
this.session.handlers.onRpcError = this.#onRpcError.bind(this);
|
|
61
|
+
this.session.handlers.onRpcResult = this.#onRpcResult.bind(this);
|
|
62
|
+
this.session.handlers.onPong = this.#onPong.bind(this);
|
|
63
|
+
this.#apiId = apiId;
|
|
64
|
+
this.#appVersion = params?.appVersion ?? _4_constants_js_1.APP_VERSION;
|
|
65
|
+
this.#deviceModel = params?.deviceModel ?? _4_constants_js_1.DEVICE_MODEL;
|
|
66
|
+
this.#langCode = params?.langCode ?? _4_constants_js_1.LANG_CODE;
|
|
67
|
+
this.#langPack = params?.langPack ?? _4_constants_js_1.LANG_PACK;
|
|
68
|
+
this.#systemLangCode = params?.systemLangCode ?? _4_constants_js_1.SYSTEM_LANG_CODE;
|
|
69
|
+
this.#systemVersion = params?.systemVersion ?? _4_constants_js_1.SYSTEM_VERSION;
|
|
70
|
+
this.#disableUpdates = params?.disableUpdates ?? false;
|
|
99
71
|
}
|
|
100
72
|
async connect() {
|
|
101
73
|
if (!this.authKey.length) {
|
|
102
|
-
await
|
|
74
|
+
await this.#createAuthKey();
|
|
103
75
|
}
|
|
104
76
|
await super.connect();
|
|
105
77
|
}
|
|
@@ -107,188 +79,199 @@ class ClientEncrypted extends _0_client_abstract_js_1.ClientAbstract {
|
|
|
107
79
|
super.disconnect();
|
|
108
80
|
this.lastRequest = undefined;
|
|
109
81
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
async invoke(function_) {
|
|
117
|
-
const messageId = await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_send).call(this, function_);
|
|
118
|
-
__classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("sent", function_._, "with msg_id", messageId);
|
|
119
|
-
const sentRequest = { call: function_, promiseWithResolvers: Promise.withResolvers() };
|
|
120
|
-
__classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").set(messageId, sentRequest);
|
|
121
|
-
return await sentRequest.promiseWithResolvers.promise;
|
|
82
|
+
#createAuthKeyPromise;
|
|
83
|
+
#createAuthKey() {
|
|
84
|
+
return this.#createAuthKeyPromise ??= this.#createAuthKeyInner().finally(() => {
|
|
85
|
+
this.#createAuthKeyPromise = undefined;
|
|
86
|
+
});
|
|
122
87
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
await __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").connect();
|
|
135
|
-
const [authKey, serverSalt] = await __classPrivateFieldGet(this, _ClientEncrypted_plain, "f").createAuthKey();
|
|
136
|
-
await this.setAuthKey(authKey);
|
|
137
|
-
this.serverSalt = serverSalt;
|
|
138
|
-
errored = false;
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
catch (err) {
|
|
142
|
-
errored = true;
|
|
143
|
-
lastErr = err;
|
|
144
|
-
if (this.isDisconnected) {
|
|
88
|
+
async #createAuthKeyInner() {
|
|
89
|
+
let lastErr;
|
|
90
|
+
let errored = false;
|
|
91
|
+
for (let i = 0; i < _a.#AUTH_KEY_CREATION_MAX_TRIES; ++i) {
|
|
92
|
+
try {
|
|
93
|
+
await this.#plain.connect();
|
|
94
|
+
const [authKey, serverSalt] = await this.#plain.createAuthKey();
|
|
95
|
+
await this.setAuthKey(authKey);
|
|
96
|
+
this.serverSalt = serverSalt;
|
|
97
|
+
errored = false;
|
|
145
98
|
break;
|
|
146
99
|
}
|
|
147
|
-
|
|
100
|
+
catch (err) {
|
|
101
|
+
errored = true;
|
|
102
|
+
lastErr = err;
|
|
103
|
+
if (this.isDisconnected) {
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
this.#L.error("failed to create auth key:", err);
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
this.#plain.disconnect();
|
|
110
|
+
}
|
|
148
111
|
}
|
|
149
|
-
|
|
150
|
-
|
|
112
|
+
if (errored) {
|
|
113
|
+
throw lastErr;
|
|
151
114
|
}
|
|
152
115
|
}
|
|
153
|
-
|
|
154
|
-
|
|
116
|
+
get authKey() {
|
|
117
|
+
return this.session.authKey;
|
|
155
118
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
let body;
|
|
159
|
-
if (_2_tl_js_1.Mtproto.is("ping", function_)) {
|
|
160
|
-
body = _2_tl_js_1.Mtproto.serializeObject(function_);
|
|
119
|
+
async setAuthKey(authKey) {
|
|
120
|
+
await this.session.setAuthKey(authKey);
|
|
161
121
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
122
|
+
#connectionInited = false;
|
|
123
|
+
lastRequest;
|
|
124
|
+
async #send(function_) {
|
|
125
|
+
this.lastRequest = new Date();
|
|
126
|
+
let body;
|
|
127
|
+
if (_2_tl_js_1.Mtproto.is("ping", function_)) {
|
|
128
|
+
body = _2_tl_js_1.Mtproto.serializeObject(function_);
|
|
165
129
|
}
|
|
166
|
-
|
|
167
|
-
if (!
|
|
168
|
-
|
|
130
|
+
else {
|
|
131
|
+
if (this.#disableUpdates && !(0, _0_utilities_js_1.isCdnFunction)(function_)) {
|
|
132
|
+
function_ = { _: "invokeWithoutUpdates", query: function_ };
|
|
169
133
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
for (let i = 0; i < __classPrivateFieldGet(_a, _a, "f", _ClientEncrypted_SEND_MAX_TRIES); ++i) {
|
|
190
|
-
let errored = false;
|
|
191
|
-
try {
|
|
192
|
-
return await this.session.send(body);
|
|
193
|
-
}
|
|
194
|
-
catch (err) {
|
|
195
|
-
errored = true;
|
|
196
|
-
lastErr = err;
|
|
197
|
-
if (this.isDisconnected) {
|
|
198
|
-
break;
|
|
134
|
+
if (!this.#connectionInited) {
|
|
135
|
+
if (!this.#apiId) {
|
|
136
|
+
throw new _0_errors_js_1.InputError("apiId not set");
|
|
137
|
+
}
|
|
138
|
+
function_ = {
|
|
139
|
+
_: "initConnection",
|
|
140
|
+
api_id: this.#apiId,
|
|
141
|
+
app_version: this.#appVersion,
|
|
142
|
+
device_model: this.#deviceModel,
|
|
143
|
+
lang_code: this.#langCode,
|
|
144
|
+
lang_pack: this.#langPack,
|
|
145
|
+
query: {
|
|
146
|
+
_: "invokeWithLayer",
|
|
147
|
+
layer: _2_tl_js_1.Api.LAYER,
|
|
148
|
+
query: function_,
|
|
149
|
+
},
|
|
150
|
+
system_lang_code: this.#systemLangCode,
|
|
151
|
+
system_version: this.#systemVersion,
|
|
152
|
+
};
|
|
199
153
|
}
|
|
200
|
-
|
|
154
|
+
body = _2_tl_js_1.Api.serializeObject(function_);
|
|
201
155
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
156
|
+
let lastErr;
|
|
157
|
+
for (let i = 0; i < _a.#SEND_MAX_TRIES; ++i) {
|
|
158
|
+
let errored = false;
|
|
159
|
+
try {
|
|
160
|
+
return await this.session.send(body);
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
errored = true;
|
|
164
|
+
lastErr = err;
|
|
165
|
+
if (this.isDisconnected) {
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
this.#L.error("send failed:", err);
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
if (!errored) {
|
|
172
|
+
this.#L.debug("invoked", (0, _0_utilities_js_1.repr)(function_));
|
|
173
|
+
this.#L.out(function_);
|
|
174
|
+
}
|
|
206
175
|
}
|
|
207
176
|
}
|
|
177
|
+
throw new Error(`Failed to invoke function after ${_a.#SEND_MAX_TRIES} tries.`, { cause: lastErr });
|
|
208
178
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
__classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").set(messageId, request);
|
|
214
|
-
}
|
|
215
|
-
catch (err) {
|
|
216
|
-
__classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("rejecting message because of resend error:", err);
|
|
217
|
-
request.promiseWithResolvers.reject(err);
|
|
218
|
-
}
|
|
219
|
-
}, _ClientEncrypted_onUpdate = async function _ClientEncrypted_onUpdate(body) {
|
|
220
|
-
let type;
|
|
221
|
-
try {
|
|
222
|
-
type = await _2_tl_js_1.Api.deserializeType(_2_tl_js_1.X, body);
|
|
223
|
-
}
|
|
224
|
-
catch (err) {
|
|
225
|
-
__classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to deserialize update:", err);
|
|
226
|
-
this.handlers.onDeserializationError?.();
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
if (_2_tl_js_1.Api.isOfEnum("Update", type) || _2_tl_js_1.Api.isOfEnum("Updates", type)) {
|
|
230
|
-
this.handlers.onUpdate?.(type);
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
__classPrivateFieldGet(this, _ClientEncrypted_L, "f").warning("received unknown type:", (0, _0_utilities_js_1.repr)(type));
|
|
234
|
-
}
|
|
235
|
-
}, _ClientEncrypted_onNewServerSalt = function _ClientEncrypted_onNewServerSalt(serverSalt) {
|
|
236
|
-
this.handlers.onNewServerSalt?.(serverSalt);
|
|
237
|
-
}, _ClientEncrypted_onMessageFailed = async function _ClientEncrypted_onMessageFailed(msgId, error) {
|
|
238
|
-
const request = __classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").get(msgId);
|
|
239
|
-
if (request) {
|
|
240
|
-
__classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").delete(msgId);
|
|
241
|
-
if (error instanceof _4_session_js_1.SessionError) {
|
|
242
|
-
await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_resend).call(this, request);
|
|
179
|
+
async #resend(request) {
|
|
180
|
+
try {
|
|
181
|
+
const messageId = await this.#send(request.call);
|
|
182
|
+
this.#sentRequests.set(messageId, request);
|
|
243
183
|
}
|
|
244
|
-
|
|
245
|
-
|
|
184
|
+
catch (err) {
|
|
185
|
+
this.#L.error("rejecting message because of resend error:", err);
|
|
186
|
+
request.promiseWithResolvers.reject(err);
|
|
246
187
|
}
|
|
247
188
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (reason instanceof _3_errors_js_1.ConnectionNotInited) {
|
|
255
|
-
__classPrivateFieldSet(this, _ClientEncrypted_connectionInited, false, "f");
|
|
256
|
-
await __classPrivateFieldGet(this, _ClientEncrypted_instances, "m", _ClientEncrypted_resend).call(this, request);
|
|
257
|
-
}
|
|
258
|
-
else {
|
|
259
|
-
request.promiseWithResolvers.reject((0, _4_errors_js_1.constructTelegramError)(error, request.call));
|
|
260
|
-
}
|
|
189
|
+
async invoke(function_) {
|
|
190
|
+
const messageId = await this.#send(function_);
|
|
191
|
+
this.#L.debug("sent", function_._, "with msg_id", messageId);
|
|
192
|
+
const sentRequest = { call: function_, promiseWithResolvers: Promise.withResolvers() };
|
|
193
|
+
this.#sentRequests.set(messageId, sentRequest);
|
|
194
|
+
return await sentRequest.promiseWithResolvers.promise;
|
|
261
195
|
}
|
|
262
|
-
|
|
263
|
-
const sentRequest = __classPrivateFieldGet(this, _ClientEncrypted_sentRequests, "f").get(msgId);
|
|
264
|
-
__classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("received rpc_result with req_msg_id =", msgId, "for", sentRequest === undefined ? "unknown" : "known", "request");
|
|
265
|
-
if (sentRequest) {
|
|
196
|
+
async #onUpdate(body) {
|
|
266
197
|
let type;
|
|
267
198
|
try {
|
|
268
|
-
type = await _2_tl_js_1.Api.deserializeType(_2_tl_js_1.
|
|
269
|
-
__classPrivateFieldGet(this, _ClientEncrypted_L, "f").in(type);
|
|
270
|
-
__classPrivateFieldGet(this, _ClientEncrypted_L, "f").debug("received rpc_result", (0, _0_utilities_js_1.repr)(type));
|
|
271
|
-
sentRequest.promiseWithResolvers.resolve(type);
|
|
199
|
+
type = await _2_tl_js_1.Api.deserializeType(_2_tl_js_1.X, body);
|
|
272
200
|
}
|
|
273
201
|
catch (err) {
|
|
274
|
-
|
|
275
|
-
__classPrivateFieldGet(this, _ClientEncrypted_L, "f").error("failed to deserialize rpc_result body:", err);
|
|
202
|
+
this.#L.error("failed to deserialize update:", err);
|
|
276
203
|
this.handlers.onDeserializationError?.();
|
|
277
204
|
return;
|
|
278
205
|
}
|
|
279
|
-
|
|
280
|
-
|
|
206
|
+
if (_2_tl_js_1.Api.isOfEnum("Update", type) || _2_tl_js_1.Api.isOfEnum("Updates", type)) {
|
|
207
|
+
this.handlers.onUpdate?.(type);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
this.#L.warning("received unknown type:", (0, _0_utilities_js_1.repr)(type));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
#onNewServerSalt(serverSalt) {
|
|
214
|
+
this.handlers.onNewServerSalt?.(serverSalt);
|
|
215
|
+
}
|
|
216
|
+
async #onMessageFailed(msgId, error) {
|
|
217
|
+
const request = this.#sentRequests.get(msgId);
|
|
218
|
+
if (request) {
|
|
219
|
+
this.#sentRequests.delete(msgId);
|
|
220
|
+
if (error instanceof _4_session_js_1.SessionError) {
|
|
221
|
+
await this.#resend(request);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
request.promiseWithResolvers.reject(error);
|
|
225
|
+
}
|
|
281
226
|
}
|
|
282
227
|
}
|
|
283
|
-
|
|
284
|
-
|
|
228
|
+
async #onRpcError(msgId, error) {
|
|
229
|
+
const request = this.#sentRequests.get(msgId);
|
|
230
|
+
this.#L.debug("received rpc_error with req_msg_id =", msgId, "for", request === undefined ? "unknown" : "known", "request");
|
|
231
|
+
if (request) {
|
|
232
|
+
this.#sentRequests.delete(msgId);
|
|
233
|
+
const reason = (0, _4_errors_js_1.constructTelegramError)(error, request.call);
|
|
234
|
+
if (reason instanceof _3_errors_js_1.ConnectionNotInited) {
|
|
235
|
+
this.#connectionInited = false;
|
|
236
|
+
await this.#resend(request);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
request.promiseWithResolvers.reject((0, _4_errors_js_1.constructTelegramError)(error, request.call));
|
|
240
|
+
}
|
|
241
|
+
}
|
|
285
242
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
sentRequest
|
|
290
|
-
|
|
243
|
+
async #onRpcResult(msgId, body) {
|
|
244
|
+
const sentRequest = this.#sentRequests.get(msgId);
|
|
245
|
+
this.#L.debug("received rpc_result with req_msg_id =", msgId, "for", sentRequest === undefined ? "unknown" : "known", "request");
|
|
246
|
+
if (sentRequest) {
|
|
247
|
+
let type;
|
|
248
|
+
try {
|
|
249
|
+
type = await _2_tl_js_1.Api.deserializeType(_2_tl_js_1.Api.mustGetReturnType(sentRequest.call._), body);
|
|
250
|
+
this.#L.in(type);
|
|
251
|
+
this.#L.debug("received rpc_result", (0, _0_utilities_js_1.repr)(type));
|
|
252
|
+
sentRequest.promiseWithResolvers.resolve(type);
|
|
253
|
+
}
|
|
254
|
+
catch (err) {
|
|
255
|
+
sentRequest.promiseWithResolvers.reject(err);
|
|
256
|
+
this.#L.error("failed to deserialize rpc_result body:", err);
|
|
257
|
+
this.handlers.onDeserializationError?.();
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
finally {
|
|
261
|
+
this.#sentRequests.delete(msgId);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
if (!this.#connectionInited) {
|
|
265
|
+
this.#connectionInited = true;
|
|
266
|
+
}
|
|
291
267
|
}
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
268
|
+
#onPong(pong) {
|
|
269
|
+
const sentRequest = this.#sentRequests.get(pong.msg_id);
|
|
270
|
+
if (sentRequest) {
|
|
271
|
+
sentRequest.promiseWithResolvers.resolve(pong);
|
|
272
|
+
this.#sentRequests.delete(pong.msg_id);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
exports.ClientEncrypted = ClientEncrypted;
|
|
277
|
+
_a = ClientEncrypted;
|