1 | "use strict";
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | const get_timer_1 = __importDefault(require("./get-timer"));
|
7 | class PingTimer {
|
8 | constructor(keepalive, checkPing, variant) {
|
9 | this.destroyed = false;
|
10 | this.keepalive = keepalive * 1000;
|
11 | this.checkPing = checkPing;
|
12 | this.timer = (0, get_timer_1.default)(variant);
|
13 | this.reschedule();
|
14 | }
|
15 | clear() {
|
16 | if (this.timerId) {
|
17 | this.timer.clear(this.timerId);
|
18 | this.timerId = null;
|
19 | }
|
20 | }
|
21 | destroy() {
|
22 | this.clear();
|
23 | this.destroyed = true;
|
24 | }
|
25 | reschedule() {
|
26 | if (this.destroyed) {
|
27 | return;
|
28 | }
|
29 | this.clear();
|
30 | this.timerId = this.timer.set(() => {
|
31 | if (this.destroyed) {
|
32 | return;
|
33 | }
|
34 | this.checkPing();
|
35 | this.reschedule();
|
36 | }, this.keepalive);
|
37 | }
|
38 | }
|
39 | exports.default = PingTimer;
|
40 |
|
\ | No newline at end of file |