react-ecosistema-unp 1.3.0-pre-release.4 → 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.
@@ -1,39 +1,39 @@
1
1
  import { jsx as p } from "react/jsx-runtime";
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";
2
+ import { useRef as l, useCallback as x, useEffect as W } from "react";
3
+ import { L as k } from "../../index-Cs6Q8pv4.js";
4
+ import { useWebSocketContext as N } from "./WebSocketProvider.js";
5
5
  import '../../assets/WebSocketManager.css';const z = ({
6
- urlWs: i,
7
- handlers: m,
8
- socketKey: e,
9
- autoReconnect: d = !0,
10
- maxReconnectAttempts: f = 5
6
+ urlWs: u,
7
+ handlers: i,
8
+ socketKey: o,
9
+ autoReconnect: f = !0,
10
+ maxReconnectAttempts: g = 5
11
11
  }) => {
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);
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);
17
17
  try {
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);
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);
22
22
  }
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.");
23
+ }, e.current.onclose = () => {
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");
32
32
  };
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, {});
33
+ }, [u, i]);
34
+ return W(() => (a(), () => {
35
+ e.current && (e.current.close(), m(o));
36
+ }), [a]), /* @__PURE__ */ p(k, {});
37
37
  };
38
38
  export {
39
39
  z as WebSocketManager
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.4",
5
+ "version": "1.3.0-pre-release.5",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  ".": {