@mtkruto/node 0.0.961 → 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.
@@ -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,91 +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
- buffer = await this.transport.receive();
460
- }
461
- catch (err) {
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
- else {
466
- throw err;
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
- this.recoverUpdateGap("decryption");
476
- continue;
477
- }
478
- const messages = decrypted instanceof MessageContainer ? decrypted.messages : [decrypted];
479
- for (const message of messages) {
480
- let body = message.body;
481
- if (body instanceof types.GZIPPacked) {
482
- 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));
483
463
  }
484
- dRecv("received %s", body.constructor.name);
485
- if (body instanceof types.Updates || body instanceof types.TypeUpdate) {
486
- this.processUpdates(body);
464
+ catch (err) {
465
+ dRecv("failed to decrypt message: %o", err);
466
+ drop(this.recoverUpdateGap("decryption"));
467
+ continue;
487
468
  }
488
- else if (message.body instanceof RPCResult) {
489
- let result = message.body.result;
490
- if (result instanceof types.GZIPPacked) {
491
- result = new TLReader(gunzip(result.packedData)).readObject();
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();
492
474
  }
493
- if (result instanceof types.RPCError) {
494
- dRecv("RPCResult: %d %s", result.errorCode, result.errorMessage);
475
+ dRecv("received %s", body.constructor.name);
476
+ if (body instanceof types.Updates || body instanceof types.TypeUpdate) {
477
+ drop(this.processUpdates(body));
495
478
  }
496
- else {
497
- dRecv("RPCResult: %s", result.constructor.name);
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
+ }
498
510
  }
499
- const messageId = message.body.messageId;
500
- const resolvePromise = () => {
501
- const promise = this.promises.get(messageId);
511
+ else if (message.body instanceof types.Pong) {
512
+ const promise = this.promises.get(message.body.msgId);
502
513
  if (promise) {
503
- if (result instanceof types.RPCError) {
504
- promise.reject(result);
505
- }
506
- else {
507
- promise.resolve(result);
508
- }
509
- this.promises.delete(messageId);
514
+ promise.resolve(message.body);
515
+ this.promises.delete(message.body.msgId);
510
516
  }
511
- };
512
- if (result instanceof types.TypeUpdates || result instanceof types.TypeUpdate) {
513
- this.processUpdates(result).then(resolvePromise);
514
517
  }
515
- else {
516
- await this.processResult(result);
517
- resolvePromise();
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
+ }
518
527
  }
528
+ this.toAcknowledge.add(message.id);
519
529
  }
520
- else if (message.body instanceof types.Pong) {
521
- const promise = this.promises.get(message.body.msgId);
522
- if (promise) {
523
- promise.resolve(message.body);
524
- this.promises.delete(message.body.msgId);
525
- }
530
+ }
531
+ catch (err) {
532
+ if (!this.connected) {
533
+ break;
526
534
  }
527
- else if (message.body instanceof types.BadMsgNotification || message.body instanceof types.BadServerSalt) {
528
- if (message.body instanceof types.BadServerSalt) {
529
- this.state.salt = message.body.newServerSalt;
530
- }
531
- const promise = this.promises.get(message.body.badMsgId);
532
- if (promise) {
533
- promise.resolve(message.body);
534
- this.promises.delete(message.body.badMsgId);
535
- }
535
+ else {
536
+ throw err;
536
537
  }
537
- this.toAcknowledge.add(message.id);
538
538
  }
539
539
  }
540
540
  }
@@ -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.961";
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.961";
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;
@@ -0,0 +1,3 @@
1
+ export function drop(promise) {
2
+ promise.then().catch();
3
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.961",
5
+ "version": "0.0.962",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -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,91 +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
- buffer = await this.transport.receive();
486
- }
487
- catch (err) {
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
- else {
492
- throw err;
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
- this.recoverUpdateGap("decryption");
502
- continue;
503
- }
504
- const messages = decrypted instanceof _7_message_container_js_1.MessageContainer ? decrypted.messages : [decrypted];
505
- for (const message of messages) {
506
- let body = message.body;
507
- if (body instanceof types.GZIPPacked) {
508
- 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));
509
489
  }
510
- dRecv("received %s", body.constructor.name);
511
- if (body instanceof types.Updates || body instanceof types.TypeUpdate) {
512
- this.processUpdates(body);
490
+ catch (err) {
491
+ dRecv("failed to decrypt message: %o", err);
492
+ (0, _0_misc_js_1.drop)(this.recoverUpdateGap("decryption"));
493
+ continue;
513
494
  }
514
- else if (message.body instanceof _5_rpc_result_js_1.RPCResult) {
515
- let result = message.body.result;
516
- if (result instanceof types.GZIPPacked) {
517
- result = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(result.packedData)).readObject();
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();
518
500
  }
519
- if (result instanceof types.RPCError) {
520
- dRecv("RPCResult: %d %s", result.errorCode, result.errorMessage);
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));
521
504
  }
522
- else {
523
- dRecv("RPCResult: %s", result.constructor.name);
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
+ }
524
536
  }
525
- const messageId = message.body.messageId;
526
- const resolvePromise = () => {
527
- const promise = this.promises.get(messageId);
537
+ else if (message.body instanceof types.Pong) {
538
+ const promise = this.promises.get(message.body.msgId);
528
539
  if (promise) {
529
- if (result instanceof types.RPCError) {
530
- promise.reject(result);
531
- }
532
- else {
533
- promise.resolve(result);
534
- }
535
- this.promises.delete(messageId);
540
+ promise.resolve(message.body);
541
+ this.promises.delete(message.body.msgId);
536
542
  }
537
- };
538
- if (result instanceof types.TypeUpdates || result instanceof types.TypeUpdate) {
539
- this.processUpdates(result).then(resolvePromise);
540
543
  }
541
- else {
542
- await this.processResult(result);
543
- resolvePromise();
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
+ }
544
553
  }
554
+ this.toAcknowledge.add(message.id);
545
555
  }
546
- else if (message.body instanceof types.Pong) {
547
- const promise = this.promises.get(message.body.msgId);
548
- if (promise) {
549
- promise.resolve(message.body);
550
- this.promises.delete(message.body.msgId);
551
- }
556
+ }
557
+ catch (err) {
558
+ if (!this.connected) {
559
+ break;
552
560
  }
553
- else if (message.body instanceof types.BadMsgNotification || message.body instanceof types.BadServerSalt) {
554
- if (message.body instanceof types.BadServerSalt) {
555
- this.state.salt = message.body.newServerSalt;
556
- }
557
- const promise = this.promises.get(message.body.badMsgId);
558
- if (promise) {
559
- promise.resolve(message.body);
560
- this.promises.delete(message.body.badMsgId);
561
- }
561
+ else {
562
+ throw err;
562
563
  }
563
- this.toAcknowledge.add(message.id);
564
564
  }
565
565
  }
566
566
  }
@@ -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.961";
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 = "";
@@ -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.961";
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;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.drop = void 0;
4
+ function drop(promise) {
5
+ promise.then().catch();
6
+ }
7
+ exports.drop = drop;