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