1 | import { RECONNECT_DELAY, RECONNECT_INTERVAL } from '../Providers/constants';
|
2 | export var ReconnectEvent;
|
3 | (function (ReconnectEvent) {
|
4 | ReconnectEvent["START_RECONNECT"] = "START_RECONNECT";
|
5 | ReconnectEvent["HALT_RECONNECT"] = "HALT_RECONNECT";
|
6 | })(ReconnectEvent || (ReconnectEvent = {}));
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | var ReconnectionMonitor = (function () {
|
14 | function ReconnectionMonitor() {
|
15 | this.reconnectObservers = [];
|
16 | }
|
17 | |
18 |
|
19 |
|
20 | ReconnectionMonitor.prototype.addObserver = function (reconnectObserver) {
|
21 | this.reconnectObservers.push(reconnectObserver);
|
22 | };
|
23 | |
24 |
|
25 |
|
26 | ReconnectionMonitor.prototype.record = function (event) {
|
27 | var _this = this;
|
28 | if (event === ReconnectEvent.START_RECONNECT) {
|
29 |
|
30 | if (this.reconnectSetTimeoutId === undefined &&
|
31 | this.reconnectIntervalId === undefined) {
|
32 | this.reconnectSetTimeoutId = setTimeout(function () {
|
33 |
|
34 | _this._triggerReconnect();
|
35 |
|
36 | _this.reconnectIntervalId = setInterval(function () {
|
37 | _this._triggerReconnect();
|
38 | }, RECONNECT_INTERVAL);
|
39 | }, RECONNECT_DELAY);
|
40 | }
|
41 | }
|
42 | if (event === ReconnectEvent.HALT_RECONNECT) {
|
43 | if (this.reconnectIntervalId) {
|
44 | clearInterval(this.reconnectIntervalId);
|
45 | this.reconnectIntervalId = undefined;
|
46 | }
|
47 | if (this.reconnectSetTimeoutId) {
|
48 | clearTimeout(this.reconnectSetTimeoutId);
|
49 | this.reconnectSetTimeoutId = undefined;
|
50 | }
|
51 | }
|
52 | };
|
53 | |
54 |
|
55 |
|
56 | ReconnectionMonitor.prototype.close = function () {
|
57 | this.reconnectObservers.forEach(function (reconnectObserver) {
|
58 | var _a;
|
59 | (_a = reconnectObserver.complete) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
|
60 | });
|
61 | };
|
62 | ReconnectionMonitor.prototype._triggerReconnect = function () {
|
63 | this.reconnectObservers.forEach(function (reconnectObserver) {
|
64 | var _a;
|
65 | (_a = reconnectObserver.next) === null || _a === void 0 ? void 0 : _a.call(reconnectObserver);
|
66 | });
|
67 | };
|
68 | return ReconnectionMonitor;
|
69 | }());
|
70 | export { ReconnectionMonitor };
|
71 |
|
\ | No newline at end of file |