dev-classes 1.3.35 → 1.4.10
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/README.md +12 -20
- package/dist/classes/EventSubscribers/EventSubscribers.js +35 -0
- package/dist/classes/HTTPSApi/HTTPSApi.js +2 -1
- package/dist/classes/HTTPSApi/deps/apiRequest/apiRequest.js +61 -61
- package/dist/classes/NetworkStatusTracker/NetworkStatusTracker.d.ts +30 -0
- package/dist/classes/NetworkStatusTracker/NetworkStatusTracker.js +158 -0
- package/dist/classes/NetworkStatusTracker/NetworkStatusTracker.types.d.ts +22 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +14 -14
- package/package.json +10 -2
- package/dist/classes/ControlAppBySocket/ControlAppBySocket.d.ts +0 -3
- package/dist/classes/ControlAppBySocket/ControlAppBySocket.js +0 -8
- package/dist/classes/SocketApi/SocketApi.d.ts +0 -52
- package/dist/classes/SocketApi/SocketApi.js +0 -127
- package/dist/classes/SocketApi/SocketApi.types.d.ts +0 -9
- package/dist/classes/SocketApi/deps/ConfigInfoConnect/ConfigInfoConnect.d.ts +0 -8
- package/dist/classes/SocketApi/deps/ConfigInfoConnect/ConfigInfoConnect.js +0 -16
- package/dist/classes/SocketApi/deps/ConfigInfoConnect/ConfigInfoConnect.types.d.ts +0 -7
- package/dist/classes/SocketApi/deps/ConfigInfoConnect/ConfigInfoConnect.types.js +0 -1
- package/dist/classes/SocketApi/deps/WsApi/WsApi.d.ts +0 -41
- package/dist/classes/SocketApi/deps/WsApi/WsApi.js +0 -116
- package/dist/classes/SocketApi/deps/WsApi/WsApi.types.d.ts +0 -22
- package/dist/classes/SocketApi/deps/WsApi/WsApi.types.js +0 -1
- package/dist/classes/SocketApi/deps/WsApi/index.d.ts +0 -2
- package/dist/classes/SocketApi/deps/WsApi/index.js +0 -4
- package/dist/classes/SocketApi/index.d.ts +0 -2
- package/dist/classes/SocketApi/index.js +0 -4
- package/dist/classes/Utils/EventSubscribers/EventSubscribers.js +0 -33
- /package/dist/classes/{Utils/EventSubscribers → EventSubscribers}/EventSubscribers.d.ts +0 -0
- /package/dist/classes/{Utils/EventSubscribers → EventSubscribers}/EventSubscribers.types.d.ts +0 -0
- /package/dist/classes/{Utils/EventSubscribers → EventSubscribers}/EventSubscribers.types.js +0 -0
- /package/dist/classes/{Utils/EventSubscribers → EventSubscribers}/index.d.ts +0 -0
- /package/dist/classes/{Utils/EventSubscribers → EventSubscribers}/index.js +0 -0
- /package/dist/classes/{SocketApi/SocketApi.types.js → NetworkStatusTracker/NetworkStatusTracker.types.js} +0 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
var v = Object.defineProperty;
|
|
2
|
+
var d = (r, t, e) => t in r ? v(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
|
|
3
|
+
var s = (r, t, e) => (d(r, typeof t != "symbol" ? t + "" : t, e), e);
|
|
4
|
+
class p {
|
|
5
|
+
constructor(t) {
|
|
6
|
+
s(this, "networkInfo");
|
|
7
|
+
s(this, "listUrls", []);
|
|
8
|
+
s(this, "state", {
|
|
9
|
+
isActiveEvents: !1,
|
|
10
|
+
isMonitoring: !1,
|
|
11
|
+
checkIntervalId: null
|
|
12
|
+
});
|
|
13
|
+
s(this, "getFetchOptions", (t) => ({
|
|
14
|
+
method: "HEAD",
|
|
15
|
+
cache: "no-store",
|
|
16
|
+
signal: t.signal,
|
|
17
|
+
headers: {
|
|
18
|
+
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
19
|
+
Pragma: "no-cache",
|
|
20
|
+
Expires: "0"
|
|
21
|
+
}
|
|
22
|
+
}));
|
|
23
|
+
s(this, "getIsNetwork", (t) => !["unknown", "none"].includes(t));
|
|
24
|
+
s(this, "getTypeNetwork", ({ effectiveType: t, type: e }, n) => (n || n === null) && (t || e) || "none");
|
|
25
|
+
/*-----------------------------------------------------------------------------*/
|
|
26
|
+
s(this, "controllersEvents", {
|
|
27
|
+
online: null,
|
|
28
|
+
offline: null,
|
|
29
|
+
change: null
|
|
30
|
+
});
|
|
31
|
+
s(this, "controllersFetching", {
|
|
32
|
+
online: null,
|
|
33
|
+
offline: null,
|
|
34
|
+
change: null
|
|
35
|
+
});
|
|
36
|
+
this.listUrls = t;
|
|
37
|
+
const e = typeof navigator < "u" ? navigator.onLine : !1;
|
|
38
|
+
this.networkInfo = {
|
|
39
|
+
isNetwork: e,
|
|
40
|
+
typeNetwork: this.getTypeNetwork(this.getConnection(), e)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
setState(t) {
|
|
44
|
+
this.state = { ...this.state, ...t };
|
|
45
|
+
}
|
|
46
|
+
getState() {
|
|
47
|
+
return this.state;
|
|
48
|
+
}
|
|
49
|
+
getConnection() {
|
|
50
|
+
var t;
|
|
51
|
+
return (t = window == null ? void 0 : window.navigator) == null ? void 0 : t.connection;
|
|
52
|
+
}
|
|
53
|
+
updateState(t, e) {
|
|
54
|
+
const n = {
|
|
55
|
+
isNetwork: t,
|
|
56
|
+
typeNetwork: this.getTypeNetwork(this.getConnection(), t)
|
|
57
|
+
};
|
|
58
|
+
this.networkInfo = n, typeof e == "function" && e(n);
|
|
59
|
+
}
|
|
60
|
+
getControllersEvents() {
|
|
61
|
+
return this.controllersEvents;
|
|
62
|
+
}
|
|
63
|
+
setControllersEvents(t) {
|
|
64
|
+
this.controllersEvents = { ...this.controllersEvents, ...t };
|
|
65
|
+
}
|
|
66
|
+
startEvents(t) {
|
|
67
|
+
var l, c, a, h;
|
|
68
|
+
const { isActiveEvents: e } = this.getState();
|
|
69
|
+
if (e)
|
|
70
|
+
return;
|
|
71
|
+
this.setState({ isActiveEvents: !0 });
|
|
72
|
+
const n = {
|
|
73
|
+
online: new AbortController(),
|
|
74
|
+
offline: new AbortController(),
|
|
75
|
+
change: new AbortController()
|
|
76
|
+
};
|
|
77
|
+
this.setControllersEvents(n);
|
|
78
|
+
const o = this.getConnection(), i = this.getTypeNetwork(o, window.navigator.onLine), g = this.getIsNetwork(i);
|
|
79
|
+
this.updateState(g, t), window.addEventListener("online", () => {
|
|
80
|
+
this.updateState(!0, t);
|
|
81
|
+
}, { signal: (l = n.online) == null ? void 0 : l.signal }), window.addEventListener("offline", () => {
|
|
82
|
+
this.updateState(!1, t);
|
|
83
|
+
}, { signal: (c = n.offline) == null ? void 0 : c.signal }), (a = this.getConnection()) != null && a.addEventListener && this.getConnection().addEventListener("change", () => {
|
|
84
|
+
const u = this.getConnection(), w = this.getTypeNetwork(u, null), f = this.getIsNetwork(w);
|
|
85
|
+
this.updateState(f, t);
|
|
86
|
+
}, { signal: (h = n.change) == null ? void 0 : h.signal });
|
|
87
|
+
}
|
|
88
|
+
stopEvents() {
|
|
89
|
+
const { isActiveEvents: t } = this.getState();
|
|
90
|
+
if (t) {
|
|
91
|
+
this.setState({ isActiveEvents: !1 });
|
|
92
|
+
const e = this.getControllersEvents();
|
|
93
|
+
for (const n of Object.values(e))
|
|
94
|
+
n == null || n.abort();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/*-----------------------------------------------------------------------------*/
|
|
98
|
+
async requestByUrls(t, e) {
|
|
99
|
+
const n = await this.checkConnection(e);
|
|
100
|
+
this.updateState(n, t);
|
|
101
|
+
}
|
|
102
|
+
async checkConnection(t = {}) {
|
|
103
|
+
for (const e of this.listUrls)
|
|
104
|
+
try {
|
|
105
|
+
const n = new AbortController(), o = setTimeout(() => n.abort(), (t == null ? void 0 : t.timeout) || 5e3), i = await window.fetch(e);
|
|
106
|
+
if (clearTimeout(o), i.status >= 200 && i.status < 400)
|
|
107
|
+
return !0;
|
|
108
|
+
} catch {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
return !1;
|
|
112
|
+
}
|
|
113
|
+
getControllersMonitoring() {
|
|
114
|
+
return this.controllersFetching;
|
|
115
|
+
}
|
|
116
|
+
setControllersMonitoring(t) {
|
|
117
|
+
this.controllersFetching = { ...this.controllersFetching, ...t };
|
|
118
|
+
}
|
|
119
|
+
startFetching(t, { interval: e = 5e3 }) {
|
|
120
|
+
const { isMonitoring: n } = this.getState();
|
|
121
|
+
if (n)
|
|
122
|
+
return;
|
|
123
|
+
this.setState({ isMonitoring: !0 });
|
|
124
|
+
const o = {
|
|
125
|
+
online: new AbortController(),
|
|
126
|
+
offline: new AbortController(),
|
|
127
|
+
change: new AbortController()
|
|
128
|
+
};
|
|
129
|
+
this.setControllersMonitoring(o), this.requestByUrls(t, { timeout: 2e3 });
|
|
130
|
+
const i = window.setInterval(() => this.requestByUrls(t), e);
|
|
131
|
+
this.setState({ checkIntervalId: i });
|
|
132
|
+
}
|
|
133
|
+
stopFetching() {
|
|
134
|
+
const { isMonitoring: t, checkIntervalId: e } = this.getState();
|
|
135
|
+
if (!t)
|
|
136
|
+
return;
|
|
137
|
+
const n = this.getControllersMonitoring();
|
|
138
|
+
for (const o of Object.values(n))
|
|
139
|
+
o == null || o.abort();
|
|
140
|
+
e && clearInterval(e), this.setState({ isMonitoring: !1, checkIntervalId: null });
|
|
141
|
+
}
|
|
142
|
+
/*--------------------------------------------------------------------------------------------------*/
|
|
143
|
+
/*--------------------------------------------------------------------------------------------------*/
|
|
144
|
+
async checkStatus(t, e) {
|
|
145
|
+
return await this.requestByUrls(t), this.getCurrentState();
|
|
146
|
+
}
|
|
147
|
+
fetchingNetwork(t, e) {
|
|
148
|
+
return this.startFetching(t, e), {
|
|
149
|
+
stop: () => this.stopFetching()
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
getCurrentState() {
|
|
153
|
+
return this.networkInfo;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
export {
|
|
157
|
+
p as NetworkStatusTracker
|
|
158
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface NetworkInfoConnection {
|
|
2
|
+
downlink?: number;
|
|
3
|
+
effectiveType?: string;
|
|
4
|
+
rtt?: number;
|
|
5
|
+
saveData?: boolean;
|
|
6
|
+
type?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface NetworkStatusInfoTracker {
|
|
9
|
+
isNetwork: boolean;
|
|
10
|
+
typeNetwork: string;
|
|
11
|
+
}
|
|
12
|
+
export interface NetworkStatusConfig {
|
|
13
|
+
interval?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface NetworkConstructorConfig {
|
|
16
|
+
timeout?: number;
|
|
17
|
+
}
|
|
18
|
+
export type OnStatusChange = (info: NetworkStatusInfoTracker) => void;
|
|
19
|
+
export interface NetworkItemListTracker {
|
|
20
|
+
keyNameSystem: string;
|
|
21
|
+
getInfo: () => NetworkStatusInfoTracker;
|
|
22
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export * from './classes/DelaysPromise';
|
|
|
4
4
|
export * from './classes/File';
|
|
5
5
|
export * from './classes/HTTPSApi';
|
|
6
6
|
export * from './classes/Numbers';
|
|
7
|
-
export * from './classes/SocketApi';
|
|
8
7
|
export * from './classes/Utils/Utils';
|
|
9
|
-
export * from './classes/
|
|
8
|
+
export * from './classes/EventSubscribers';
|
|
9
|
+
export * from './classes/NetworkStatusTracker/NetworkStatusTracker';
|
|
10
10
|
export * from './classes/Utils/NetworkInformation';
|
package/dist/index.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { Color as t } from "./classes/Color/Color.js";
|
|
2
2
|
import { DateProcessing as m } from "./classes/DateProcessing/DateProcessing.js";
|
|
3
3
|
import { DelaysPromise as p } from "./classes/DelaysPromise/DelaysPromise.js";
|
|
4
|
-
import { File as
|
|
5
|
-
import { HTTPSApi as
|
|
4
|
+
import { File as a } from "./classes/File/File.js";
|
|
5
|
+
import { HTTPSApi as n } from "./classes/HTTPSApi/HTTPSApi.js";
|
|
6
6
|
import { Numbers as k } from "./classes/Numbers/Numbers.js";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { NetworkInformation as
|
|
7
|
+
import { Utils as w } from "./classes/Utils/Utils.js";
|
|
8
|
+
import { EventSubscribers as c } from "./classes/EventSubscribers/EventSubscribers.js";
|
|
9
|
+
import { NetworkStatusTracker as I } from "./classes/NetworkStatusTracker/NetworkStatusTracker.js";
|
|
10
|
+
import { NetworkInformation as u } from "./classes/Utils/NetworkInformation/NetworkInformation.js";
|
|
11
11
|
import { NetworkInformationPC as S } from "./classes/Utils/NetworkInformation/classes/NetworkInformationPC.js";
|
|
12
12
|
import { NetworkInformationAbstract as v } from "./classes/Utils/NetworkInformation/classes/types/types.abscruct.js";
|
|
13
|
-
import { NetworkInformationCordova as
|
|
13
|
+
import { NetworkInformationCordova as D } from "./classes/Utils/NetworkInformation/classes/NetworkInformationCordova.js";
|
|
14
14
|
export {
|
|
15
15
|
t as Color,
|
|
16
16
|
m as DateProcessing,
|
|
17
17
|
p as DelaysPromise,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
c as EventSubscribers,
|
|
19
|
+
a as File,
|
|
20
|
+
n as HTTPSApi,
|
|
21
|
+
u as NetworkInformation,
|
|
22
22
|
v as NetworkInformationAbstract,
|
|
23
|
-
|
|
23
|
+
D as NetworkInformationCordova,
|
|
24
24
|
S as NetworkInformationPC,
|
|
25
|
+
I as NetworkStatusTracker,
|
|
25
26
|
k as Numbers,
|
|
26
|
-
|
|
27
|
-
l as Utils
|
|
27
|
+
w as Utils
|
|
28
28
|
};
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "git+https://github.com/SinGlEBW/dev-classes.git"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
|
-
"version": "1.
|
|
14
|
+
"version": "1.4.10",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"module": "./dist/index.js",
|
|
17
17
|
"main": "./dist/index.js",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
},
|
|
25
25
|
"keywords": [
|
|
26
26
|
"dev-classes",
|
|
27
|
-
"SocketApi",
|
|
28
27
|
"EventSubscribers",
|
|
29
28
|
"NetworkInformation",
|
|
30
29
|
"HTTPSApi",
|
|
@@ -44,6 +43,7 @@
|
|
|
44
43
|
"devDependencies": {
|
|
45
44
|
"@types/js-cookie": "^3.0.6",
|
|
46
45
|
"@types/node": "^20.12.7",
|
|
46
|
+
"@types/react": "^18.3.23",
|
|
47
47
|
"glob": "^10.3.12",
|
|
48
48
|
"typescript": "^5.2.2",
|
|
49
49
|
"vite": "^5.1.6",
|
|
@@ -54,5 +54,13 @@
|
|
|
54
54
|
"axios": "^1.7.7",
|
|
55
55
|
"js-cookie": "^3.0.5",
|
|
56
56
|
"uuid4": "^2.0.3"
|
|
57
|
+
},
|
|
58
|
+
"peerDependencies": {
|
|
59
|
+
"@emotion/react": "^11.11.4",
|
|
60
|
+
"@emotion/styled": "^11.11.0",
|
|
61
|
+
"@mui/icons-material": "^5.15.14",
|
|
62
|
+
"@mui/material": "^5.15.14",
|
|
63
|
+
"classnames": "^2.5.1",
|
|
64
|
+
"react": "^18.2.0"
|
|
57
65
|
}
|
|
58
66
|
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { WsApi_Events } from './deps/WsApi/WsApi.types';
|
|
2
|
-
import { WsApi_Options_P } from './deps/WsApi';
|
|
3
|
-
import { SocketApi_Options_P, SocketApi_StateProps_P } from './SocketApi.types';
|
|
4
|
-
|
|
5
|
-
interface SocketApi_Events {
|
|
6
|
-
timeOffReConnect(info: {
|
|
7
|
-
status: boolean;
|
|
8
|
-
msg: string;
|
|
9
|
-
}): void;
|
|
10
|
-
reConnect(status: boolean): void;
|
|
11
|
-
}
|
|
12
|
-
type CommonEvents = SocketApi_Events & WsApi_Events;
|
|
13
|
-
export declare class SocketApi {
|
|
14
|
-
#private;
|
|
15
|
-
private static state;
|
|
16
|
-
private static options;
|
|
17
|
-
private static wsApi;
|
|
18
|
-
private static delay;
|
|
19
|
-
private static internet;
|
|
20
|
-
private static events;
|
|
21
|
-
private static saveID;
|
|
22
|
-
private static stateDefault;
|
|
23
|
-
private static copyState;
|
|
24
|
-
private static setState;
|
|
25
|
-
private static resetState;
|
|
26
|
-
private static setOptions;
|
|
27
|
-
private static setStatusReConnect;
|
|
28
|
-
private static setInfoConnect;
|
|
29
|
-
private static online;
|
|
30
|
-
private static offline;
|
|
31
|
-
private static splitOptions;
|
|
32
|
-
static getState: () => SocketApi_StateProps_P;
|
|
33
|
-
static on: <K extends keyof CommonEvents>(name: K, cb: CommonEvents[K]) => void;
|
|
34
|
-
static off: typeof SocketApi.wsApi.on & typeof SocketApi.events.subscribe;
|
|
35
|
-
static getRequestSave: () => {
|
|
36
|
-
payload: {
|
|
37
|
-
[key: string]: any;
|
|
38
|
-
action: string;
|
|
39
|
-
};
|
|
40
|
-
reqId: string;
|
|
41
|
-
cb: any;
|
|
42
|
-
}[];
|
|
43
|
-
static getStatusSocket: () => import('./deps/WsApi').WsApiE_StatusConnect_OR;
|
|
44
|
-
static close: () => void;
|
|
45
|
-
static init: (options: WsApi_Options_P & SocketApi_Options_P) => void;
|
|
46
|
-
static connect(): void;
|
|
47
|
-
static disconnect(): void;
|
|
48
|
-
static send<ResType>(data: object, cb?: (data: ResType) => void): void;
|
|
49
|
-
static stopReConnect(status?: boolean): void;
|
|
50
|
-
static socketReConnect: () => void;
|
|
51
|
-
}
|
|
52
|
-
export {};
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
var w = Object.defineProperty;
|
|
2
|
-
var C = (o, e, s) => e in o ? w(o, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : o[e] = s;
|
|
3
|
-
var n = (o, e, s) => (C(o, typeof e != "symbol" ? e + "" : e, s), s);
|
|
4
|
-
var f = (o, e, s) => {
|
|
5
|
-
if (e.has(o))
|
|
6
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
7
|
-
e instanceof WeakSet ? e.add(o) : e.set(o, s);
|
|
8
|
-
};
|
|
9
|
-
import { DelaysPromise as R } from "../DelaysPromise/DelaysPromise.js";
|
|
10
|
-
import { NetworkInformationCordova as v } from "../Utils/NetworkInformation/classes/NetworkInformationCordova.js";
|
|
11
|
-
import { NetworkInformationPC as d } from "../Utils/NetworkInformation/classes/NetworkInformationPC.js";
|
|
12
|
-
import { EventSubscribers as g } from "../Utils/EventSubscribers/EventSubscribers.js";
|
|
13
|
-
import { NetworkInformation as O } from "../Utils/NetworkInformation/NetworkInformation.js";
|
|
14
|
-
import { WsApi as S } from "./deps/WsApi/WsApi.js";
|
|
15
|
-
const I = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
|
16
|
-
function m(o) {
|
|
17
|
-
return I.test(o);
|
|
18
|
-
}
|
|
19
|
-
function u() {
|
|
20
|
-
var o = URL.createObjectURL(new Blob()), e = o.toString();
|
|
21
|
-
return URL.revokeObjectURL(o), e.split(/[:\/]/g).pop().toLowerCase();
|
|
22
|
-
}
|
|
23
|
-
u.valid = m;
|
|
24
|
-
var r, A;
|
|
25
|
-
const t = class t {
|
|
26
|
-
static copyState(e) {
|
|
27
|
-
return JSON.parse(JSON.stringify(e));
|
|
28
|
-
}
|
|
29
|
-
static setState(e) {
|
|
30
|
-
t.state = { ...t.state, ...e };
|
|
31
|
-
}
|
|
32
|
-
static resetState() {
|
|
33
|
-
t.state = t.copyState(t.stateDefault);
|
|
34
|
-
}
|
|
35
|
-
static setOptions(e) {
|
|
36
|
-
t.options = { ...t.options, ...e };
|
|
37
|
-
}
|
|
38
|
-
static setStatusReConnect(e) {
|
|
39
|
-
t.setState({ isActiveReConnect: e }), t.events.publish("reConnect", e);
|
|
40
|
-
}
|
|
41
|
-
static connect() {
|
|
42
|
-
t.wsApi.getIsInitWS() && (console.log("CONNECT WS"), t.setState({ isDisconnect: !1 }), t.wsApi.connect());
|
|
43
|
-
}
|
|
44
|
-
static disconnect() {
|
|
45
|
-
t.state.isDisconnect || (t.setState({ isDisconnect: !0 }), console.log("DISCONNECT WS"), t.wsApi.disconnect(), t.resetState());
|
|
46
|
-
}
|
|
47
|
-
static send(e, s) {
|
|
48
|
-
const { action: i, ...c } = e, a = u();
|
|
49
|
-
t.wsApi.setRequestSave({
|
|
50
|
-
reqId: a,
|
|
51
|
-
payload: { action: i, ...c },
|
|
52
|
-
cb: s
|
|
53
|
-
});
|
|
54
|
-
const l = t.wsApi.getSocket();
|
|
55
|
-
if (!l || l.readyState !== 1) {
|
|
56
|
-
console.log("Нет подключения к сокету");
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
t.wsApi.send(e);
|
|
60
|
-
}
|
|
61
|
-
static stopReConnect(e) {
|
|
62
|
-
console.dir("функция stop не присвоена к stopReConnect");
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
r = new WeakSet(), A = function() {
|
|
66
|
-
}, f(t, r), n(t, "state", {
|
|
67
|
-
isDisconnect: !0,
|
|
68
|
-
isActiveReConnect: !1,
|
|
69
|
-
isOfflineSocket: !0,
|
|
70
|
-
isReady: !1,
|
|
71
|
-
isNetworkStatus: navigator.onLine
|
|
72
|
-
}), n(t, "options", {
|
|
73
|
-
isReConnectNetworkOnline: !1
|
|
74
|
-
}), n(t, "wsApi", new S()), n(t, "delay", new R()), n(t, "internet", new O([new d(), new v()])), n(t, "events", new g(["timeOffReConnect", "reConnect"])), n(t, "saveID", {
|
|
75
|
-
idReConnect: null,
|
|
76
|
-
checkConnect: null
|
|
77
|
-
}), n(t, "stateDefault", t.copyState(t.state)), n(t, "setInfoConnect", (e) => {
|
|
78
|
-
e.status || t.close(), t.setState({ isOfflineSocket: !e.status }), t.events.publish("timeOffReConnect", e), t.setStatusReConnect(!1);
|
|
79
|
-
}), n(t, "online", () => {
|
|
80
|
-
t.setState({ isNetworkStatus: !0 }), !t.state.isActiveReConnect && t.options.isReConnectNetworkOnline && t.socketReConnect();
|
|
81
|
-
}), n(t, "offline", () => {
|
|
82
|
-
t.setState({ isNetworkStatus: !1 }), t.state.isActiveReConnect && t.stopReConnect(!1);
|
|
83
|
-
}), n(t, "splitOptions", (e) => Object.entries(e).reduce(
|
|
84
|
-
(s, [i, c]) => {
|
|
85
|
-
const a = t.wsApi.getOptions();
|
|
86
|
-
return i in a ? { ...s, WsOptions: { ...s.WsOptions, [i]: c } } : { ...s, SocketApiOptions: { ...s.SocketApiOptions, [i]: c } };
|
|
87
|
-
},
|
|
88
|
-
{ WsOptions: {}, SocketApiOptions: {} }
|
|
89
|
-
)), /*---------------------------------------------------------------------------------------------------------------------------*/
|
|
90
|
-
n(t, "getState", () => t.state), n(t, "on", (e, s) => {
|
|
91
|
-
t.wsApi.getRegisteredEvents().includes(e) ? t.wsApi.on(e, s) : t.events.subscribe(e, s);
|
|
92
|
-
}), n(t, "off", (e, s) => {
|
|
93
|
-
t.wsApi.getRegisteredEvents().includes(e) ? t.wsApi.off(e, s) : t.events.unsubscribe(e, s);
|
|
94
|
-
}), n(t, "getRequestSave", t.wsApi.getRequestSave), n(t, "getStatusSocket", t.wsApi.getStatusSocket), n(t, "close", () => {
|
|
95
|
-
t.state.isActiveReConnect ? t.stopReConnect(!1) : t.wsApi.close();
|
|
96
|
-
}), n(t, "init", (e) => {
|
|
97
|
-
const { WsOptions: s, SocketApiOptions: i } = t.splitOptions(e);
|
|
98
|
-
t.internet.run((c) => {
|
|
99
|
-
c ? t.online() : t.offline();
|
|
100
|
-
}), t.setOptions(i), t.wsApi.init(s);
|
|
101
|
-
}), /*------------------------------------------------------------------------------------------------------*/
|
|
102
|
-
n(t, "socketReConnect", () => {
|
|
103
|
-
if (t.wsApi.getIsInitWS())
|
|
104
|
-
if (console.log("reconnect"), t.saveID.idReConnect)
|
|
105
|
-
console.groupCollapsed("Процесс socketReConnect уже запущен"), console.log("SocketApi.saveID: ", t.saveID), console.groupEnd();
|
|
106
|
-
else {
|
|
107
|
-
t.setStatusReConnect(!0), t.connect();
|
|
108
|
-
const { timeReConnect: e, numberOfRepit: s } = t.wsApi.getOptions();
|
|
109
|
-
t.delay.startActionEvery(
|
|
110
|
-
() => (console.log("reconnect:>>delay"), t.wsApi.getStatusSocket() === "ready" ? (console.dir("Подключение установлено"), !0) : (t.connect(), !1)),
|
|
111
|
-
{
|
|
112
|
-
interval: e,
|
|
113
|
-
countAction: s,
|
|
114
|
-
watchIdInterval: (c) => {
|
|
115
|
-
t.saveID.idReConnect = c;
|
|
116
|
-
},
|
|
117
|
-
controlAction: ({ stop: c, getIsActiveEvent: a }) => {
|
|
118
|
-
t.stopReConnect = c;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
).promise.then(t.setInfoConnect).catch(t.setInfoConnect);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
let p = t;
|
|
125
|
-
export {
|
|
126
|
-
p as SocketApi
|
|
127
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { WsApiE_StatusConnect_OR } from './deps/WsApi';
|
|
2
|
-
|
|
3
|
-
export interface SocketApi_Options_P {
|
|
4
|
-
isReConnectNetworkOnline?: boolean;
|
|
5
|
-
}
|
|
6
|
-
type SocketApi_StateProps_OR = 'isDisconnect' | 'isActiveReConnect' | 'isOfflineSocket' | 'isReady' | 'isNetworkStatus';
|
|
7
|
-
export type SocketApi_StateProps_P = Record<SocketApi_StateProps_OR, boolean>;
|
|
8
|
-
export type SocketApi_StatusConnect_OR = WsApiE_StatusConnect_OR;
|
|
9
|
-
export {};
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ConfigInfoConnectI, OptionsConditionReConnect } from './ConfigInfoConnect.types';
|
|
2
|
-
|
|
3
|
-
export declare class ConfigInfoConnect implements ConfigInfoConnectI {
|
|
4
|
-
options: {
|
|
5
|
-
stop: boolean;
|
|
6
|
-
};
|
|
7
|
-
setConditionReConnect: (options: Partial<OptionsConditionReConnect>) => void;
|
|
8
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
var i = Object.defineProperty;
|
|
2
|
-
var e = (n, o, t) => o in n ? i(n, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[o] = t;
|
|
3
|
-
var s = (n, o, t) => (e(n, typeof o != "symbol" ? o + "" : o, t), t);
|
|
4
|
-
class C {
|
|
5
|
-
constructor() {
|
|
6
|
-
s(this, "options", {
|
|
7
|
-
stop: !1
|
|
8
|
-
});
|
|
9
|
-
s(this, "setConditionReConnect", (o) => {
|
|
10
|
-
this.options = { ...this.options, ...o };
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export {
|
|
15
|
-
C as ConfigInfoConnect
|
|
16
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { WsApi_Events, WsApi_Options_P, WsApiE_StatusConnect_OR } from './WsApi.types';
|
|
2
|
-
|
|
3
|
-
export declare class WsApi {
|
|
4
|
-
private options;
|
|
5
|
-
private state;
|
|
6
|
-
private initOptions;
|
|
7
|
-
private events;
|
|
8
|
-
private stateDefault;
|
|
9
|
-
private resetState;
|
|
10
|
-
private setState;
|
|
11
|
-
private eventListener;
|
|
12
|
-
private openHandler;
|
|
13
|
-
private closeHandler;
|
|
14
|
-
private msgHandler;
|
|
15
|
-
private errHandler;
|
|
16
|
-
private copyState;
|
|
17
|
-
private filterSaveItemsByResponse;
|
|
18
|
-
private errorInitSocket;
|
|
19
|
-
private setStatus;
|
|
20
|
-
getSocket: () => WebSocket | null;
|
|
21
|
-
getStatusSocket: () => WsApiE_StatusConnect_OR;
|
|
22
|
-
getRequestSave: () => {
|
|
23
|
-
payload: {
|
|
24
|
-
[key: string]: any;
|
|
25
|
-
action: string;
|
|
26
|
-
};
|
|
27
|
-
reqId: string;
|
|
28
|
-
cb: any;
|
|
29
|
-
}[];
|
|
30
|
-
getOptions: () => WsApi_Options_P;
|
|
31
|
-
getRegisteredEvents: () => string[];
|
|
32
|
-
on: <K extends keyof WsApi_Events>(name: K, cb: WsApi_Events[K]) => void;
|
|
33
|
-
off: <K extends keyof WsApi_Events>(name: K, cb: WsApi_Events[K]) => void;
|
|
34
|
-
init: (options: typeof this.options) => void;
|
|
35
|
-
getIsInitWS: () => boolean;
|
|
36
|
-
connect(): void;
|
|
37
|
-
close(): void;
|
|
38
|
-
disconnect(): void;
|
|
39
|
-
send(data: any): void;
|
|
40
|
-
setRequestSave(reqInfo: (typeof this.state.arrSaveReq)[number]): void;
|
|
41
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
var c = Object.defineProperty;
|
|
2
|
-
var l = (a, t, s) => t in a ? c(a, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : a[t] = s;
|
|
3
|
-
var e = (a, t, s) => (l(a, typeof t != "symbol" ? t + "" : t, s), s);
|
|
4
|
-
import { EventSubscribers as S } from "../../../Utils/EventSubscribers/EventSubscribers.js";
|
|
5
|
-
class d {
|
|
6
|
-
constructor() {
|
|
7
|
-
e(this, "options", {
|
|
8
|
-
timeReConnect: 5e3,
|
|
9
|
-
numberOfRepit: 5,
|
|
10
|
-
url: ""
|
|
11
|
-
});
|
|
12
|
-
e(this, "state", {
|
|
13
|
-
statusConnect: "disconnect",
|
|
14
|
-
ws: null,
|
|
15
|
-
arrSaveReq: []
|
|
16
|
-
});
|
|
17
|
-
e(this, "initOptions", !1);
|
|
18
|
-
e(this, "events", new S(["status", "msg"]));
|
|
19
|
-
e(this, "stateDefault", this.copyState(this.state));
|
|
20
|
-
e(this, "eventListener", (t) => {
|
|
21
|
-
var i, r;
|
|
22
|
-
const s = [
|
|
23
|
-
["open", this.openHandler],
|
|
24
|
-
["close", this.closeHandler],
|
|
25
|
-
["message", this.msgHandler],
|
|
26
|
-
["error", this.errHandler]
|
|
27
|
-
];
|
|
28
|
-
for (let n = 0; n < s.length; n++) {
|
|
29
|
-
const [o, h] = s[n];
|
|
30
|
-
t === "add" ? (i = this.state.ws) == null || i.addEventListener(o, h) : (r = this.state.ws) == null || r.removeEventListener(o, h);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
e(this, "openHandler", () => {
|
|
34
|
-
this.setStatus("ready");
|
|
35
|
-
});
|
|
36
|
-
e(this, "closeHandler", () => {
|
|
37
|
-
this.setStatus("close");
|
|
38
|
-
});
|
|
39
|
-
e(this, "msgHandler", (t) => {
|
|
40
|
-
const s = JSON.parse(t.data ? t.data : "{}");
|
|
41
|
-
try {
|
|
42
|
-
const { action: i } = s;
|
|
43
|
-
i && this.filterSaveItemsByResponse(s), this.events.publish("msg", s);
|
|
44
|
-
} catch {
|
|
45
|
-
this.events.publish("msg", JSON.parse("{}"));
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
e(this, "errHandler", (t) => {
|
|
49
|
-
console.log("errHandler", t), this.setStatus("error");
|
|
50
|
-
});
|
|
51
|
-
e(this, "errorInitSocket", () => {
|
|
52
|
-
console.error("Вы не установили опции");
|
|
53
|
-
});
|
|
54
|
-
e(this, "setStatus", (t) => {
|
|
55
|
-
this.events.publish("status", t), this.setState({ statusConnect: t });
|
|
56
|
-
});
|
|
57
|
-
/*----------------------------------------------------------------------------------------------------------*/
|
|
58
|
-
e(this, "getSocket", () => this.state.ws);
|
|
59
|
-
e(this, "getStatusSocket", () => this.state.statusConnect);
|
|
60
|
-
e(this, "getRequestSave", () => this.state.arrSaveReq);
|
|
61
|
-
e(this, "getOptions", () => this.options);
|
|
62
|
-
e(this, "getRegisteredEvents", this.events.getListNameEvents);
|
|
63
|
-
e(this, "on", this.events.subscribe);
|
|
64
|
-
e(this, "off", this.events.unsubscribe);
|
|
65
|
-
e(this, "init", (t) => {
|
|
66
|
-
this.initOptions = !0, this.options = { ...this.options, ...t };
|
|
67
|
-
});
|
|
68
|
-
e(this, "getIsInitWS", () => {
|
|
69
|
-
const t = this.initOptions;
|
|
70
|
-
return t || this.errorInitSocket(), t;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
resetState() {
|
|
74
|
-
this.state = this.copyState(this.stateDefault);
|
|
75
|
-
}
|
|
76
|
-
setState(t) {
|
|
77
|
-
this.state = { ...this.state, ...t };
|
|
78
|
-
}
|
|
79
|
-
copyState(t) {
|
|
80
|
-
return JSON.parse(JSON.stringify(t));
|
|
81
|
-
}
|
|
82
|
-
filterSaveItemsByResponse(t) {
|
|
83
|
-
const s = this.getRequestSave(), i = [];
|
|
84
|
-
for (let r = 0; r < s.length; r++) {
|
|
85
|
-
const n = s[r];
|
|
86
|
-
n.payload.action !== t.action ? i.push(n) : n.cb && n.cb(t);
|
|
87
|
-
}
|
|
88
|
-
this.state.arrSaveReq = i;
|
|
89
|
-
}
|
|
90
|
-
connect() {
|
|
91
|
-
this.initOptions && (this.close(), this.setState({
|
|
92
|
-
ws: new WebSocket(this.options.url)
|
|
93
|
-
}), this.setStatus("pending"), this.eventListener("add"));
|
|
94
|
-
}
|
|
95
|
-
close() {
|
|
96
|
-
var t;
|
|
97
|
-
(t = this.state.ws) == null || t.close(), this.eventListener("remove"), this.setStatus("close");
|
|
98
|
-
}
|
|
99
|
-
disconnect() {
|
|
100
|
-
this.close(), this.resetState();
|
|
101
|
-
}
|
|
102
|
-
send(t) {
|
|
103
|
-
var i;
|
|
104
|
-
const s = JSON.stringify(t);
|
|
105
|
-
(i = this.state.ws) == null || i.send(s);
|
|
106
|
-
}
|
|
107
|
-
setRequestSave(t) {
|
|
108
|
-
if ("action" in t.payload) {
|
|
109
|
-
const s = this.state.arrSaveReq.findIndex((i) => i.payload.action === t.payload.action);
|
|
110
|
-
~s ? this.state.arrSaveReq[s] = t : this.state.arrSaveReq.push(t);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
export {
|
|
115
|
-
d as WsApi
|
|
116
|
-
};
|