react-ecosistema-unp 1.14.0 → 1.14.1
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.
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
|
|
1
|
+
var u = Object.defineProperty;
|
|
2
|
+
var k = (n, t, e) => t in n ? u(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
3
|
+
var r = (n, t, e) => k(n, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
const i = [3e3, 3e4, 18e4];
|
|
5
|
+
class S {
|
|
5
6
|
constructor() {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
r(this, "sockets", /* @__PURE__ */ new Map());
|
|
8
|
+
r(this, "statusCallbacks", []);
|
|
8
9
|
}
|
|
9
10
|
getAggregateStatus() {
|
|
10
11
|
const t = Array.from(this.sockets.values()).map((e) => e.status);
|
|
@@ -26,7 +27,8 @@ class k {
|
|
|
26
27
|
status: "disconnected",
|
|
27
28
|
messageHandlers: /* @__PURE__ */ new Set(),
|
|
28
29
|
reconnectTimer: null,
|
|
29
|
-
shouldReconnect: !0
|
|
30
|
+
shouldReconnect: !0,
|
|
31
|
+
retryCount: 0
|
|
30
32
|
};
|
|
31
33
|
return this.sockets.set(t, e), e;
|
|
32
34
|
}
|
|
@@ -40,25 +42,27 @@ class k {
|
|
|
40
42
|
e.shouldReconnect = !0, this.setSocketStatus(t, "connecting");
|
|
41
43
|
const s = new WebSocket(t);
|
|
42
44
|
e.socket = s, s.onopen = () => {
|
|
43
|
-
console.log(`✅ WebSocket conectado a ${t}`), this.setSocketStatus(t, "connected"), e.reconnectTimer && clearTimeout(e.reconnectTimer), e.reconnectTimer = null;
|
|
45
|
+
console.log(`✅ WebSocket conectado a ${t}`), this.setSocketStatus(t, "connected"), e.reconnectTimer && clearTimeout(e.reconnectTimer), e.reconnectTimer = null, e.retryCount = 0;
|
|
44
46
|
}, s.onmessage = (c) => {
|
|
45
47
|
try {
|
|
46
48
|
const o = JSON.parse(c.data);
|
|
47
|
-
e == null || e.messageHandlers.forEach((
|
|
49
|
+
e == null || e.messageHandlers.forEach((a) => a(o));
|
|
48
50
|
} catch (o) {
|
|
49
51
|
console.error("❌ Error parseando mensaje WebSocket", o);
|
|
50
52
|
}
|
|
51
53
|
}, s.onclose = () => {
|
|
52
|
-
if (
|
|
54
|
+
if (e.socket = null, !e.shouldReconnect) {
|
|
53
55
|
this.setSocketStatus(t, "disconnected");
|
|
54
56
|
return;
|
|
55
57
|
}
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
e.reconnectTimer = null, e.shouldReconnect && this.connect(t);
|
|
60
|
-
}, c);
|
|
58
|
+
if (e.retryCount >= i.length) {
|
|
59
|
+
console.warn(`🔌 WebSocket: se agotaron los reintentos para ${t}`), e.shouldReconnect = !1, this.setSocketStatus(t, "disconnected");
|
|
60
|
+
return;
|
|
61
61
|
}
|
|
62
|
+
const c = i[e.retryCount];
|
|
63
|
+
e.retryCount++, console.warn(`🔌 WebSocket cerrado para ${t}. Reintentando en ${c / 1e3}s (intento ${e.retryCount}/${i.length})...`), this.setSocketStatus(t, "connecting"), e.reconnectTimer || (e.reconnectTimer = setTimeout(() => {
|
|
64
|
+
e.reconnectTimer = null, e.shouldReconnect && this.connect(t);
|
|
65
|
+
}, c));
|
|
62
66
|
}, s.onerror = (c) => {
|
|
63
67
|
console.error("⚠️ WebSocket error:", c), this.setSocketStatus(t, "disconnected"), s.close();
|
|
64
68
|
};
|
|
@@ -92,7 +96,7 @@ class k {
|
|
|
92
96
|
s == null || s.messageHandlers.delete(e);
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
|
-
const
|
|
99
|
+
const h = new S();
|
|
96
100
|
export {
|
|
97
|
-
|
|
101
|
+
h as webSocketService
|
|
98
102
|
};
|