@mtcute/core 0.20.1 → 0.20.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/highlevel/base.cjs +5 -0
- package/highlevel/base.js +5 -0
- package/network/network-manager.cjs +1 -1
- package/network/network-manager.js +1 -1
- package/network/persistent-connection.cjs +12 -4
- package/network/persistent-connection.js +13 -5
- package/network/session-connection.cjs +1 -10
- package/network/session-connection.js +1 -10
- package/package.json +1 -1
package/highlevel/base.cjs
CHANGED
|
@@ -133,6 +133,11 @@ class BaseTelegramClient {
|
|
|
133
133
|
this.mt.network.notifyLoggedOut();
|
|
134
134
|
this.log.prefix = "[USER n/a] ";
|
|
135
135
|
await this.storage.self.store(null);
|
|
136
|
+
const primaryDc = this.mt.network.getPrimaryDcId();
|
|
137
|
+
for (const dc of this.mt.network.config.getCached()?.dcOptions ?? []) {
|
|
138
|
+
if (dc.id === primaryDc) continue;
|
|
139
|
+
await this.mt.storage.provider.authKeys.deleteByDc(dc.id);
|
|
140
|
+
}
|
|
136
141
|
}
|
|
137
142
|
async notifyChannelOpened(channelId, pts) {
|
|
138
143
|
return this.updates?.notifyChannelOpened(channelId, pts) ?? false;
|
package/highlevel/base.js
CHANGED
|
@@ -126,6 +126,11 @@ class BaseTelegramClient {
|
|
|
126
126
|
this.mt.network.notifyLoggedOut();
|
|
127
127
|
this.log.prefix = "[USER n/a] ";
|
|
128
128
|
await this.storage.self.store(null);
|
|
129
|
+
const primaryDc = this.mt.network.getPrimaryDcId();
|
|
130
|
+
for (const dc of this.mt.network.config.getCached()?.dcOptions ?? []) {
|
|
131
|
+
if (dc.id === primaryDc) continue;
|
|
132
|
+
await this.mt.storage.provider.authKeys.deleteByDc(dc.id);
|
|
133
|
+
}
|
|
129
134
|
}
|
|
130
135
|
async notifyChannelOpened(channelId, pts) {
|
|
131
136
|
return this.updates?.notifyChannelOpened(channelId, pts) ?? false;
|
|
@@ -94,16 +94,18 @@ class PersistentConnection {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
_onClose() {
|
|
98
98
|
this.log.debug("connection closed");
|
|
99
99
|
this._updateLogPrefix();
|
|
100
100
|
this._writer = void 0;
|
|
101
101
|
this._codec.reset();
|
|
102
102
|
this.onClosed();
|
|
103
103
|
}
|
|
104
|
-
|
|
104
|
+
_onError(err) {
|
|
105
105
|
this._updateLogPrefix();
|
|
106
|
-
|
|
106
|
+
if (!(err instanceof net.ConnectionClosedError)) {
|
|
107
|
+
this.handleError(err);
|
|
108
|
+
}
|
|
107
109
|
return "reconnect";
|
|
108
110
|
}
|
|
109
111
|
async changeTransport(transport) {
|
|
@@ -167,7 +169,13 @@ class PersistentConnection {
|
|
|
167
169
|
}
|
|
168
170
|
if (this._writer) {
|
|
169
171
|
this._rescheduleInactivity();
|
|
170
|
-
|
|
172
|
+
try {
|
|
173
|
+
await this._writer.write(data);
|
|
174
|
+
} catch (e) {
|
|
175
|
+
this.log.warn("encountered an error closed while sending, reconnecting: %e", e);
|
|
176
|
+
this._fuman.reconnect(true);
|
|
177
|
+
this._sendOnceConnected.push(data);
|
|
178
|
+
}
|
|
171
179
|
} else {
|
|
172
180
|
this._sendOnceConnected.push(data);
|
|
173
181
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FramedReader, FramedWriter } from "@fuman/io";
|
|
2
|
-
import { PersistentConnection as PersistentConnection$1 } from "@fuman/net";
|
|
2
|
+
import { PersistentConnection as PersistentConnection$1, ConnectionClosedError } from "@fuman/net";
|
|
3
3
|
import { Emitter, timers } from "@fuman/utils";
|
|
4
4
|
let nextConnectionUid = 0;
|
|
5
5
|
class PersistentConnection {
|
|
@@ -87,16 +87,18 @@ class PersistentConnection {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
-
|
|
90
|
+
_onClose() {
|
|
91
91
|
this.log.debug("connection closed");
|
|
92
92
|
this._updateLogPrefix();
|
|
93
93
|
this._writer = void 0;
|
|
94
94
|
this._codec.reset();
|
|
95
95
|
this.onClosed();
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
_onError(err) {
|
|
98
98
|
this._updateLogPrefix();
|
|
99
|
-
|
|
99
|
+
if (!(err instanceof ConnectionClosedError)) {
|
|
100
|
+
this.handleError(err);
|
|
101
|
+
}
|
|
100
102
|
return "reconnect";
|
|
101
103
|
}
|
|
102
104
|
async changeTransport(transport) {
|
|
@@ -160,7 +162,13 @@ class PersistentConnection {
|
|
|
160
162
|
}
|
|
161
163
|
if (this._writer) {
|
|
162
164
|
this._rescheduleInactivity();
|
|
163
|
-
|
|
165
|
+
try {
|
|
166
|
+
await this._writer.write(data);
|
|
167
|
+
} catch (e) {
|
|
168
|
+
this.log.warn("encountered an error closed while sending, reconnecting: %e", e);
|
|
169
|
+
this._fuman.reconnect(true);
|
|
170
|
+
this._sendOnceConnected.push(data);
|
|
171
|
+
}
|
|
164
172
|
} else {
|
|
165
173
|
this._sendOnceConnected.push(data);
|
|
166
174
|
}
|
|
@@ -1428,16 +1428,7 @@ class SessionConnection extends persistentConnection.PersistentConnection {
|
|
|
1428
1428
|
rootMsgId
|
|
1429
1429
|
);
|
|
1430
1430
|
const enc = this._session.encryptMessage(result);
|
|
1431
|
-
const promise = this.send(enc)
|
|
1432
|
-
if (this._destroyed) return;
|
|
1433
|
-
this.log.error("error while sending pending messages (root msg_id = %l): %e", rootMsgId, err);
|
|
1434
|
-
if (ackMsgIds) {
|
|
1435
|
-
this._session.queuedAcks.splice(0, 0, ...ackMsgIds);
|
|
1436
|
-
}
|
|
1437
|
-
if (rootMsgId) {
|
|
1438
|
-
this._onMessageFailed(rootMsgId, "unknown error");
|
|
1439
|
-
}
|
|
1440
|
-
});
|
|
1431
|
+
const promise = this.send(enc);
|
|
1441
1432
|
if (this._inactivityPendingFlush && !this._session.hasPendingMessages) {
|
|
1442
1433
|
void promise.then(() => {
|
|
1443
1434
|
this.log.debug("pending messages sent, closing connection");
|
|
@@ -1421,16 +1421,7 @@ class SessionConnection extends PersistentConnection {
|
|
|
1421
1421
|
rootMsgId
|
|
1422
1422
|
);
|
|
1423
1423
|
const enc = this._session.encryptMessage(result);
|
|
1424
|
-
const promise = this.send(enc)
|
|
1425
|
-
if (this._destroyed) return;
|
|
1426
|
-
this.log.error("error while sending pending messages (root msg_id = %l): %e", rootMsgId, err);
|
|
1427
|
-
if (ackMsgIds) {
|
|
1428
|
-
this._session.queuedAcks.splice(0, 0, ...ackMsgIds);
|
|
1429
|
-
}
|
|
1430
|
-
if (rootMsgId) {
|
|
1431
|
-
this._onMessageFailed(rootMsgId, "unknown error");
|
|
1432
|
-
}
|
|
1433
|
-
});
|
|
1424
|
+
const promise = this.send(enc);
|
|
1434
1425
|
if (this._inactivityPendingFlush && !this._session.hasPendingMessages) {
|
|
1435
1426
|
void promise.then(() => {
|
|
1436
1427
|
this.log.debug("pending messages sent, closing connection");
|