teleproto 1.224.0 → 1.224.2
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/Utils.js +36 -1
- package/Version.d.ts +1 -1
- package/Version.js +1 -1
- package/client/PtsWaiter.d.ts +44 -0
- package/client/PtsWaiter.js +158 -0
- package/client/TelegramClient.d.ts +1 -0
- package/client/TelegramClient.js +42 -9
- package/client/UpdateManager.d.ts +53 -0
- package/client/UpdateManager.js +572 -0
- package/client/telegramBaseClient.d.ts +33 -48
- package/client/telegramBaseClient.js +83 -13
- package/client/updates.d.ts +4 -59
- package/client/updates.js +33 -907
- package/errors/RPCBaseErrors.d.ts +9 -0
- package/errors/RPCBaseErrors.js +14 -1
- package/errors/RPCErrorList.d.ts +7 -1
- package/errors/RPCErrorList.js +17 -1
- package/extensions/PromisedNetSockets.js +16 -4
- package/network/MTProtoSender.js +20 -2
- package/network/MTProtoState.d.ts +1 -1
- package/network/MTProtoState.js +6 -8
- package/network/ReceivedIdsManager.d.ts +16 -0
- package/network/ReceivedIdsManager.js +72 -0
- package/package.json +1 -1
- package/sessions/Abstract.d.ts +7 -0
- package/sessions/Abstract.js +18 -0
- package/sessions/StoreSession.d.ts +2 -0
- package/sessions/StoreSession.js +11 -0
package/Utils.js
CHANGED
|
@@ -915,11 +915,46 @@ function getInputMedia(media, { isPhoto = false, attributes = undefined, forceDo
|
|
|
915
915
|
else {
|
|
916
916
|
correctAnswers = undefined;
|
|
917
917
|
}
|
|
918
|
+
const pollWithInputAnswers = new tl_1.Api.Poll({
|
|
919
|
+
id: media.poll.id,
|
|
920
|
+
question: media.poll.question,
|
|
921
|
+
answers: media.poll.answers.map((a) => {
|
|
922
|
+
if (!(a instanceof tl_1.Api.PollAnswer))
|
|
923
|
+
return a;
|
|
924
|
+
return new tl_1.Api.PollAnswer({
|
|
925
|
+
text: a.text,
|
|
926
|
+
option: a.option,
|
|
927
|
+
media: a.media
|
|
928
|
+
? getInputMedia(a.media)
|
|
929
|
+
: undefined,
|
|
930
|
+
addedBy: a.addedBy,
|
|
931
|
+
date: a.date,
|
|
932
|
+
});
|
|
933
|
+
}),
|
|
934
|
+
closed: media.poll.closed,
|
|
935
|
+
publicVoters: media.poll.publicVoters,
|
|
936
|
+
multipleChoice: media.poll.multipleChoice,
|
|
937
|
+
quiz: media.poll.quiz,
|
|
938
|
+
openAnswers: media.poll.openAnswers,
|
|
939
|
+
revotingDisabled: media.poll.revotingDisabled,
|
|
940
|
+
shuffleAnswers: media.poll.shuffleAnswers,
|
|
941
|
+
hideResultsUntilClose: media.poll.hideResultsUntilClose,
|
|
942
|
+
creator: media.poll.creator,
|
|
943
|
+
closePeriod: media.poll.closePeriod,
|
|
944
|
+
closeDate: media.poll.closeDate,
|
|
945
|
+
hash: media.poll.hash,
|
|
946
|
+
});
|
|
918
947
|
return new tl_1.Api.InputMediaPoll({
|
|
919
|
-
poll:
|
|
948
|
+
poll: pollWithInputAnswers,
|
|
920
949
|
correctAnswers: correctAnswers,
|
|
921
950
|
solution: media.results.solution,
|
|
922
951
|
solutionEntities: media.results.solutionEntities,
|
|
952
|
+
attachedMedia: media.attachedMedia
|
|
953
|
+
? getInputMedia(media.attachedMedia)
|
|
954
|
+
: undefined,
|
|
955
|
+
solutionMedia: media.results.solutionMedia
|
|
956
|
+
? getInputMedia(media.results.solutionMedia)
|
|
957
|
+
: undefined,
|
|
923
958
|
});
|
|
924
959
|
}
|
|
925
960
|
if (media instanceof tl_1.Api.Poll) {
|
package/Version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.224.
|
|
1
|
+
export declare const version = "1.224.2";
|
package/Version.js
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Api } from "../tl";
|
|
2
|
+
export declare const WAIT_FOR_SKIPPED_TIMEOUT_MS = 1000;
|
|
3
|
+
export type SkippedTag = "update" | "updates";
|
|
4
|
+
export interface SkippedEntry {
|
|
5
|
+
pts: number;
|
|
6
|
+
tieBreaker: number;
|
|
7
|
+
tag: SkippedTag;
|
|
8
|
+
update?: Api.TypeUpdate;
|
|
9
|
+
updates?: Api.TypeUpdates;
|
|
10
|
+
}
|
|
11
|
+
export interface PtsWaiterHost {
|
|
12
|
+
onWaitForSkipped(ms: number): void;
|
|
13
|
+
onWaitForShortPoll(ms: number): void;
|
|
14
|
+
}
|
|
15
|
+
export declare class PtsWaiter {
|
|
16
|
+
private readonly host;
|
|
17
|
+
private good;
|
|
18
|
+
private last;
|
|
19
|
+
private count;
|
|
20
|
+
private requestingFlag;
|
|
21
|
+
private waitingForSkipped;
|
|
22
|
+
private waitingForShortPoll;
|
|
23
|
+
private applyingSkippedDepth;
|
|
24
|
+
private skippedKey;
|
|
25
|
+
private readonly queue;
|
|
26
|
+
constructor(host: PtsWaiterHost);
|
|
27
|
+
inited(): boolean;
|
|
28
|
+
current(): number;
|
|
29
|
+
init(pts: number): void;
|
|
30
|
+
requesting(): boolean;
|
|
31
|
+
setRequesting(value: boolean): void;
|
|
32
|
+
isWaitingForSkipped(): boolean;
|
|
33
|
+
isWaitingForShortPoll(): boolean;
|
|
34
|
+
setWaitingForSkipped(ms: number): void;
|
|
35
|
+
setWaitingForShortPoll(ms: number): void;
|
|
36
|
+
updated(pts: number, count: number, payload: Omit<SkippedEntry, "pts" | "tieBreaker">): boolean;
|
|
37
|
+
updateAndApply(pts: number, count: number, payload: Omit<SkippedEntry, "pts" | "tieBreaker">, applyUpdate: (update: Api.TypeUpdate) => void, applyUpdates: (updates: Api.TypeUpdates) => void): boolean;
|
|
38
|
+
applySkippedUpdates(applyUpdate: (update: Api.TypeUpdate) => void, applyUpdates: (updates: Api.TypeUpdates) => void): void;
|
|
39
|
+
clearSkippedUpdates(): void;
|
|
40
|
+
private check;
|
|
41
|
+
private enqueue;
|
|
42
|
+
private lowerBoundOf;
|
|
43
|
+
private checkForWaiting;
|
|
44
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PtsWaiter = exports.WAIT_FOR_SKIPPED_TIMEOUT_MS = void 0;
|
|
4
|
+
exports.WAIT_FOR_SKIPPED_TIMEOUT_MS = 1000;
|
|
5
|
+
class PtsWaiter {
|
|
6
|
+
constructor(host) {
|
|
7
|
+
this.host = host;
|
|
8
|
+
this.good = 0;
|
|
9
|
+
this.last = 0;
|
|
10
|
+
this.count = 0;
|
|
11
|
+
this.requestingFlag = false;
|
|
12
|
+
this.waitingForSkipped = false;
|
|
13
|
+
this.waitingForShortPoll = false;
|
|
14
|
+
this.applyingSkippedDepth = 0;
|
|
15
|
+
this.skippedKey = 0;
|
|
16
|
+
this.queue = [];
|
|
17
|
+
}
|
|
18
|
+
inited() {
|
|
19
|
+
return this.good > 0;
|
|
20
|
+
}
|
|
21
|
+
current() {
|
|
22
|
+
return this.good;
|
|
23
|
+
}
|
|
24
|
+
init(pts) {
|
|
25
|
+
this.good = pts;
|
|
26
|
+
this.last = pts;
|
|
27
|
+
this.count = pts;
|
|
28
|
+
this.clearSkippedUpdates();
|
|
29
|
+
}
|
|
30
|
+
requesting() {
|
|
31
|
+
return this.requestingFlag;
|
|
32
|
+
}
|
|
33
|
+
setRequesting(value) {
|
|
34
|
+
this.requestingFlag = value;
|
|
35
|
+
if (value)
|
|
36
|
+
this.clearSkippedUpdates();
|
|
37
|
+
}
|
|
38
|
+
isWaitingForSkipped() {
|
|
39
|
+
return this.waitingForSkipped;
|
|
40
|
+
}
|
|
41
|
+
isWaitingForShortPoll() {
|
|
42
|
+
return this.waitingForShortPoll;
|
|
43
|
+
}
|
|
44
|
+
setWaitingForSkipped(ms) {
|
|
45
|
+
if (ms >= 0) {
|
|
46
|
+
this.waitingForSkipped = true;
|
|
47
|
+
this.host.onWaitForSkipped(ms);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
this.waitingForSkipped = false;
|
|
51
|
+
this.checkForWaiting();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
setWaitingForShortPoll(ms) {
|
|
55
|
+
if (ms >= 0) {
|
|
56
|
+
this.waitingForShortPoll = true;
|
|
57
|
+
this.host.onWaitForShortPoll(ms);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
this.waitingForShortPoll = false;
|
|
61
|
+
this.checkForWaiting();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
updated(pts, count, payload) {
|
|
65
|
+
if (this.requestingFlag || this.applyingSkippedDepth > 0) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (count > 0 && pts <= this.good) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (this.check(pts, count)) {
|
|
72
|
+
return true;
|
|
73
|
+
}
|
|
74
|
+
this.enqueue(pts, payload);
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
updateAndApply(pts, count, payload, applyUpdate, applyUpdates) {
|
|
78
|
+
if (!this.updated(pts, count, payload))
|
|
79
|
+
return false;
|
|
80
|
+
if (!this.waitingForSkipped || this.queue.length === 0) {
|
|
81
|
+
if (payload.tag === "update" && payload.update)
|
|
82
|
+
applyUpdate(payload.update);
|
|
83
|
+
else if (payload.tag === "updates" && payload.updates)
|
|
84
|
+
applyUpdates(payload.updates);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
this.enqueue(pts, payload);
|
|
88
|
+
this.applySkippedUpdates(applyUpdate, applyUpdates);
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
applySkippedUpdates(applyUpdate, applyUpdates) {
|
|
92
|
+
if (!this.waitingForSkipped)
|
|
93
|
+
return;
|
|
94
|
+
this.setWaitingForSkipped(-1);
|
|
95
|
+
if (this.queue.length === 0)
|
|
96
|
+
return;
|
|
97
|
+
this.applyingSkippedDepth++;
|
|
98
|
+
try {
|
|
99
|
+
for (const entry of this.queue) {
|
|
100
|
+
if (entry.tag === "update" && entry.update)
|
|
101
|
+
applyUpdate(entry.update);
|
|
102
|
+
else if (entry.tag === "updates" && entry.updates)
|
|
103
|
+
applyUpdates(entry.updates);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
this.applyingSkippedDepth--;
|
|
108
|
+
this.clearSkippedUpdates();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
clearSkippedUpdates() {
|
|
112
|
+
this.queue.length = 0;
|
|
113
|
+
}
|
|
114
|
+
check(pts, count) {
|
|
115
|
+
if (!this.inited()) {
|
|
116
|
+
this.init(pts);
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
this.last = Math.max(this.last, pts);
|
|
120
|
+
this.count += count;
|
|
121
|
+
if (this.last === this.count) {
|
|
122
|
+
this.good = this.last;
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
if (this.last < this.count) {
|
|
126
|
+
this.setWaitingForSkipped(1);
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
this.setWaitingForSkipped(exports.WAIT_FOR_SKIPPED_TIMEOUT_MS);
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
enqueue(pts, payload) {
|
|
133
|
+
const entry = Object.assign({ pts, tieBreaker: ++this.skippedKey }, payload);
|
|
134
|
+
const idx = this.lowerBoundOf(entry);
|
|
135
|
+
this.queue.splice(idx, 0, entry);
|
|
136
|
+
}
|
|
137
|
+
lowerBoundOf(entry) {
|
|
138
|
+
let lo = 0;
|
|
139
|
+
let hi = this.queue.length;
|
|
140
|
+
while (lo < hi) {
|
|
141
|
+
const mid = (lo + hi) >>> 1;
|
|
142
|
+
const cur = this.queue[mid];
|
|
143
|
+
const lt = cur.pts < entry.pts ||
|
|
144
|
+
(cur.pts === entry.pts && cur.tieBreaker < entry.tieBreaker);
|
|
145
|
+
if (lt)
|
|
146
|
+
lo = mid + 1;
|
|
147
|
+
else
|
|
148
|
+
hi = mid;
|
|
149
|
+
}
|
|
150
|
+
return lo;
|
|
151
|
+
}
|
|
152
|
+
checkForWaiting() {
|
|
153
|
+
if (!this.waitingForSkipped && !this.waitingForShortPoll) {
|
|
154
|
+
this.host.onWaitForSkipped(-1);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
exports.PtsWaiter = PtsWaiter;
|
|
@@ -1129,6 +1129,7 @@ export declare class TelegramClient extends TelegramBaseClient {
|
|
|
1129
1129
|
ipAddress: string;
|
|
1130
1130
|
port: number;
|
|
1131
1131
|
}>;
|
|
1132
|
+
private _lookupDcOption;
|
|
1132
1133
|
/** @hidden */
|
|
1133
1134
|
_getDownloadConcurrency(fileSize: number): Promise<number>;
|
|
1134
1135
|
/** @hidden */
|
package/client/TelegramClient.js
CHANGED
|
@@ -1246,19 +1246,52 @@ class TelegramClient extends telegramBaseClient_1.TelegramBaseClient {
|
|
|
1246
1246
|
async getDC(dcId, downloadDC = false) {
|
|
1247
1247
|
this._log.debug(`Getting DC ${dcId}`);
|
|
1248
1248
|
if (!this._config) {
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
id: DC.id,
|
|
1255
|
-
ipAddress: DC.ipAddress,
|
|
1256
|
-
port: 443,
|
|
1257
|
-
};
|
|
1249
|
+
try {
|
|
1250
|
+
this._config = await this.invoke(new tl_1.Api.help.GetConfig());
|
|
1251
|
+
}
|
|
1252
|
+
catch (e) {
|
|
1253
|
+
this._log.warn(`help.GetConfig failed, falling back to built-in DC seeds: ${e}`);
|
|
1258
1254
|
}
|
|
1259
1255
|
}
|
|
1256
|
+
const lookup = this._lookupDcOption(dcId, downloadDC);
|
|
1257
|
+
if (lookup) {
|
|
1258
|
+
return lookup;
|
|
1259
|
+
}
|
|
1260
|
+
const ipv4Table = this._testServers ? telegramBaseClient_1.TEST_DC_IPV4 : telegramBaseClient_1.PROD_DC_IPV4;
|
|
1261
|
+
const ipv6Table = this._testServers ? telegramBaseClient_1.TEST_DC_IPV6 : telegramBaseClient_1.PROD_DC_IPV6;
|
|
1262
|
+
const ipAddress = (this._useIPV6 ? ipv6Table : ipv4Table)[dcId];
|
|
1263
|
+
if (ipAddress) {
|
|
1264
|
+
return { id: dcId, ipAddress, port: 443 };
|
|
1265
|
+
}
|
|
1260
1266
|
throw new Error(`Cannot find the DC with the ID of ${dcId}`);
|
|
1261
1267
|
}
|
|
1268
|
+
_lookupDcOption(dcId, mediaCluster) {
|
|
1269
|
+
if (!this._config)
|
|
1270
|
+
return undefined;
|
|
1271
|
+
let candidates = this._config.dcOptions.filter((DC) => {
|
|
1272
|
+
if (DC.id !== dcId)
|
|
1273
|
+
return false;
|
|
1274
|
+
if (DC.cdn)
|
|
1275
|
+
return false;
|
|
1276
|
+
if (DC.mediaOnly && !mediaCluster)
|
|
1277
|
+
return false;
|
|
1278
|
+
if (DC.secret && DC.secret.length)
|
|
1279
|
+
return false;
|
|
1280
|
+
if (DC.tcpoOnly)
|
|
1281
|
+
return false;
|
|
1282
|
+
return !!DC.ipv6 === this._useIPV6;
|
|
1283
|
+
});
|
|
1284
|
+
if (!candidates.length)
|
|
1285
|
+
return undefined;
|
|
1286
|
+
if (mediaCluster && candidates.some((DC) => DC.mediaOnly)) {
|
|
1287
|
+
candidates = candidates.filter((DC) => DC.mediaOnly);
|
|
1288
|
+
}
|
|
1289
|
+
if (this._proxy && candidates.some((DC) => DC.static)) {
|
|
1290
|
+
candidates = candidates.filter((DC) => DC.static);
|
|
1291
|
+
}
|
|
1292
|
+
const chosen = candidates[0];
|
|
1293
|
+
return { id: chosen.id, ipAddress: chosen.ipAddress, port: 443 };
|
|
1294
|
+
}
|
|
1262
1295
|
/** @hidden */
|
|
1263
1296
|
async _getDownloadConcurrency(fileSize) {
|
|
1264
1297
|
var _a, _b, _c, _d;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Api } from "../tl";
|
|
2
|
+
import type { TelegramClient } from "./TelegramClient";
|
|
3
|
+
export interface UpdateState {
|
|
4
|
+
pts: number;
|
|
5
|
+
qts: number;
|
|
6
|
+
date: number;
|
|
7
|
+
seq: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class UpdateManager {
|
|
10
|
+
state?: UpdateState;
|
|
11
|
+
lastUpdateTime: number;
|
|
12
|
+
private readonly client;
|
|
13
|
+
private readonly globalPts;
|
|
14
|
+
private globalPtsTimer?;
|
|
15
|
+
private readonly channels;
|
|
16
|
+
private readonly pendingSeq;
|
|
17
|
+
private fetchingDifference;
|
|
18
|
+
private failTimeoutS;
|
|
19
|
+
private failRetryTimer?;
|
|
20
|
+
private readonly channelFailTimeoutS;
|
|
21
|
+
private readonly channelFailRetryTimers;
|
|
22
|
+
private running;
|
|
23
|
+
constructor(client: TelegramClient);
|
|
24
|
+
start(): void;
|
|
25
|
+
stop(): void;
|
|
26
|
+
onUpdates(update: Api.TypeUpdate | Api.TypeUpdates): void;
|
|
27
|
+
catchUp(): Promise<void>;
|
|
28
|
+
ensureState(): Promise<void>;
|
|
29
|
+
refreshFromState(state: {
|
|
30
|
+
pts: number;
|
|
31
|
+
qts: number;
|
|
32
|
+
date: number;
|
|
33
|
+
seq: number;
|
|
34
|
+
}): void;
|
|
35
|
+
isStale(): boolean;
|
|
36
|
+
recoverIfStale(): Promise<void>;
|
|
37
|
+
private handleContainer;
|
|
38
|
+
private handleShortMessage;
|
|
39
|
+
private feedUpdate;
|
|
40
|
+
private dispatch;
|
|
41
|
+
private collectEntities;
|
|
42
|
+
private makeGlobalWaiter;
|
|
43
|
+
private getOrCreateChannel;
|
|
44
|
+
private scheduleCommonDifference;
|
|
45
|
+
private fetchCommonDifference;
|
|
46
|
+
private fetchDifferenceLoop;
|
|
47
|
+
private processDifference;
|
|
48
|
+
private drainPendingSeq;
|
|
49
|
+
private fetchChannelDifference;
|
|
50
|
+
private resolveChannel;
|
|
51
|
+
private bumpFailTimeout;
|
|
52
|
+
private bumpChannelFailTimeout;
|
|
53
|
+
}
|