@imessaging/telegram-mtproto 0.6.4 → 0.6.5
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/package.json
CHANGED
|
@@ -86,6 +86,8 @@ export class TelegramMtprotoTransport
|
|
|
86
86
|
private lastActivityAt?: Date;
|
|
87
87
|
private readonly incoming = new IncomingDispatcher();
|
|
88
88
|
private incomingListener: ((event: unknown) => void) | null = null;
|
|
89
|
+
/** Отметка жизни подписки: срабатывает на любом обновлении, включая служебные. */
|
|
90
|
+
private activityListener: ((event: unknown) => void) | null = null;
|
|
89
91
|
|
|
90
92
|
constructor(private readonly options: TelegramMtprotoTransportOptions) {
|
|
91
93
|
if (!options.accountId.trim()) throw new Error("accountId must not be empty");
|
|
@@ -182,6 +184,17 @@ export class TelegramMtprotoTransport
|
|
|
182
184
|
};
|
|
183
185
|
this.incomingListener = listener;
|
|
184
186
|
this.client.addEventHandler(listener, new NewMessage({}));
|
|
187
|
+
|
|
188
|
+
// ОТМЕТКА ЖИЗНИ ПОДПИСКИ — на ЛЮБОМ обновлении, а не только на сообщении.
|
|
189
|
+
//
|
|
190
|
+
// Канал заказчика молчит и сутки — это его обычный ритм, а не поломка. Сторож, который смотрит
|
|
191
|
+
// на сообщения, в таком затишье перезапускает процесс зря, а каждый перезапуск — новая
|
|
192
|
+
// авторизация сессии, за частоту которых Telegram наказывает. Служебные события идут и в
|
|
193
|
+
// тишине, поэтому именно они отличают мёртвую подписку от спокойного канала.
|
|
194
|
+
this.activityListener = (): void => {
|
|
195
|
+
this.lastActivityAt = new Date();
|
|
196
|
+
};
|
|
197
|
+
this.client.addEventHandler(this.activityListener);
|
|
185
198
|
}
|
|
186
199
|
|
|
187
200
|
/**
|
|
@@ -222,6 +235,11 @@ export class TelegramMtprotoTransport
|
|
|
222
235
|
if (this.incoming.size > 0 || this.incomingListener === null) return;
|
|
223
236
|
this.client.removeEventHandler(this.incomingListener, new NewMessage({}));
|
|
224
237
|
this.incomingListener = null;
|
|
238
|
+
if (this.activityListener) {
|
|
239
|
+
// Снимается тем же способом, что и ставилась: без построителя событий.
|
|
240
|
+
this.client.removeEventHandler(this.activityListener, undefined as never);
|
|
241
|
+
this.activityListener = null;
|
|
242
|
+
}
|
|
225
243
|
}
|
|
226
244
|
|
|
227
245
|
/**
|