@mtkruto/node 0.0.960 → 0.0.962
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/3_client.js +73 -72
- package/esm/constants.d.ts +1 -1
- package/esm/constants.js +1 -1
- package/esm/utilities/0_misc.d.ts +1 -0
- package/esm/utilities/0_misc.js +3 -0
- package/package.json +1 -1
- package/script/client/3_client.js +73 -72
- package/script/constants.d.ts +1 -1
- package/script/constants.js +1 -1
- package/script/utilities/0_misc.d.ts +1 -0
- package/script/utilities/0_misc.js +7 -0
package/esm/client/3_client.js
CHANGED
|
@@ -23,6 +23,7 @@ import { parseHtml } from "./0_html.js";
|
|
|
23
23
|
import { checkPassword } from "./0_password.js";
|
|
24
24
|
import { ClientAbstract } from "./1_client_abstract.js";
|
|
25
25
|
import { ClientPlain } from "./2_client_plain.js";
|
|
26
|
+
import { drop } from "../utilities/0_misc.js";
|
|
26
27
|
import { getChannelChatId, peerToChatId } from "./0_utilities.js";
|
|
27
28
|
const d = debug("Client");
|
|
28
29
|
const dGap = debug("Client/recoverUpdateGap");
|
|
@@ -243,8 +244,8 @@ export class Client extends ClientAbstract {
|
|
|
243
244
|
await this.storage.setDc(this.transportProvider.initialDc);
|
|
244
245
|
}
|
|
245
246
|
d("encrypted client connected");
|
|
246
|
-
this.receiveLoop();
|
|
247
|
-
this.pingLoop();
|
|
247
|
+
drop(this.receiveLoop());
|
|
248
|
+
drop(this.pingLoop());
|
|
248
249
|
}
|
|
249
250
|
async fetchState(source) {
|
|
250
251
|
const state = await this.invoke(new functions.UpdatesGetState());
|
|
@@ -450,90 +451,90 @@ export class Client extends ClientAbstract {
|
|
|
450
451
|
throw new Error("Not connected");
|
|
451
452
|
}
|
|
452
453
|
while (this.connected) {
|
|
453
|
-
if (this.toAcknowledge.size >= ackThreshold) {
|
|
454
|
-
await this.send(new types.MsgsAck({ msgIds: [...this.toAcknowledge] }));
|
|
455
|
-
this.toAcknowledge.clear();
|
|
456
|
-
}
|
|
457
|
-
let buffer;
|
|
458
454
|
try {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
if (!this.connected) {
|
|
463
|
-
break;
|
|
455
|
+
if (this.toAcknowledge.size >= ackThreshold) {
|
|
456
|
+
await this.send(new types.MsgsAck({ msgIds: [...this.toAcknowledge] }));
|
|
457
|
+
this.toAcknowledge.clear();
|
|
464
458
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
let decrypted;
|
|
470
|
-
try {
|
|
471
|
-
decrypted = await decryptMessage(buffer, this.auth.key, this.auth.id, this.sessionId);
|
|
472
|
-
}
|
|
473
|
-
catch (err) {
|
|
474
|
-
dRecv("failed to decrypt message: %o", err);
|
|
475
|
-
continue;
|
|
476
|
-
}
|
|
477
|
-
const messages = decrypted instanceof MessageContainer ? decrypted.messages : [decrypted];
|
|
478
|
-
for (const message of messages) {
|
|
479
|
-
let body = message.body;
|
|
480
|
-
if (body instanceof types.GZIPPacked) {
|
|
481
|
-
body = new TLReader(gunzip(body.packedData)).readObject();
|
|
459
|
+
const buffer = await this.transport.receive();
|
|
460
|
+
let decrypted;
|
|
461
|
+
try {
|
|
462
|
+
decrypted = await (decryptMessage(buffer, this.auth.key, this.auth.id, this.sessionId));
|
|
482
463
|
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
this.
|
|
464
|
+
catch (err) {
|
|
465
|
+
dRecv("failed to decrypt message: %o", err);
|
|
466
|
+
drop(this.recoverUpdateGap("decryption"));
|
|
467
|
+
continue;
|
|
486
468
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
469
|
+
const messages = decrypted instanceof MessageContainer ? decrypted.messages : [decrypted];
|
|
470
|
+
for (const message of messages) {
|
|
471
|
+
let body = message.body;
|
|
472
|
+
if (body instanceof types.GZIPPacked) {
|
|
473
|
+
body = new TLReader(gunzip(body.packedData)).readObject();
|
|
491
474
|
}
|
|
492
|
-
|
|
493
|
-
|
|
475
|
+
dRecv("received %s", body.constructor.name);
|
|
476
|
+
if (body instanceof types.Updates || body instanceof types.TypeUpdate) {
|
|
477
|
+
drop(this.processUpdates(body));
|
|
494
478
|
}
|
|
495
|
-
else {
|
|
496
|
-
|
|
479
|
+
else if (message.body instanceof RPCResult) {
|
|
480
|
+
let result = message.body.result;
|
|
481
|
+
if (result instanceof types.GZIPPacked) {
|
|
482
|
+
result = new TLReader(gunzip(result.packedData)).readObject();
|
|
483
|
+
}
|
|
484
|
+
if (result instanceof types.RPCError) {
|
|
485
|
+
dRecv("RPCResult: %d %s", result.errorCode, result.errorMessage);
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
dRecv("RPCResult: %s", result.constructor.name);
|
|
489
|
+
}
|
|
490
|
+
const messageId = message.body.messageId;
|
|
491
|
+
const resolvePromise = () => {
|
|
492
|
+
const promise = this.promises.get(messageId);
|
|
493
|
+
if (promise) {
|
|
494
|
+
if (result instanceof types.RPCError) {
|
|
495
|
+
promise.reject(result);
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
promise.resolve(result);
|
|
499
|
+
}
|
|
500
|
+
this.promises.delete(messageId);
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
if (result instanceof types.TypeUpdates || result instanceof types.TypeUpdate) {
|
|
504
|
+
this.processUpdates(result).then(resolvePromise).catch();
|
|
505
|
+
}
|
|
506
|
+
else {
|
|
507
|
+
await this.processResult(result);
|
|
508
|
+
resolvePromise();
|
|
509
|
+
}
|
|
497
510
|
}
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
const promise = this.promises.get(messageId);
|
|
511
|
+
else if (message.body instanceof types.Pong) {
|
|
512
|
+
const promise = this.promises.get(message.body.msgId);
|
|
501
513
|
if (promise) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
}
|
|
505
|
-
else {
|
|
506
|
-
promise.resolve(result);
|
|
507
|
-
}
|
|
508
|
-
this.promises.delete(messageId);
|
|
514
|
+
promise.resolve(message.body);
|
|
515
|
+
this.promises.delete(message.body.msgId);
|
|
509
516
|
}
|
|
510
|
-
};
|
|
511
|
-
if (result instanceof types.TypeUpdates || result instanceof types.TypeUpdate) {
|
|
512
|
-
this.processUpdates(result).then(resolvePromise);
|
|
513
517
|
}
|
|
514
|
-
else {
|
|
515
|
-
|
|
516
|
-
|
|
518
|
+
else if (message.body instanceof types.BadMsgNotification || message.body instanceof types.BadServerSalt) {
|
|
519
|
+
if (message.body instanceof types.BadServerSalt) {
|
|
520
|
+
this.state.salt = message.body.newServerSalt;
|
|
521
|
+
}
|
|
522
|
+
const promise = this.promises.get(message.body.badMsgId);
|
|
523
|
+
if (promise) {
|
|
524
|
+
promise.resolve(message.body);
|
|
525
|
+
this.promises.delete(message.body.badMsgId);
|
|
526
|
+
}
|
|
517
527
|
}
|
|
528
|
+
this.toAcknowledge.add(message.id);
|
|
518
529
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
this.promises.delete(message.body.msgId);
|
|
524
|
-
}
|
|
530
|
+
}
|
|
531
|
+
catch (err) {
|
|
532
|
+
if (!this.connected) {
|
|
533
|
+
break;
|
|
525
534
|
}
|
|
526
|
-
else
|
|
527
|
-
|
|
528
|
-
this.state.salt = message.body.newServerSalt;
|
|
529
|
-
}
|
|
530
|
-
const promise = this.promises.get(message.body.badMsgId);
|
|
531
|
-
if (promise) {
|
|
532
|
-
promise.resolve(message.body);
|
|
533
|
-
this.promises.delete(message.body.badMsgId);
|
|
534
|
-
}
|
|
535
|
+
else {
|
|
536
|
+
throw err;
|
|
535
537
|
}
|
|
536
|
-
this.toAcknowledge.add(message.id);
|
|
537
538
|
}
|
|
538
539
|
}
|
|
539
540
|
}
|
package/esm/constants.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
|
|
|
4
4
|
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
5
5
|
export declare const DEFAULT_INITIAL_DC: DC;
|
|
6
6
|
export declare const LAYER = 158;
|
|
7
|
-
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.
|
|
7
|
+
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.962";
|
|
8
8
|
export declare const DEFAULT_DEVICE_MODEL: string;
|
|
9
9
|
export declare const DEFAULT_LANG_CODE: string;
|
|
10
10
|
export declare const DEFAULT_LANG_PACK = "";
|
package/esm/constants.js
CHANGED
|
@@ -62,7 +62,7 @@ export const publicKeys = new Map([
|
|
|
62
62
|
export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
63
63
|
export const DEFAULT_INITIAL_DC = "2-test";
|
|
64
64
|
export const LAYER = 158;
|
|
65
|
-
export const DEFAULT_APP_VERSION = "MTKruto 0.0.
|
|
65
|
+
export const DEFAULT_APP_VERSION = "MTKruto 0.0.962";
|
|
66
66
|
// @ts-ignore: lib
|
|
67
67
|
export const DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
|
|
68
68
|
export const DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function drop<T>(promise: Promise<T>): void;
|
package/package.json
CHANGED
|
@@ -49,6 +49,7 @@ const _0_html_js_1 = require("./0_html.js");
|
|
|
49
49
|
const _0_password_js_1 = require("./0_password.js");
|
|
50
50
|
const _1_client_abstract_js_1 = require("./1_client_abstract.js");
|
|
51
51
|
const _2_client_plain_js_1 = require("./2_client_plain.js");
|
|
52
|
+
const _0_misc_js_1 = require("../utilities/0_misc.js");
|
|
52
53
|
const _0_utilities_js_1 = require("./0_utilities.js");
|
|
53
54
|
const d = (0, deps_js_1.debug)("Client");
|
|
54
55
|
const dGap = (0, deps_js_1.debug)("Client/recoverUpdateGap");
|
|
@@ -269,8 +270,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
269
270
|
await this.storage.setDc(this.transportProvider.initialDc);
|
|
270
271
|
}
|
|
271
272
|
d("encrypted client connected");
|
|
272
|
-
this.receiveLoop();
|
|
273
|
-
this.pingLoop();
|
|
273
|
+
(0, _0_misc_js_1.drop)(this.receiveLoop());
|
|
274
|
+
(0, _0_misc_js_1.drop)(this.pingLoop());
|
|
274
275
|
}
|
|
275
276
|
async fetchState(source) {
|
|
276
277
|
const state = await this.invoke(new functions.UpdatesGetState());
|
|
@@ -476,90 +477,90 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
476
477
|
throw new Error("Not connected");
|
|
477
478
|
}
|
|
478
479
|
while (this.connected) {
|
|
479
|
-
if (this.toAcknowledge.size >= constants_js_1.ackThreshold) {
|
|
480
|
-
await this.send(new types.MsgsAck({ msgIds: [...this.toAcknowledge] }));
|
|
481
|
-
this.toAcknowledge.clear();
|
|
482
|
-
}
|
|
483
|
-
let buffer;
|
|
484
480
|
try {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
if (!this.connected) {
|
|
489
|
-
break;
|
|
481
|
+
if (this.toAcknowledge.size >= constants_js_1.ackThreshold) {
|
|
482
|
+
await this.send(new types.MsgsAck({ msgIds: [...this.toAcknowledge] }));
|
|
483
|
+
this.toAcknowledge.clear();
|
|
490
484
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
let decrypted;
|
|
496
|
-
try {
|
|
497
|
-
decrypted = await (0, _0_message_js_1.decryptMessage)(buffer, this.auth.key, this.auth.id, this.sessionId);
|
|
498
|
-
}
|
|
499
|
-
catch (err) {
|
|
500
|
-
dRecv("failed to decrypt message: %o", err);
|
|
501
|
-
continue;
|
|
502
|
-
}
|
|
503
|
-
const messages = decrypted instanceof _7_message_container_js_1.MessageContainer ? decrypted.messages : [decrypted];
|
|
504
|
-
for (const message of messages) {
|
|
505
|
-
let body = message.body;
|
|
506
|
-
if (body instanceof types.GZIPPacked) {
|
|
507
|
-
body = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(body.packedData)).readObject();
|
|
485
|
+
const buffer = await this.transport.receive();
|
|
486
|
+
let decrypted;
|
|
487
|
+
try {
|
|
488
|
+
decrypted = await ((0, _0_message_js_1.decryptMessage)(buffer, this.auth.key, this.auth.id, this.sessionId));
|
|
508
489
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
this.
|
|
490
|
+
catch (err) {
|
|
491
|
+
dRecv("failed to decrypt message: %o", err);
|
|
492
|
+
(0, _0_misc_js_1.drop)(this.recoverUpdateGap("decryption"));
|
|
493
|
+
continue;
|
|
512
494
|
}
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
495
|
+
const messages = decrypted instanceof _7_message_container_js_1.MessageContainer ? decrypted.messages : [decrypted];
|
|
496
|
+
for (const message of messages) {
|
|
497
|
+
let body = message.body;
|
|
498
|
+
if (body instanceof types.GZIPPacked) {
|
|
499
|
+
body = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(body.packedData)).readObject();
|
|
517
500
|
}
|
|
518
|
-
|
|
519
|
-
|
|
501
|
+
dRecv("received %s", body.constructor.name);
|
|
502
|
+
if (body instanceof types.Updates || body instanceof types.TypeUpdate) {
|
|
503
|
+
(0, _0_misc_js_1.drop)(this.processUpdates(body));
|
|
520
504
|
}
|
|
521
|
-
else {
|
|
522
|
-
|
|
505
|
+
else if (message.body instanceof _5_rpc_result_js_1.RPCResult) {
|
|
506
|
+
let result = message.body.result;
|
|
507
|
+
if (result instanceof types.GZIPPacked) {
|
|
508
|
+
result = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(result.packedData)).readObject();
|
|
509
|
+
}
|
|
510
|
+
if (result instanceof types.RPCError) {
|
|
511
|
+
dRecv("RPCResult: %d %s", result.errorCode, result.errorMessage);
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
dRecv("RPCResult: %s", result.constructor.name);
|
|
515
|
+
}
|
|
516
|
+
const messageId = message.body.messageId;
|
|
517
|
+
const resolvePromise = () => {
|
|
518
|
+
const promise = this.promises.get(messageId);
|
|
519
|
+
if (promise) {
|
|
520
|
+
if (result instanceof types.RPCError) {
|
|
521
|
+
promise.reject(result);
|
|
522
|
+
}
|
|
523
|
+
else {
|
|
524
|
+
promise.resolve(result);
|
|
525
|
+
}
|
|
526
|
+
this.promises.delete(messageId);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
if (result instanceof types.TypeUpdates || result instanceof types.TypeUpdate) {
|
|
530
|
+
this.processUpdates(result).then(resolvePromise).catch();
|
|
531
|
+
}
|
|
532
|
+
else {
|
|
533
|
+
await this.processResult(result);
|
|
534
|
+
resolvePromise();
|
|
535
|
+
}
|
|
523
536
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
const promise = this.promises.get(messageId);
|
|
537
|
+
else if (message.body instanceof types.Pong) {
|
|
538
|
+
const promise = this.promises.get(message.body.msgId);
|
|
527
539
|
if (promise) {
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
else {
|
|
532
|
-
promise.resolve(result);
|
|
533
|
-
}
|
|
534
|
-
this.promises.delete(messageId);
|
|
540
|
+
promise.resolve(message.body);
|
|
541
|
+
this.promises.delete(message.body.msgId);
|
|
535
542
|
}
|
|
536
|
-
};
|
|
537
|
-
if (result instanceof types.TypeUpdates || result instanceof types.TypeUpdate) {
|
|
538
|
-
this.processUpdates(result).then(resolvePromise);
|
|
539
543
|
}
|
|
540
|
-
else {
|
|
541
|
-
|
|
542
|
-
|
|
544
|
+
else if (message.body instanceof types.BadMsgNotification || message.body instanceof types.BadServerSalt) {
|
|
545
|
+
if (message.body instanceof types.BadServerSalt) {
|
|
546
|
+
this.state.salt = message.body.newServerSalt;
|
|
547
|
+
}
|
|
548
|
+
const promise = this.promises.get(message.body.badMsgId);
|
|
549
|
+
if (promise) {
|
|
550
|
+
promise.resolve(message.body);
|
|
551
|
+
this.promises.delete(message.body.badMsgId);
|
|
552
|
+
}
|
|
543
553
|
}
|
|
554
|
+
this.toAcknowledge.add(message.id);
|
|
544
555
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
this.promises.delete(message.body.msgId);
|
|
550
|
-
}
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
if (!this.connected) {
|
|
559
|
+
break;
|
|
551
560
|
}
|
|
552
|
-
else
|
|
553
|
-
|
|
554
|
-
this.state.salt = message.body.newServerSalt;
|
|
555
|
-
}
|
|
556
|
-
const promise = this.promises.get(message.body.badMsgId);
|
|
557
|
-
if (promise) {
|
|
558
|
-
promise.resolve(message.body);
|
|
559
|
-
this.promises.delete(message.body.badMsgId);
|
|
560
|
-
}
|
|
561
|
+
else {
|
|
562
|
+
throw err;
|
|
561
563
|
}
|
|
562
|
-
this.toAcknowledge.add(message.id);
|
|
563
564
|
}
|
|
564
565
|
}
|
|
565
566
|
}
|
package/script/constants.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
|
|
|
4
4
|
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
5
5
|
export declare const DEFAULT_INITIAL_DC: DC;
|
|
6
6
|
export declare const LAYER = 158;
|
|
7
|
-
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.
|
|
7
|
+
export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.962";
|
|
8
8
|
export declare const DEFAULT_DEVICE_MODEL: string;
|
|
9
9
|
export declare const DEFAULT_LANG_CODE: string;
|
|
10
10
|
export declare const DEFAULT_LANG_PACK = "";
|
package/script/constants.js
CHANGED
|
@@ -88,7 +88,7 @@ exports.publicKeys = new Map([
|
|
|
88
88
|
exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
89
89
|
exports.DEFAULT_INITIAL_DC = "2-test";
|
|
90
90
|
exports.LAYER = 158;
|
|
91
|
-
exports.DEFAULT_APP_VERSION = "MTKruto 0.0.
|
|
91
|
+
exports.DEFAULT_APP_VERSION = "MTKruto 0.0.962";
|
|
92
92
|
// @ts-ignore: lib
|
|
93
93
|
exports.DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
|
|
94
94
|
exports.DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function drop<T>(promise: Promise<T>): void;
|