@mtkruto/node 0.0.961 → 0.0.963
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 -73
- package/esm/connection/1_connection_web_socket.d.ts +1 -0
- package/esm/connection/1_connection_web_socket.js +11 -3
- package/esm/constants.d.ts +1 -1
- package/esm/constants.js +1 -1
- package/esm/tl/1_tl_object.js +4 -1
- package/esm/types/3_message.js +3 -0
- package/esm/utilities/0_base64.js +4 -2
- package/esm/utilities/0_base64_test.d.ts +1 -0
- 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 -73
- package/script/connection/1_connection_web_socket.d.ts +1 -0
- package/script/connection/1_connection_web_socket.js +11 -3
- package/script/constants.d.ts +1 -1
- package/script/constants.js +1 -1
- package/script/tl/1_tl_object.js +4 -1
- package/script/types/3_message.js +3 -0
- package/script/utilities/0_base64.js +4 -2
- package/script/utilities/0_base64_test.d.ts +1 -0
- 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,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
|
-
|
|
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
|
-
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
|
-
|
|
485
|
-
|
|
486
|
-
this.
|
|
464
|
+
catch (err) {
|
|
465
|
+
dRecv("failed to decrypt message: %o", err);
|
|
466
|
+
drop(this.recoverUpdateGap("decryption"));
|
|
467
|
+
continue;
|
|
487
468
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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
|
-
|
|
494
|
-
|
|
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
|
-
|
|
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
|
-
|
|
500
|
-
|
|
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
|
-
|
|
504
|
-
|
|
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
|
-
|
|
517
|
-
|
|
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
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
this.promises.delete(message.body.msgId);
|
|
525
|
-
}
|
|
530
|
+
}
|
|
531
|
+
catch (err) {
|
|
532
|
+
if (!this.connected) {
|
|
533
|
+
break;
|
|
526
534
|
}
|
|
527
|
-
else
|
|
528
|
-
|
|
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
|
}
|
|
@@ -33,8 +33,15 @@ export class ConnectionWebSocket {
|
|
|
33
33
|
writable: true,
|
|
34
34
|
value: null
|
|
35
35
|
});
|
|
36
|
-
this.webSocket =
|
|
37
|
-
|
|
36
|
+
this.webSocket = this.reinitWs(url);
|
|
37
|
+
// TODO
|
|
38
|
+
this.webSocket.onclose = () => {
|
|
39
|
+
this.webSocket = this.reinitWs(url);
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
reinitWs(url) {
|
|
43
|
+
const webSocket = new dntShim.WebSocket(url, "binary");
|
|
44
|
+
webSocket.onmessage = async (e) => {
|
|
38
45
|
// deno-lint-ignore no-explicit-any
|
|
39
46
|
const data = e.data instanceof Blob ? new Uint8Array(await e.data.arrayBuffer()) : new Uint8Array(e.data);
|
|
40
47
|
for (const byte of data) {
|
|
@@ -45,9 +52,10 @@ export class ConnectionWebSocket {
|
|
|
45
52
|
this.nextResolve = null;
|
|
46
53
|
}
|
|
47
54
|
};
|
|
48
|
-
|
|
55
|
+
webSocket.onerror = (err) => {
|
|
49
56
|
d("WebSocket error: %o", err);
|
|
50
57
|
};
|
|
58
|
+
return webSocket;
|
|
51
59
|
}
|
|
52
60
|
get connected() {
|
|
53
61
|
return this.webSocket.readyState == dntShim.WebSocket.OPEN;
|
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.963";
|
|
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.963";
|
|
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];
|
package/esm/tl/1_tl_object.js
CHANGED
|
@@ -91,8 +91,11 @@ function serializeSingleParam(writer, value, type, ntype) {
|
|
|
91
91
|
writer.writeBytes(value);
|
|
92
92
|
}
|
|
93
93
|
else {
|
|
94
|
-
|
|
94
|
+
writer.writeString("");
|
|
95
95
|
}
|
|
96
|
+
// else {
|
|
97
|
+
// throw new TypeError(`Expected string or Uint8Array but received ${valueRepr}`);
|
|
98
|
+
// }
|
|
96
99
|
break;
|
|
97
100
|
case "true":
|
|
98
101
|
if (value !== true) {
|
package/esm/types/3_message.js
CHANGED
|
@@ -380,6 +380,9 @@ export async function constructMessage(message_, getEntity, getMessage, getStick
|
|
|
380
380
|
else if (message_.media instanceof types.MessageMediaGeo || message_.media instanceof types.MessageMediaGeoLive) {
|
|
381
381
|
message.location = constructLocation(message_.media);
|
|
382
382
|
}
|
|
383
|
+
else if (message_.media instanceof types.MessageMediaWebPage) {
|
|
384
|
+
//
|
|
385
|
+
}
|
|
383
386
|
else {
|
|
384
387
|
// not implemented
|
|
385
388
|
UNREACHABLE();
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { base64Decode, base64Encode } from "../deps.js";
|
|
2
|
-
// TODO: test
|
|
3
2
|
export function base64EncodeUrlSafe(data) {
|
|
4
3
|
return base64Encode(data).replace(/=*$/, "").replaceAll("+", "-").replaceAll("/", "_");
|
|
5
4
|
}
|
|
6
5
|
export function base64DecodeUrlSafe(data) {
|
|
7
6
|
data = data.replaceAll("_", "/").replaceAll("-", "+");
|
|
8
|
-
|
|
7
|
+
if (data.length != 4) {
|
|
8
|
+
data += "=".repeat(4 - data.length % 4);
|
|
9
|
+
}
|
|
10
|
+
return base64Decode(data);
|
|
9
11
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,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
|
-
|
|
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
|
-
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
|
-
|
|
511
|
-
|
|
512
|
-
this.
|
|
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
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
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
|
-
|
|
520
|
-
|
|
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
|
-
|
|
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
|
-
|
|
526
|
-
|
|
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
|
-
|
|
530
|
-
|
|
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
|
-
|
|
543
|
-
|
|
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
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
this.promises.delete(message.body.msgId);
|
|
551
|
-
}
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
if (!this.connected) {
|
|
559
|
+
break;
|
|
552
560
|
}
|
|
553
|
-
else
|
|
554
|
-
|
|
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
|
}
|
|
@@ -59,8 +59,15 @@ class ConnectionWebSocket {
|
|
|
59
59
|
writable: true,
|
|
60
60
|
value: null
|
|
61
61
|
});
|
|
62
|
-
this.webSocket =
|
|
63
|
-
|
|
62
|
+
this.webSocket = this.reinitWs(url);
|
|
63
|
+
// TODO
|
|
64
|
+
this.webSocket.onclose = () => {
|
|
65
|
+
this.webSocket = this.reinitWs(url);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
reinitWs(url) {
|
|
69
|
+
const webSocket = new dntShim.WebSocket(url, "binary");
|
|
70
|
+
webSocket.onmessage = async (e) => {
|
|
64
71
|
// deno-lint-ignore no-explicit-any
|
|
65
72
|
const data = e.data instanceof Blob ? new Uint8Array(await e.data.arrayBuffer()) : new Uint8Array(e.data);
|
|
66
73
|
for (const byte of data) {
|
|
@@ -71,9 +78,10 @@ class ConnectionWebSocket {
|
|
|
71
78
|
this.nextResolve = null;
|
|
72
79
|
}
|
|
73
80
|
};
|
|
74
|
-
|
|
81
|
+
webSocket.onerror = (err) => {
|
|
75
82
|
d("WebSocket error: %o", err);
|
|
76
83
|
};
|
|
84
|
+
return webSocket;
|
|
77
85
|
}
|
|
78
86
|
get connected() {
|
|
79
87
|
return this.webSocket.readyState == dntShim.WebSocket.OPEN;
|
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.963";
|
|
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.963";
|
|
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];
|
package/script/tl/1_tl_object.js
CHANGED
|
@@ -96,8 +96,11 @@ function serializeSingleParam(writer, value, type, ntype) {
|
|
|
96
96
|
writer.writeBytes(value);
|
|
97
97
|
}
|
|
98
98
|
else {
|
|
99
|
-
|
|
99
|
+
writer.writeString("");
|
|
100
100
|
}
|
|
101
|
+
// else {
|
|
102
|
+
// throw new TypeError(`Expected string or Uint8Array but received ${valueRepr}`);
|
|
103
|
+
// }
|
|
101
104
|
break;
|
|
102
105
|
case "true":
|
|
103
106
|
if (value !== true) {
|
|
@@ -406,6 +406,9 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
|
|
|
406
406
|
else if (message_.media instanceof types.MessageMediaGeo || message_.media instanceof types.MessageMediaGeoLive) {
|
|
407
407
|
message.location = (0, _0_location_js_1.constructLocation)(message_.media);
|
|
408
408
|
}
|
|
409
|
+
else if (message_.media instanceof types.MessageMediaWebPage) {
|
|
410
|
+
//
|
|
411
|
+
}
|
|
409
412
|
else {
|
|
410
413
|
// not implemented
|
|
411
414
|
(0, _0_control_js_1.UNREACHABLE)();
|
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.base64DecodeUrlSafe = exports.base64EncodeUrlSafe = void 0;
|
|
4
4
|
const deps_js_1 = require("../deps.js");
|
|
5
|
-
// TODO: test
|
|
6
5
|
function base64EncodeUrlSafe(data) {
|
|
7
6
|
return (0, deps_js_1.base64Encode)(data).replace(/=*$/, "").replaceAll("+", "-").replaceAll("/", "_");
|
|
8
7
|
}
|
|
9
8
|
exports.base64EncodeUrlSafe = base64EncodeUrlSafe;
|
|
10
9
|
function base64DecodeUrlSafe(data) {
|
|
11
10
|
data = data.replaceAll("_", "/").replaceAll("-", "+");
|
|
12
|
-
|
|
11
|
+
if (data.length != 4) {
|
|
12
|
+
data += "=".repeat(4 - data.length % 4);
|
|
13
|
+
}
|
|
14
|
+
return (0, deps_js_1.base64Decode)(data);
|
|
13
15
|
}
|
|
14
16
|
exports.base64DecodeUrlSafe = base64DecodeUrlSafe;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function drop<T>(promise: Promise<T>): void;
|