rc-lib-ui 1.2.14 → 1.2.15
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.
- package/dist/socket.js +68 -68
- package/package.json +1 -1
package/dist/socket.js
CHANGED
|
@@ -2,7 +2,7 @@ import './socket.css';var J = Object.defineProperty;
|
|
|
2
2
|
var z = (n, e, t) => e in n ? J(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
|
|
3
3
|
var r = (n, e, t) => z(n, typeof e != "symbol" ? e + "" : e, t);
|
|
4
4
|
import { jsx as D } from "react/jsx-runtime";
|
|
5
|
-
import q, { useState as F, useRef as x, useCallback as E, useEffect as
|
|
5
|
+
import q, { useState as F, useRef as x, useCallback as E, useEffect as I } from "react";
|
|
6
6
|
import { c as U } from "./react-CLnE01WS.js";
|
|
7
7
|
import { styled as M, Collapse as G } from "@mui/material";
|
|
8
8
|
import B from "classnames";
|
|
@@ -76,11 +76,11 @@ const L = {
|
|
|
76
76
|
height: "100%"
|
|
77
77
|
}
|
|
78
78
|
})), Z = ({ text: n = "Происходит подключение к серверу", className: e, ...t }) => {
|
|
79
|
-
const
|
|
79
|
+
const o = g(b.getStatusConnectSocket), i = g(b.getStatusIsReConnectSocket);
|
|
80
80
|
return /* @__PURE__ */ D(
|
|
81
81
|
Y,
|
|
82
82
|
{
|
|
83
|
-
in: i,
|
|
83
|
+
in: o === "pending" || i,
|
|
84
84
|
collapsedSize: "1px",
|
|
85
85
|
className: B(X["connect-server-anim"], e),
|
|
86
86
|
unmountOnExit: !0,
|
|
@@ -100,26 +100,26 @@ class ee {
|
|
|
100
100
|
}, i = (u) => {
|
|
101
101
|
t != null && t.controlAction && (t == null || t.controlAction(u));
|
|
102
102
|
};
|
|
103
|
-
let
|
|
103
|
+
let c = !0, a, l, S;
|
|
104
104
|
const f = (u = !0) => {
|
|
105
105
|
const C = "Ручное завершение startActionEvery";
|
|
106
|
-
|
|
106
|
+
c = !1, clearInterval(a), o(null), u ? l && l({ status: u, msg: C + ": (true)" }) : S && S({ status: u, msg: C + ": (false)" });
|
|
107
107
|
};
|
|
108
108
|
return {
|
|
109
109
|
promise: new Promise((u, C) => {
|
|
110
110
|
l = u, S = C;
|
|
111
111
|
let O = 0, d = 0;
|
|
112
|
-
|
|
112
|
+
a = setInterval(
|
|
113
113
|
() => {
|
|
114
114
|
if (O += t.interval, d += 1, t != null && t.cutoffTime && O > t.cutoffTime || t != null && t.countAction && (t == null ? void 0 : t.countAction) < d) {
|
|
115
|
-
|
|
115
|
+
c = !1, clearInterval(a), o(null), C({ status: !1, msg: Error("Время загрузки истекло") });
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
|
-
e() && (
|
|
118
|
+
e() && (c = !1, clearInterval(a), o(null), u({ status: !0, msg: "cb вернул true" }));
|
|
119
119
|
},
|
|
120
120
|
t.interval < 200 ? 200 : t.interval
|
|
121
|
-
), o(
|
|
122
|
-
getIsActiveEvent: () =>
|
|
121
|
+
), o(a), i({
|
|
122
|
+
getIsActiveEvent: () => c,
|
|
123
123
|
stop: f
|
|
124
124
|
});
|
|
125
125
|
}),
|
|
@@ -131,24 +131,24 @@ class ee {
|
|
|
131
131
|
e().then(() => {
|
|
132
132
|
i === 1 && (i = 0);
|
|
133
133
|
});
|
|
134
|
-
let
|
|
135
|
-
i === 1 && t(), clearInterval(
|
|
134
|
+
let c = setInterval(() => {
|
|
135
|
+
i === 1 && t(), clearInterval(c);
|
|
136
136
|
}, o * 1e3);
|
|
137
137
|
});
|
|
138
|
-
r(this, "oneOfPromise", (e, t, { second: o }) => new Promise((i,
|
|
139
|
-
let
|
|
138
|
+
r(this, "oneOfPromise", (e, t, { second: o }) => new Promise((i, c) => {
|
|
139
|
+
let a = 1, l = { status: !1, msg: "" };
|
|
140
140
|
e().then((f) => {
|
|
141
|
-
|
|
141
|
+
a === 1 && (a = 0, i(f));
|
|
142
142
|
}).catch((f) => {
|
|
143
|
-
|
|
143
|
+
a === 1 && (a = 0, l.msg = f, c(f));
|
|
144
144
|
});
|
|
145
145
|
let S = setInterval(() => {
|
|
146
|
-
if (
|
|
147
|
-
if (
|
|
148
|
-
|
|
146
|
+
if (a === 1) {
|
|
147
|
+
if (a = 0, typeof t == "function") {
|
|
148
|
+
c({ status: !1, msg: "", ...t(l) });
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
|
-
|
|
151
|
+
c({ status: !1, msg: "oneOfPromise reject" });
|
|
152
152
|
}
|
|
153
153
|
clearInterval(S);
|
|
154
154
|
}, o * 1e3);
|
|
@@ -207,9 +207,9 @@ class te {
|
|
|
207
207
|
["message", this.msgHandler],
|
|
208
208
|
["error", this.errHandler]
|
|
209
209
|
];
|
|
210
|
-
for (let
|
|
211
|
-
const [
|
|
212
|
-
e === "add" ? (o = this.state.ws) == null || o.addEventListener(
|
|
210
|
+
for (let c = 0; c < t.length; c++) {
|
|
211
|
+
const [a, l] = t[c];
|
|
212
|
+
e === "add" ? (o = this.state.ws) == null || o.addEventListener(a, l) : (i = this.state.ws) == null || i.removeEventListener(a, l);
|
|
213
213
|
}
|
|
214
214
|
});
|
|
215
215
|
r(this, "openHandler", () => {
|
|
@@ -223,7 +223,7 @@ class te {
|
|
|
223
223
|
try {
|
|
224
224
|
const { action: o } = t, i = this.findDataRequestByAction(o);
|
|
225
225
|
if (i) {
|
|
226
|
-
const { cb:
|
|
226
|
+
const { cb: c, ...a } = i, { payload: l, ...S } = a;
|
|
227
227
|
this.events.publish("msg", { ...t, request: { ...S, ...l } });
|
|
228
228
|
} else
|
|
229
229
|
this.events.publish("msg", t);
|
|
@@ -261,7 +261,7 @@ class te {
|
|
|
261
261
|
const e = this.initOptions;
|
|
262
262
|
return e || this.errorInitSocket(), e;
|
|
263
263
|
});
|
|
264
|
-
r(this, "findDataRequestByAction", (e) => this.getItemsRequestSaveByAction(e).sort((i,
|
|
264
|
+
r(this, "findDataRequestByAction", (e) => this.getItemsRequestSaveByAction(e).sort((i, c) => c.requestTime - i.requestTime)[0]);
|
|
265
265
|
}
|
|
266
266
|
resetState() {
|
|
267
267
|
this.state = this.copyState(this.stateDefault);
|
|
@@ -275,8 +275,8 @@ class te {
|
|
|
275
275
|
filterSaveItemsByResponse(e) {
|
|
276
276
|
const t = this.getRequestSave(), o = [];
|
|
277
277
|
for (let i = 0; i < t.length; i++) {
|
|
278
|
-
const
|
|
279
|
-
|
|
278
|
+
const c = t[i];
|
|
279
|
+
c.payload.action !== e.action ? o.push(c) : c.cb && c.cb(e);
|
|
280
280
|
}
|
|
281
281
|
this.state.arrSaveReq = o;
|
|
282
282
|
}
|
|
@@ -334,11 +334,11 @@ const s = class s {
|
|
|
334
334
|
s.state.isDisconnect || (s.setState({ isDisconnect: !0 }), console.log("DISCONNECT WS"), s.wsApi.disconnect(), s.resetState(), s.events.resetSubscribers());
|
|
335
335
|
}
|
|
336
336
|
static send(e, t) {
|
|
337
|
-
const { action: o, ...i } = e,
|
|
337
|
+
const { action: o, ...i } = e, c = i != null && i.request_id ? i.request_id : W(), a = Date.now();
|
|
338
338
|
s.wsApi.setRequestSave({
|
|
339
339
|
requestAction: o,
|
|
340
|
-
request_id:
|
|
341
|
-
requestTime:
|
|
340
|
+
request_id: c,
|
|
341
|
+
requestTime: a,
|
|
342
342
|
payload: { action: o, ...i },
|
|
343
343
|
cb: t
|
|
344
344
|
});
|
|
@@ -359,10 +359,10 @@ const s = class s {
|
|
|
359
359
|
i(new DOMException("Aborted", "AbortError"));
|
|
360
360
|
return;
|
|
361
361
|
}
|
|
362
|
-
const
|
|
362
|
+
const c = e.action, a = e.request_id ? e.request_id : W(), l = Date.now();
|
|
363
363
|
s.wsApi.setRequestSave({
|
|
364
|
-
requestAction:
|
|
365
|
-
request_id:
|
|
364
|
+
requestAction: c,
|
|
365
|
+
request_id: a,
|
|
366
366
|
requestTime: l,
|
|
367
367
|
payload: e,
|
|
368
368
|
cb: void 0
|
|
@@ -375,8 +375,8 @@ const s = class s {
|
|
|
375
375
|
C(), i(v);
|
|
376
376
|
}, p = (v) => {
|
|
377
377
|
var A;
|
|
378
|
-
const
|
|
379
|
-
!
|
|
378
|
+
const y = this.wsApi.findDataRequestByAction(c);
|
|
379
|
+
!y || ((A = v == null ? void 0 : v.request) == null ? void 0 : A.requestAction) !== y.requestAction || (C(), o({ ...v }));
|
|
380
380
|
}, u = () => {
|
|
381
381
|
C(), i(new DOMException("Aborted", "AbortError"));
|
|
382
382
|
}, C = () => {
|
|
@@ -416,8 +416,8 @@ r(s, "state", {
|
|
|
416
416
|
s.state.isActiveReConnect && s.stopReConnect(!1);
|
|
417
417
|
}), r(s, "splitOptions", (e) => Object.entries(e).reduce(
|
|
418
418
|
(t, [o, i]) => {
|
|
419
|
-
const
|
|
420
|
-
return o in
|
|
419
|
+
const c = s.wsApi.getOptions();
|
|
420
|
+
return o in c ? { ...t, WsOptions: { ...t.WsOptions, [o]: i } } : { ...t, SocketApiOptions: { ...t.SocketApiOptions, [o]: i } };
|
|
421
421
|
},
|
|
422
422
|
{ WsOptions: {}, SocketApiOptions: {} }
|
|
423
423
|
)), /*---------------------------------------------------------------------------------------------------------------------------*/
|
|
@@ -450,27 +450,27 @@ r(s, "socketReConnect", () => {
|
|
|
450
450
|
{
|
|
451
451
|
interval: e,
|
|
452
452
|
countAction: i,
|
|
453
|
-
watchIdInterval: (
|
|
454
|
-
s.saveID.idReConnect =
|
|
453
|
+
watchIdInterval: (a) => {
|
|
454
|
+
s.saveID.idReConnect = a;
|
|
455
455
|
},
|
|
456
|
-
controlAction: ({ stop:
|
|
457
|
-
s.stopReConnect =
|
|
456
|
+
controlAction: ({ stop: a, getIsActiveEvent: l }) => {
|
|
457
|
+
s.stopReConnect = a;
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
|
-
).promise.then((
|
|
461
|
-
s.setInfoConnect(
|
|
462
|
-
}).catch((
|
|
460
|
+
).promise.then((a) => {
|
|
461
|
+
s.setInfoConnect(a);
|
|
462
|
+
}).catch((a) => {
|
|
463
463
|
if (s.wsApi.getStatusSocket() === "ready") {
|
|
464
464
|
console.log("Сокет успел подключиться, игнорируем ошибку таймаута"), s.setInfoConnect({ status: !0, msg: "Подключено (восстановлено)" });
|
|
465
465
|
return;
|
|
466
466
|
}
|
|
467
|
-
s.setInfoConnect(
|
|
467
|
+
s.setInfoConnect(a);
|
|
468
468
|
});
|
|
469
469
|
}
|
|
470
470
|
});
|
|
471
471
|
let m = s;
|
|
472
472
|
const se = (n, e = {}) => {
|
|
473
|
-
const t = n.action, { skip: o = !1, timeout: i = 5e3 } = e, [
|
|
473
|
+
const t = n.action, { skip: o = !1, timeout: i = 5e3 } = e, [c, a] = F({
|
|
474
474
|
data: null,
|
|
475
475
|
error: "",
|
|
476
476
|
isLoading: !1,
|
|
@@ -479,9 +479,9 @@ const se = (n, e = {}) => {
|
|
|
479
479
|
}), l = g(b.getStatusReady), S = g(b.getStatusConnectSocket), f = x(null), p = x(e);
|
|
480
480
|
p.current = e;
|
|
481
481
|
const u = E(async () => {
|
|
482
|
-
var k, v,
|
|
482
|
+
var k, v, y, A;
|
|
483
483
|
if (o) return;
|
|
484
|
-
|
|
484
|
+
a((w) => ({
|
|
485
485
|
...w,
|
|
486
486
|
isLoading: !0,
|
|
487
487
|
isError: !1,
|
|
@@ -493,7 +493,7 @@ const se = (n, e = {}) => {
|
|
|
493
493
|
try {
|
|
494
494
|
const w = await m.request(n, { timeout: i, signal: d });
|
|
495
495
|
if (d.aborted) return;
|
|
496
|
-
|
|
496
|
+
a((N) => ({
|
|
497
497
|
...N,
|
|
498
498
|
data: w,
|
|
499
499
|
isSuccess: !0,
|
|
@@ -502,19 +502,19 @@ const se = (n, e = {}) => {
|
|
|
502
502
|
} catch (w) {
|
|
503
503
|
if (d.aborted) return;
|
|
504
504
|
const N = w instanceof Error ? w.message : String(w);
|
|
505
|
-
|
|
505
|
+
a((H) => ({
|
|
506
506
|
...H,
|
|
507
507
|
error: N,
|
|
508
508
|
isError: !0,
|
|
509
509
|
isLoading: !1
|
|
510
|
-
})), (A = (
|
|
510
|
+
})), (A = (y = p.current).onError) == null || A.call(y, N);
|
|
511
511
|
}
|
|
512
512
|
}, [o, t, n, i]);
|
|
513
|
-
|
|
513
|
+
I(() => (!o && l && u(), () => {
|
|
514
514
|
var d;
|
|
515
515
|
(d = f.current) == null || d.abort();
|
|
516
|
-
}), [u, o, l]),
|
|
517
|
-
!l && S === "pending" &&
|
|
516
|
+
}), [u, o, l]), I(() => {
|
|
517
|
+
!l && S === "pending" && a((d) => ({
|
|
518
518
|
...d,
|
|
519
519
|
isError: !1,
|
|
520
520
|
isSuccess: !1,
|
|
@@ -526,16 +526,16 @@ const se = (n, e = {}) => {
|
|
|
526
526
|
return (d = f.current) == null || d.abort(), u();
|
|
527
527
|
}, [u]), O = E(() => {
|
|
528
528
|
var d;
|
|
529
|
-
(d = f.current) == null || d.abort(),
|
|
529
|
+
(d = f.current) == null || d.abort(), a((k) => ({ ...k, isLoading: !1 }));
|
|
530
530
|
}, []);
|
|
531
531
|
return {
|
|
532
|
-
...
|
|
532
|
+
...c,
|
|
533
533
|
refetch: C,
|
|
534
534
|
abort: O
|
|
535
535
|
};
|
|
536
536
|
}, be = (n, e) => se(n, e), ne = (n) => {
|
|
537
|
-
const { isNetwork: e, typeNetwork: t } = n, { isModal: o } = g(b.getInfoNoConnectServer), i = g(b.getStatusIsReConnectSocket),
|
|
538
|
-
return
|
|
537
|
+
const { isNetwork: e, typeNetwork: t } = n, { isModal: o } = g(b.getInfoNoConnectServer), i = g(b.getStatusIsReConnectSocket), c = g(b.getIsDisableConnectSocket), a = g(b.getStatusConnectSocket);
|
|
538
|
+
return I(() => (m.init(n.init), typeof n.onMount == "function" && n.onMount(), m.on("status", (l) => {
|
|
539
539
|
const S = R.getState(), { isReadySocket: f, infoNoConnectServer: { isModal: p }, isOfflineSocket: u } = S;
|
|
540
540
|
l !== "ready" && f && h.setStatusReady({ isReadySocket: !1 }), !f && l === "ready" && (h.setStatusReady({ isReadySocket: !0 }), p && u && (console.log("Вырубаем модалку т.к. сокет законектился после окончания timeOffReConnect"), h.setInfoNoConnectServer({ isModal: !1 }), h.setIsOfflineSocket({ isOfflineSocket: !1 }))), h.setStatusConnectSocket({ statusConnect: l });
|
|
541
541
|
}), m.on("error", (l) => {
|
|
@@ -552,13 +552,13 @@ const se = (n, e = {}) => {
|
|
|
552
552
|
}
|
|
553
553
|
}), m.connect(), () => {
|
|
554
554
|
typeof n.onUnmount == "function" && n.onUnmount(), console.dir("disconnect"), m.disconnect();
|
|
555
|
-
}), []),
|
|
556
|
-
e && !
|
|
557
|
-
}, [
|
|
558
|
-
i && (!e ||
|
|
559
|
-
}, [i, e,
|
|
560
|
-
|
|
561
|
-
}, [
|
|
555
|
+
}), []), I(() => {
|
|
556
|
+
e && !c && !o && !i && ["close"].includes(a) && t !== "none" && (console.log("Запущен socketReConnect"), m.socketReConnect());
|
|
557
|
+
}, [c, o, i, a, t, e]), I(() => {
|
|
558
|
+
i && (!e || a === "ready") && (console.log("Запущен stopReConnect"), m.stopReConnect());
|
|
559
|
+
}, [i, e, a]), I(() => {
|
|
560
|
+
c && (console.log("isDisableConnectSocket: ", c), h.setIsOfflineSocket({ isOfflineSocket: !0 }), m.close());
|
|
561
|
+
}, [c]), null;
|
|
562
562
|
}, oe = q.memo(ne), ie = M(T, {
|
|
563
563
|
shouldForwardProp: (n) => ![""].includes(n)
|
|
564
564
|
})(({ theme: n }) => ({
|
|
@@ -570,14 +570,14 @@ const se = (n, e = {}) => {
|
|
|
570
570
|
padding: "1px 10px"
|
|
571
571
|
}
|
|
572
572
|
})), re = ({ children: n, className: e, isNetwork: t, ...o }) => {
|
|
573
|
-
const i = g(b.getIsOfflineSocket),
|
|
573
|
+
const i = g(b.getIsOfflineSocket), c = g(b.getIsDisableConnectSocket), a = i || !t, l = "Оффлайн";
|
|
574
574
|
return /* @__PURE__ */ D(
|
|
575
575
|
ie,
|
|
576
576
|
{
|
|
577
|
-
in:
|
|
577
|
+
in: a,
|
|
578
578
|
className: B("socket-offline", e),
|
|
579
579
|
...o,
|
|
580
|
-
children: typeof n == "function" ? n({ isDisableConnectSocket:
|
|
580
|
+
children: typeof n == "function" ? n({ isDisableConnectSocket: c }) : c ? `Режим ${l}` : l
|
|
581
581
|
}
|
|
582
582
|
);
|
|
583
583
|
}, ce = q.memo(re), ae = ({ children: n }) => {
|