dev-classes 1.3.35 → 1.4.1
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 +2 -20
- package/dist/index.d.ts +0 -1
- package/dist/index.js +12 -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/SocketApi.types.js +0 -1
- 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/README.md
CHANGED
|
@@ -1,24 +1,6 @@
|
|
|
1
1
|
<h3 align="center">SocketApi</h3>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { SocketApi } from 'dev-classes';
|
|
5
|
-
|
|
6
|
-
SocketApi.init({
|
|
7
|
-
url: 'wss://...',
|
|
8
|
-
timeReConnect: 5000,
|
|
9
|
-
numberOfRepit: 5,
|
|
10
|
-
isReConnectNetworkOnline: true
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
SocketApi.on('status', (status) => { console.log('onStatus', status); });
|
|
14
|
-
SocketApi.on('msg', (messages) => { console.log('onMessages', messages); });
|
|
15
|
-
SocketApi.on('reConnect', (status) => { console.log('reConnect', status); });
|
|
16
|
-
SocketApi.on('timeOffReConnect', (data) => { console.log('timeOffReConnect', data); });
|
|
17
|
-
|
|
18
|
-
SocketApi.connect();
|
|
19
|
-
//...
|
|
20
|
-
|
|
21
|
-
```
|
|
2
|
+
### !!! Пакет пепеехал в lib-socket-api !!!
|
|
3
|
+
|
|
22
4
|
<h3 align="center">HTTPSApi</h3>
|
|
23
5
|
|
|
24
6
|
```ts
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ 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
8
|
export * from './classes/Utils/EventSubscribers';
|
|
10
9
|
export * from './classes/Utils/NetworkInformation';
|
package/dist/index.js
CHANGED
|
@@ -3,26 +3,24 @@ import { DateProcessing as m } from "./classes/DateProcessing/DateProcessing.js"
|
|
|
3
3
|
import { DelaysPromise as p } from "./classes/DelaysPromise/DelaysPromise.js";
|
|
4
4
|
import { File as i } from "./classes/File/File.js";
|
|
5
5
|
import { HTTPSApi as s } from "./classes/HTTPSApi/HTTPSApi.js";
|
|
6
|
-
import { Numbers as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { NetworkInformationPC as S } from "./classes/Utils/NetworkInformation/classes/NetworkInformationPC.js";
|
|
6
|
+
import { Numbers as N } from "./classes/Numbers/Numbers.js";
|
|
7
|
+
import { Utils as k } from "./classes/Utils/Utils.js";
|
|
8
|
+
import { EventSubscribers as w } from "./classes/Utils/EventSubscribers/EventSubscribers.js";
|
|
9
|
+
import { NetworkInformation as P } from "./classes/Utils/NetworkInformation/NetworkInformation.js";
|
|
10
|
+
import { NetworkInformationPC as C } from "./classes/Utils/NetworkInformation/classes/NetworkInformationPC.js";
|
|
12
11
|
import { NetworkInformationAbstract as v } from "./classes/Utils/NetworkInformation/classes/types/types.abscruct.js";
|
|
13
|
-
import { NetworkInformationCordova as
|
|
12
|
+
import { NetworkInformationCordova as D } from "./classes/Utils/NetworkInformation/classes/NetworkInformationCordova.js";
|
|
14
13
|
export {
|
|
15
14
|
t as Color,
|
|
16
15
|
m as DateProcessing,
|
|
17
16
|
p as DelaysPromise,
|
|
18
|
-
|
|
17
|
+
w as EventSubscribers,
|
|
19
18
|
i as File,
|
|
20
19
|
s as HTTPSApi,
|
|
21
|
-
|
|
20
|
+
P as NetworkInformation,
|
|
22
21
|
v as NetworkInformationAbstract,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
l as Utils
|
|
22
|
+
D as NetworkInformationCordova,
|
|
23
|
+
C as NetworkInformationPC,
|
|
24
|
+
N as Numbers,
|
|
25
|
+
k as Utils
|
|
28
26
|
};
|
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.1",
|
|
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 +0,0 @@
|
|
|
1
|
-
|
|
@@ -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
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
export interface WsApi_Options_P {
|
|
2
|
-
url: string;
|
|
3
|
-
timeReConnect: number;
|
|
4
|
-
numberOfRepit?: number;
|
|
5
|
-
}
|
|
6
|
-
export type WsApiE_StatusConnect_OR = "pending" | "ready" | "error" | "close" | "disconnect";
|
|
7
|
-
export interface WsApi_Events {
|
|
8
|
-
status(status: WsApiE_StatusConnect_OR): void;
|
|
9
|
-
msg(message: any): void;
|
|
10
|
-
}
|
|
11
|
-
export interface WsApi_StateProps {
|
|
12
|
-
statusConnect: WsApiE_StatusConnect_OR;
|
|
13
|
-
ws: null | WebSocket;
|
|
14
|
-
arrSaveReq: {
|
|
15
|
-
payload: {
|
|
16
|
-
action: string;
|
|
17
|
-
[key: string]: any;
|
|
18
|
-
};
|
|
19
|
-
reqId: string;
|
|
20
|
-
cb: any;
|
|
21
|
-
}[];
|
|
22
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|