react-ecosistema-unp 1.3.0-pre-release.2 → 1.3.0-pre-release.4

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.
@@ -7,7 +7,6 @@ interface WebSocketManagerProps {
7
7
  urlWs: string;
8
8
  handlers: WebSocketMessageHandler[];
9
9
  socketKey: string;
10
- onGeneralFetch?: (showLoading?: boolean) => void;
11
10
  autoReconnect?: boolean;
12
11
  maxReconnectAttempts?: number;
13
12
  }
@@ -1,42 +1,40 @@
1
1
  import { jsx as p } from "react/jsx-runtime";
2
- import { useRef as b, useCallback as W, useEffect as j } from "react";
3
- import { L as k } from "../../index-Cs6Q8pv4.js";
4
- import { useWebSocketContext as C } from "./WebSocketProvider.js";
5
- import '../../assets/WebSocketManager.css';const L = ({
6
- urlWs: l,
7
- handlers: i,
8
- socketKey: r,
9
- onGeneralFetch: a,
10
- autoReconnect: m = !0,
11
- maxReconnectAttempts: d = 5
2
+ import { useRef as u, useCallback as W, useEffect as x } from "react";
3
+ import { L as N } from "../../index-Cs6Q8pv4.js";
4
+ import { useWebSocketContext as h } from "./WebSocketProvider.js";
5
+ import '../../assets/WebSocketManager.css';const z = ({
6
+ urlWs: i,
7
+ handlers: m,
8
+ socketKey: e,
9
+ autoReconnect: d = !0,
10
+ maxReconnectAttempts: f = 5
12
11
  }) => {
13
- const e = b(null), c = b(0), { setSocket: f, setStatus: t, removeSocket: s } = C(), u = W(() => {
14
- e.current && e.current.close(), console.log(`Conectando WebSocket: ${r}`), t(r, "connecting"), e.current = new WebSocket(l), e.current.onopen = () => {
15
- console.log("WebSocket conectado."), c.current = 0, f(r, e.current), t(r, "connected");
16
- }, e.current.onmessage = (n) => {
17
- console.log("Mensaje recibido:", n.data);
12
+ const r = u(null), t = u(0), { setSocket: g, setStatus: n, removeSocket: s } = h(), a = u(!1), l = W(() => {
13
+ r.current && r.current.close(), console.log(`Conectando WebSocket: ${e}`), n(e, "connecting"), r.current = new WebSocket(i), r.current.onopen = () => {
14
+ console.log("WebSocket conectado."), t.current = 0, a.current = !0, g(e, r.current), n(e, "connected");
15
+ }, r.current.onmessage = (o) => {
16
+ console.log("Mensaje recibido:", o.data);
18
17
  try {
19
- const o = JSON.parse(n.data), S = i.find((g) => g.message === o.message);
20
- S ? S.action(o) : console.warn("No se encontró handler para el mensaje:", o.message), a && a();
21
- } catch (o) {
22
- console.error("Error procesando mensaje WebSocket:", o);
18
+ const c = JSON.parse(o.data), S = m.find((b) => b.message === c.message);
19
+ S ? S.action(c) : console.warn("No se encontró handler para el mensaje:", c.message);
20
+ } catch (c) {
21
+ console.error("Error procesando mensaje:", c);
23
22
  }
24
- }, e.current.onclose = () => {
25
- if (console.log("WebSocket cerrado."), t(r, "disconnected"), s(r), m && c.current < d) {
26
- const n = Math.min(3e4, 1e3 * 2 ** c.current);
27
- console.log(`Reintentando en ${n / 1e3}s...`), setTimeout(() => {
28
- c.current += 1, u();
29
- }, n);
30
- }
31
- }, e.current.onerror = (n) => {
32
- var o;
33
- console.error("Error en WebSocket:", n), t(r, "error"), (o = e.current) == null || o.close();
23
+ }, r.current.onerror = (o) => {
24
+ console.error("Error en WebSocket:", o), n(e, "error");
25
+ }, r.current.onclose = () => {
26
+ if (console.log("WebSocket cerrado."), n(e, "disconnected"), s(e), d && t.current < f && a.current) {
27
+ const o = Math.min(3e4, 1e3 * 2 ** t.current);
28
+ console.log(`Reintentando conexión en ${o / 1e3}s...`), setTimeout(() => {
29
+ t.current += 1, l();
30
+ }, o);
31
+ } else a.current ? console.error("No se realizará más reconexiones. Máximo alcanzado.") : console.error("Nunca se logró conectar. No se realizarán reconexiones.");
34
32
  };
35
- }, [l, i, r, a, m, d, f, t, s]);
36
- return j(() => (u(), () => {
37
- e.current && (e.current.close(), s(r));
38
- }), [u, r, s]), /* @__PURE__ */ p(k, {});
33
+ }, [i, m, e, d, f, g, n, s]);
34
+ return x(() => (l(), () => {
35
+ r.current && (r.current.close(), s(e));
36
+ }), [l, e, s]), /* @__PURE__ */ p(N, {});
39
37
  };
40
38
  export {
41
- L as WebSocketManager
39
+ z as WebSocketManager
42
40
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "react-ecosistema-unp",
3
3
  "author": "Ecosistema de Información - Unidad Nacional de Protección",
4
4
  "private": false,
5
- "version": "1.3.0-pre-release.2",
5
+ "version": "1.3.0-pre-release.4",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {