dev-classes 1.1.20 → 1.2.0
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/classes/SocketApi/SocketApi.d.ts +10 -2
- package/dist/classes/SocketApi/SocketApi.js +19 -17
- package/dist/classes/SocketApi/deps/WsApi/WsApi.d.ts +14 -6
- package/dist/classes/SocketApi/deps/WsApi/WsApi.js +54 -38
- package/dist/classes/SocketApi/deps/WsApi/WsApi.types.d.ts +9 -1
- package/package.json +1 -1
|
@@ -22,12 +22,20 @@ export declare class SocketApi {
|
|
|
22
22
|
static setOptions: (option?: ConnectOptions_P) => void;
|
|
23
23
|
static close(): void;
|
|
24
24
|
static disconnect(): void;
|
|
25
|
-
static send<ResType>(data: object):
|
|
25
|
+
static send<ResType>(data: object, cbSyccess?: (data: ResType) => void, cbError?: (err: Error) => void): void;
|
|
26
26
|
static connect(): void;
|
|
27
27
|
static stopReConnect(): void;
|
|
28
28
|
static resetState(): void;
|
|
29
29
|
static getTimeRequest(): void;
|
|
30
|
-
static
|
|
30
|
+
static getRequestSave: () => {
|
|
31
|
+
payload: {
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
action: string;
|
|
34
|
+
};
|
|
35
|
+
reqId: string;
|
|
36
|
+
resolve: any;
|
|
37
|
+
reject: any;
|
|
38
|
+
}[];
|
|
31
39
|
static watchReConnect(cb: WatchI["watchReConnect"]): void;
|
|
32
40
|
static watchTimeOffReConnect(cb: WatchI["watchTimeOffReConnect"]): void;
|
|
33
41
|
private static copyState;
|
|
@@ -2,15 +2,15 @@ var p = Object.defineProperty;
|
|
|
2
2
|
var u = (n, e, s) => e in n ? p(n, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[e] = s;
|
|
3
3
|
var c = (n, e, s) => (u(n, typeof e != "symbol" ? e + "" : e, s), s);
|
|
4
4
|
import { WsApi as C } from "./deps/WsApi/WsApi.js";
|
|
5
|
-
const
|
|
6
|
-
function
|
|
7
|
-
return
|
|
5
|
+
const d = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
6
|
+
function R(n) {
|
|
7
|
+
return d.test(n);
|
|
8
8
|
}
|
|
9
9
|
function i() {
|
|
10
10
|
var n = URL.createObjectURL(new Blob()), e = n.toString();
|
|
11
11
|
return URL.revokeObjectURL(n), e.split(/[:\/]/g).pop().toLowerCase();
|
|
12
12
|
}
|
|
13
|
-
i.valid =
|
|
13
|
+
i.valid = R;
|
|
14
14
|
class v {
|
|
15
15
|
watchTimeOffReConnect(e) {
|
|
16
16
|
}
|
|
@@ -30,17 +30,19 @@ const t = class t {
|
|
|
30
30
|
static disconnect() {
|
|
31
31
|
t.state.isDisconnect || (t.state.isDisconnect = !0, console.log("DISCONNECT WS"), t.wsApi.internet.removeWatcherInternet(), t.wsApi.setStatus("disconnect"), t.resetSocket(), t.resetState(), t.wsApi.resetState());
|
|
32
32
|
}
|
|
33
|
-
static send(e) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
33
|
+
static send(e, s, r) {
|
|
34
|
+
var a;
|
|
35
|
+
const { action: w, ...l } = e, f = i();
|
|
36
|
+
if (t.wsApi.setRequestSave({
|
|
37
|
+
reqId: f,
|
|
38
|
+
payload: { action: w, ...l },
|
|
39
|
+
resolve: s,
|
|
40
|
+
reject: r
|
|
41
|
+
}), !t.wsApi.state.ws || t.wsApi.state.ws.readyState !== 1) {
|
|
42
|
+
console.log("Нет подключения к сокету. Данные запроса сохранены", t.wsApi.state.arrSaveReq);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
(a = t.wsApi.state.ws) == null || a.send(JSON.stringify(e));
|
|
44
46
|
}
|
|
45
47
|
static connect() {
|
|
46
48
|
t.createConnect();
|
|
@@ -81,9 +83,9 @@ c(t, "wsApi", new C()), c(t, "watch", new v()), c(t, "state", {
|
|
|
81
83
|
checkConnect: null
|
|
82
84
|
}), c(t, "stateDefault", t.copyState(t.state)), c(t, "setOptions", (e = t.wsApi.configWs) => {
|
|
83
85
|
t.state.initConnect || (t.state.initConnect = !0, t.wsApi.configWs = { ...t.wsApi.configWs, ...e }, t.wsApi.internet.addWatcherInternet());
|
|
84
|
-
}), c(t, "
|
|
86
|
+
}), c(t, "getRequestSave", t.wsApi.getRequestSave), c(t, "socketReConnect", () => {
|
|
85
87
|
t.saveID.idConnect ? (console.groupCollapsed("Процесс idConnect уже запущен"), console.log("SocketApi.saveID: ", t.saveID), console.groupEnd()) : (t.state.isReConnect = !0, t.watch.watchReConnect(!0), t.createConnect(), t.wsApi.startActionEvery(
|
|
86
|
-
() => t.wsApi.state.statusConnect === "ready" ? !0 : (t.createConnect(), !1),
|
|
88
|
+
() => t.wsApi.state.statusConnect === "ready" ? (console.dir("Подключение установлено"), !0) : (t.createConnect(), !1),
|
|
87
89
|
{
|
|
88
90
|
interval: t.wsApi.configWs.timeReConnect,
|
|
89
91
|
countAction: t.wsApi.configWs.numberOfRepit,
|
|
@@ -6,12 +6,6 @@ export declare class WsApi extends DelaysPromise {
|
|
|
6
6
|
configWs: ConnectOptions_P;
|
|
7
7
|
internet: InternetWatcher;
|
|
8
8
|
state: WsApiStateDefaultI & WsApiStateSaveDefaultI;
|
|
9
|
-
totalInfoReqPromise: {
|
|
10
|
-
action: string;
|
|
11
|
-
reqId: string;
|
|
12
|
-
resolve: any;
|
|
13
|
-
reject: any;
|
|
14
|
-
}[];
|
|
15
9
|
private stateDefault;
|
|
16
10
|
setStatus: (status: StatusConnect_OR) => void;
|
|
17
11
|
removeEvents: () => void;
|
|
@@ -25,4 +19,18 @@ export declare class WsApi extends DelaysPromise {
|
|
|
25
19
|
private copyState;
|
|
26
20
|
resetState(): void;
|
|
27
21
|
private sendInformationToTheEvent;
|
|
22
|
+
setRequestSave(reqInfo: typeof this.state.arrSaveReq[number]): void;
|
|
23
|
+
getRequestSave(): {
|
|
24
|
+
payload: {
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
action: string;
|
|
27
|
+
};
|
|
28
|
+
reqId: string;
|
|
29
|
+
resolve: any;
|
|
30
|
+
reject: any;
|
|
31
|
+
}[];
|
|
32
|
+
setResponceInReqSave(responce: {
|
|
33
|
+
action: string;
|
|
34
|
+
[key: string]: any;
|
|
35
|
+
}): void;
|
|
28
36
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var r = (
|
|
4
|
-
import { DelaysPromise as
|
|
1
|
+
var h = Object.defineProperty;
|
|
2
|
+
var l = (i, n, e) => n in i ? h(i, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[n] = e;
|
|
3
|
+
var r = (i, n, e) => (l(i, typeof n != "symbol" ? n + "" : n, e), e);
|
|
4
|
+
import { DelaysPromise as c } from "../../../Delay/Delay.js";
|
|
5
5
|
import { InternetWatcher as v } from "../InternetWatcher/InternetWatcher.js";
|
|
6
|
-
class
|
|
6
|
+
class p extends c {
|
|
7
7
|
constructor() {
|
|
8
8
|
super(...arguments);
|
|
9
9
|
r(this, "configWs", {
|
|
@@ -22,68 +22,84 @@ class E extends d {
|
|
|
22
22
|
status: []
|
|
23
23
|
}
|
|
24
24
|
});
|
|
25
|
-
// saveState: WsApiStateSaveDefaultI = {
|
|
26
|
-
// };
|
|
27
|
-
r(this, "totalInfoReqPromise", []);
|
|
28
25
|
r(this, "stateDefault", this.copyState(this.state));
|
|
29
|
-
r(this, "setStatus", (
|
|
30
|
-
this.sendInformationToTheEvent("status",
|
|
26
|
+
r(this, "setStatus", (e) => {
|
|
27
|
+
this.sendInformationToTheEvent("status", e), this.state.statusConnect = e;
|
|
31
28
|
});
|
|
32
29
|
r(this, "removeEvents", () => {
|
|
33
|
-
var
|
|
34
|
-
(
|
|
30
|
+
var e, t, s, a;
|
|
31
|
+
(e = this.state.ws) == null || e.removeEventListener("open", this.openHandler), (t = this.state.ws) == null || t.removeEventListener("close", this.closeHandler), (s = this.state.ws) == null || s.removeEventListener("message", this.msgHandler), (a = this.state.ws) == null || a.removeEventListener("error", this.errHandler);
|
|
35
32
|
});
|
|
36
33
|
r(this, "addEvents", () => {
|
|
37
|
-
var
|
|
38
|
-
(
|
|
34
|
+
var e, t, s, a;
|
|
35
|
+
(e = this.state.ws) == null || e.addEventListener("open", this.openHandler), (t = this.state.ws) == null || t.addEventListener("close", this.closeHandler), (s = this.state.ws) == null || s.addEventListener("message", this.msgHandler), (a = this.state.ws) == null || a.addEventListener("error", this.errHandler);
|
|
39
36
|
});
|
|
40
37
|
r(this, "openHandler", () => {
|
|
38
|
+
var t;
|
|
41
39
|
console.log("this >> open"), this.setStatus("ready");
|
|
40
|
+
const e = this.getRequestSave();
|
|
41
|
+
if (e.length)
|
|
42
|
+
for (let s = 0; s < e.length; s++) {
|
|
43
|
+
const a = e[s];
|
|
44
|
+
(t = this.state.ws) == null || t.send(JSON.stringify(a.payload));
|
|
45
|
+
}
|
|
42
46
|
});
|
|
43
47
|
r(this, "closeHandler", () => {
|
|
44
48
|
console.log("this >> close"), this.setStatus("close");
|
|
45
49
|
});
|
|
46
|
-
r(this, "msgHandler", (
|
|
47
|
-
const
|
|
48
|
-
if ("action" in e && this.state.arrSaveReq.length) {
|
|
49
|
-
const s = this.state.arrSaveReq.findIndex((n) => n.action === e.action);
|
|
50
|
-
~s && this.state.arrSaveReq.splice(s, 1);
|
|
51
|
-
}
|
|
52
|
-
!this.state.arrSaveReq.length && this.state.isRequestArrSaveReq && (this.state.isRequestArrSaveReq = !1);
|
|
50
|
+
r(this, "msgHandler", (e) => {
|
|
51
|
+
const t = JSON.parse(e.data ? e.data : "{}");
|
|
53
52
|
try {
|
|
54
|
-
const { action: s } =
|
|
55
|
-
|
|
56
|
-
const o = this.totalInfoReqPromise[h];
|
|
57
|
-
o.action !== s ? n.push(o) : o.resolve && o.resolve(e);
|
|
58
|
-
}
|
|
59
|
-
this.totalInfoReqPromise = n, this.sendInformationToTheEvent("msg", e);
|
|
53
|
+
const { action: s } = t;
|
|
54
|
+
s && this.setResponceInReqSave(t), this.sendInformationToTheEvent("msg", t);
|
|
60
55
|
} catch {
|
|
61
56
|
this.sendInformationToTheEvent("msg", JSON.parse("{}"));
|
|
62
57
|
}
|
|
63
58
|
});
|
|
64
|
-
r(this, "errHandler", (
|
|
59
|
+
r(this, "errHandler", (e) => {
|
|
65
60
|
console.log("this >> err"), this.setStatus("error");
|
|
66
61
|
});
|
|
67
|
-
r(this, "sendInformationToTheEvent", (
|
|
62
|
+
r(this, "sendInformationToTheEvent", (e, t) => {
|
|
68
63
|
var s;
|
|
69
|
-
(s = this.state.subscribersEvents[
|
|
64
|
+
(s = this.state.subscribersEvents[e]) == null || s.forEach((a) => a(t));
|
|
70
65
|
});
|
|
71
66
|
}
|
|
72
|
-
on(
|
|
73
|
-
return this.state.subscribersEvents[
|
|
74
|
-
this.state.subscribersEvents[
|
|
67
|
+
on(e, t) {
|
|
68
|
+
return this.state.subscribersEvents[e].push(t), () => {
|
|
69
|
+
this.state.subscribersEvents[e] = this.state.subscribersEvents[e].filter((s) => s !== t);
|
|
75
70
|
};
|
|
76
71
|
}
|
|
77
|
-
off(
|
|
78
|
-
this.state.subscribersEvents[
|
|
72
|
+
off(e, t) {
|
|
73
|
+
this.state.subscribersEvents[e] = this.state.subscribersEvents[e].filter((s) => s !== t);
|
|
79
74
|
}
|
|
80
|
-
copyState(
|
|
81
|
-
return JSON.parse(JSON.stringify(
|
|
75
|
+
copyState(e) {
|
|
76
|
+
return JSON.parse(JSON.stringify(e));
|
|
82
77
|
}
|
|
83
78
|
resetState() {
|
|
84
79
|
this.state = this.copyState(this.stateDefault);
|
|
85
80
|
}
|
|
81
|
+
setRequestSave(e) {
|
|
82
|
+
if ("action" in e.payload) {
|
|
83
|
+
const t = this.state.arrSaveReq.findIndex((s) => s.payload.action === e.payload.action);
|
|
84
|
+
~t ? this.state.arrSaveReq[t] = e : this.state.arrSaveReq.push(e);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
// removeItemRequestSave(action: string) {
|
|
88
|
+
// const newTotalRequestSave = this.state.arrSaveReq.filter((item) => item.payload?.action !== action);
|
|
89
|
+
// this.state.arrSaveReq = newTotalRequestSave
|
|
90
|
+
// }
|
|
91
|
+
getRequestSave() {
|
|
92
|
+
return this.state.arrSaveReq;
|
|
93
|
+
}
|
|
94
|
+
setResponceInReqSave(e) {
|
|
95
|
+
const t = this.getRequestSave(), s = [];
|
|
96
|
+
for (let a = 0; a < t.length; a++) {
|
|
97
|
+
const o = t[a];
|
|
98
|
+
o.payload.action !== e.action ? s.push(o) : o.resolve && o.resolve(e);
|
|
99
|
+
}
|
|
100
|
+
this.state.arrSaveReq = s, console.log("filterArrSaveReq", s);
|
|
101
|
+
}
|
|
86
102
|
}
|
|
87
103
|
export {
|
|
88
|
-
|
|
104
|
+
p as WsApi
|
|
89
105
|
};
|
|
@@ -25,7 +25,15 @@ export interface WsApiStateDefaultI {
|
|
|
25
25
|
}
|
|
26
26
|
export interface WsApiStateSaveDefaultI {
|
|
27
27
|
isRequestArrSaveReq: boolean;
|
|
28
|
-
arrSaveReq:
|
|
28
|
+
arrSaveReq: {
|
|
29
|
+
payload: {
|
|
30
|
+
action: string;
|
|
31
|
+
[key: string]: any;
|
|
32
|
+
};
|
|
33
|
+
reqId: string;
|
|
34
|
+
resolve: any;
|
|
35
|
+
reject: any;
|
|
36
|
+
}[];
|
|
29
37
|
subscribersEvents: SubscribersEvents_P;
|
|
30
38
|
}
|
|
31
39
|
export {};
|