@dooboostore/simple-boot-http-server 1.0.23 → 1.0.24
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 +27 -1
- package/dist/cjs/SimpleBootHttpServer.js +79 -39
- package/dist/cjs/SimpleBootHttpServer.js.map +3 -3
- package/dist/cjs/codes/HttpHeaders.js +14 -3
- package/dist/cjs/codes/HttpHeaders.js.map +2 -2
- package/dist/cjs/codes/Mimes.js +2 -0
- package/dist/cjs/codes/Mimes.js.map +2 -2
- package/dist/cjs/decorators/MethodMapping.js +7 -6
- package/dist/cjs/decorators/MethodMapping.js.map +3 -3
- package/dist/cjs/endpoints/WebSocketEndPoint.js +16 -0
- package/dist/cjs/endpoints/WebSocketEndPoint.js.map +7 -0
- package/dist/cjs/filters/CacheFilter.js +75 -35
- package/dist/cjs/filters/CacheFilter.js.map +3 -3
- package/dist/cjs/filters/IntentSchemeFilter.js +98 -0
- package/dist/cjs/filters/IntentSchemeFilter.js.map +7 -0
- package/dist/cjs/filters/ResourceFilter.js +4 -1
- package/dist/cjs/filters/ResourceFilter.js.map +2 -2
- package/dist/cjs/filters/TopicProtocolFilter.js +343 -0
- package/dist/cjs/filters/TopicProtocolFilter.js.map +7 -0
- package/dist/cjs/filters/index.js +2 -0
- package/dist/cjs/filters/index.js.map +2 -2
- package/dist/cjs/index.js +28 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/models/RequestResponse.js +51 -89
- package/dist/cjs/models/RequestResponse.js.map +3 -3
- package/dist/cjs/models/datas/body/ReqPathData.js +29 -0
- package/dist/cjs/models/datas/body/ReqPathData.js.map +7 -0
- package/dist/cjs/option/HttpServerOption.js +25 -5
- package/dist/cjs/option/HttpServerOption.js.map +2 -2
- package/dist/cjs/proxy/SymbolIntentApiServiceProxy.js +141 -0
- package/dist/cjs/proxy/SymbolIntentApiServiceProxy.js.map +7 -0
- package/dist/cjs/proxy/SymbolIntentApiServiceProxyBase.js +35 -0
- package/dist/cjs/proxy/SymbolIntentApiServiceProxyBase.js.map +7 -0
- package/dist/cjs/proxy/TopicProtocolApiServiceProxy.js +324 -0
- package/dist/cjs/proxy/TopicProtocolApiServiceProxy.js.map +7 -0
- package/dist/cjs/proxy/index.js +26 -0
- package/dist/cjs/proxy/index.js.map +7 -0
- package/dist/cjs/resolvers/ResourceResolver.js +2 -2
- package/dist/cjs/resolvers/ResourceResolver.js.map +2 -2
- package/dist/cjs/session/SessionManager.js +2 -2
- package/dist/cjs/session/SessionManager.js.map +2 -2
- package/dist/cjs/websocket/WebSocketClient.js +554 -0
- package/dist/cjs/websocket/WebSocketClient.js.map +7 -0
- package/dist/cjs/websocket/WebSocketManager.js +652 -0
- package/dist/cjs/websocket/WebSocketManager.js.map +7 -0
- package/dist/cjs/websocket/index.js +24 -0
- package/dist/cjs/websocket/index.js.map +7 -0
- package/dist/esm/SimpleBootHttpServer.js +59 -19
- package/dist/esm/SimpleBootHttpServer.js.map +2 -2
- package/dist/esm/codes/HttpHeaders.js +12 -2
- package/dist/esm/codes/HttpHeaders.js.map +2 -2
- package/dist/esm/codes/Mimes.js +2 -0
- package/dist/esm/codes/Mimes.js.map +2 -2
- package/dist/esm/decorators/MethodMapping.js +2 -1
- package/dist/esm/decorators/MethodMapping.js.map +2 -2
- package/dist/esm/endpoints/WebSocketEndPoint.js +1 -0
- package/dist/esm/endpoints/WebSocketEndPoint.js.map +7 -0
- package/dist/esm/filters/CacheFilter.js +67 -27
- package/dist/esm/filters/CacheFilter.js.map +2 -2
- package/dist/esm/filters/IntentSchemeFilter.js +75 -0
- package/dist/esm/filters/IntentSchemeFilter.js.map +7 -0
- package/dist/esm/filters/ResourceFilter.js +4 -1
- package/dist/esm/filters/ResourceFilter.js.map +2 -2
- package/dist/esm/filters/TopicProtocolFilter.js +310 -0
- package/dist/esm/filters/TopicProtocolFilter.js.map +7 -0
- package/dist/esm/filters/index.js +1 -0
- package/dist/esm/filters/index.js.map +2 -2
- package/dist/esm/index.js +12 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/models/RequestResponse.js +46 -84
- package/dist/esm/models/RequestResponse.js.map +2 -2
- package/dist/esm/models/datas/body/ReqPathData.js +6 -0
- package/dist/esm/models/datas/body/ReqPathData.js.map +7 -0
- package/dist/esm/option/HttpServerOption.js +24 -4
- package/dist/esm/option/HttpServerOption.js.map +2 -2
- package/dist/esm/proxy/SymbolIntentApiServiceProxy.js +118 -0
- package/dist/esm/proxy/SymbolIntentApiServiceProxy.js.map +7 -0
- package/dist/esm/proxy/SymbolIntentApiServiceProxyBase.js +12 -0
- package/dist/esm/proxy/SymbolIntentApiServiceProxyBase.js.map +7 -0
- package/dist/esm/proxy/TopicProtocolApiServiceProxy.js +301 -0
- package/dist/esm/proxy/TopicProtocolApiServiceProxy.js.map +7 -0
- package/dist/esm/proxy/index.js +4 -0
- package/dist/esm/proxy/index.js.map +7 -0
- package/dist/esm/resolvers/ResourceResolver.js +1 -1
- package/dist/esm/resolvers/ResourceResolver.js.map +1 -1
- package/dist/esm/session/SessionManager.js +1 -1
- package/dist/esm/session/SessionManager.js.map +1 -1
- package/dist/esm/websocket/WebSocketClient.js +529 -0
- package/dist/esm/websocket/WebSocketClient.js.map +7 -0
- package/dist/esm/websocket/WebSocketManager.js +622 -0
- package/dist/esm/websocket/WebSocketManager.js.map +7 -0
- package/dist/esm/websocket/index.js +3 -0
- package/dist/esm/websocket/index.js.map +7 -0
- package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js +13190 -4886
- package/dist/esm-bundle/dooboostore-simple-boot-http-server.esm.js.map +4 -4
- package/dist/types/SimpleBootHttpServer.d.ts +5 -3
- package/dist/types/SimpleBootHttpServer.d.ts.map +1 -1
- package/dist/types/codes/HttpHeaders.d.ts +3 -0
- package/dist/types/codes/HttpHeaders.d.ts.map +1 -1
- package/dist/types/codes/Mimes.d.ts +3 -1
- package/dist/types/codes/Mimes.d.ts.map +1 -1
- package/dist/types/decorators/MethodMapping.d.ts +3 -2
- package/dist/types/decorators/MethodMapping.d.ts.map +1 -1
- package/dist/types/endpoints/WebSocketEndPoint.d.ts +17 -0
- package/dist/types/endpoints/WebSocketEndPoint.d.ts.map +1 -0
- package/dist/types/filters/CacheFilter.d.ts +6 -0
- package/dist/types/filters/CacheFilter.d.ts.map +1 -1
- package/dist/types/filters/IntentSchemeFilter.d.ts +20 -0
- package/dist/types/filters/IntentSchemeFilter.d.ts.map +1 -0
- package/dist/types/filters/ResourceFilter.d.ts.map +1 -1
- package/dist/types/filters/TopicProtocolFilter.d.ts +34 -0
- package/dist/types/filters/TopicProtocolFilter.d.ts.map +1 -0
- package/dist/types/filters/index.d.ts +1 -0
- package/dist/types/filters/index.d.ts.map +1 -1
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/models/RequestResponse.d.ts +9 -6
- package/dist/types/models/RequestResponse.d.ts.map +1 -1
- package/dist/types/models/datas/body/ReqPathData.d.ts +4 -0
- package/dist/types/models/datas/body/ReqPathData.d.ts.map +1 -0
- package/dist/types/option/HttpServerOption.d.ts +30 -20
- package/dist/types/option/HttpServerOption.d.ts.map +1 -1
- package/dist/types/proxy/SymbolIntentApiServiceProxy.d.ts +18 -0
- package/dist/types/proxy/SymbolIntentApiServiceProxy.d.ts.map +1 -0
- package/dist/types/proxy/SymbolIntentApiServiceProxyBase.d.ts +5 -0
- package/dist/types/proxy/SymbolIntentApiServiceProxyBase.d.ts.map +1 -0
- package/dist/types/proxy/TopicProtocolApiServiceProxy.d.ts +28 -0
- package/dist/types/proxy/TopicProtocolApiServiceProxy.d.ts.map +1 -0
- package/dist/types/proxy/index.d.ts +4 -0
- package/dist/types/proxy/index.d.ts.map +1 -0
- package/dist/types/session/SessionManager.d.ts +2 -17
- package/dist/types/session/SessionManager.d.ts.map +1 -1
- package/dist/types/websocket/WebSocketClient.d.ts +88 -0
- package/dist/types/websocket/WebSocketClient.d.ts.map +1 -0
- package/dist/types/websocket/WebSocketManager.d.ts +163 -0
- package/dist/types/websocket/WebSocketManager.d.ts.map +1 -0
- package/dist/types/websocket/index.d.ts +3 -0
- package/dist/types/websocket/index.d.ts.map +1 -0
- package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js +13262 -4958
- package/dist/umd-bundle/dooboostore-simple-boot-http-server.umd.js.map +4 -4
- package/dist/umd-bundle/websocket-client.umd.js +11194 -0
- package/dist/umd-bundle/websocket-client.umd.js.map +7 -0
- package/package.json +24 -15
- package/src/SimpleBootHttpServer.ts +366 -312
- package/src/codes/HttpHeaders.ts +13 -2
- package/src/codes/Mimes.ts +27 -25
- package/src/decorators/MethodMapping.ts +4 -3
- package/src/endpoints/WebSocketEndPoint.ts +12 -0
- package/src/filters/CacheFilter.ts +112 -67
- package/src/filters/IntentSchemeFilter.ts +69 -0
- package/src/filters/ResourceFilter.ts +6 -1
- package/src/filters/TopicProtocolFilter.ts +349 -0
- package/src/filters/index.ts +1 -0
- package/src/index.ts +12 -12
- package/src/models/RequestResponse.ts +108 -240
- package/src/models/datas/body/ReqPathData.ts +3 -0
- package/src/option/HttpServerOption.ts +73 -23
- package/src/proxy/SymbolIntentApiServiceProxy.ts +120 -0
- package/src/proxy/SymbolIntentApiServiceProxyBase.ts +16 -0
- package/src/proxy/TopicProtocolApiServiceProxy.ts +328 -0
- package/src/proxy/index.ts +3 -0
- package/src/resolvers/ResourceResolver.ts +1 -1
- package/src/session/SessionManager.ts +3 -3
- package/src/websocket/WebSocketClient.ts +637 -0
- package/src/websocket/WebSocketManager.ts +713 -0
- package/src/websocket/index.ts +2 -0
- package/tsconfig.json +3 -1
|
@@ -20,7 +20,7 @@ __export(SessionManager_exports, {
|
|
|
20
20
|
SessionManager: () => SessionManager
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(SessionManager_exports);
|
|
23
|
-
var
|
|
23
|
+
var import_core = require("@dooboostore/core");
|
|
24
24
|
var import_RequestResponse = require("../models/RequestResponse");
|
|
25
25
|
class SessionManager {
|
|
26
26
|
constructor(option) {
|
|
@@ -69,7 +69,7 @@ class SessionManager {
|
|
|
69
69
|
return now - access >= this.option.sessionOption.expiredTime;
|
|
70
70
|
}
|
|
71
71
|
makeUUID() {
|
|
72
|
-
return
|
|
72
|
+
return import_core.RandomUtils.uuid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
|
|
73
73
|
}
|
|
74
74
|
async session(rrOrUUID) {
|
|
75
75
|
let uuid;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/session/SessionManager.ts"],
|
|
4
|
-
"sourcesContent": ["import {RandomUtils} from '@dooboostore/core
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import {RandomUtils} from '@dooboostore/core'\nimport { HttpServerOption, SessionOption } from '../option/HttpServerOption';\nimport {RequestResponse} from '../models/RequestResponse';\n\nexport class SessionManager {\n private sessions = new Map<string, { access: number, data?: any }>();\n public sessionOption: SessionOption;\n\n constructor(private option: HttpServerOption) {\n this.sessionOption = option.sessionOption;\n setInterval(async () => {\n const uuids = (await this.getSessionUUIDs());\n for (const uuid of uuids) {\n const dataSet = await this.getSessionDataSet(uuid);\n if (dataSet && this.isExpired(dataSet.access)) {\n await this.deleteSession(uuid);\n }\n }\n }, this.sessionOption.expiredTime);\n }\n\n async getSessionUUIDs() {\n if (this.sessionOption.provider?.uuids) {\n return this.sessionOption.provider.uuids();\n } else {\n return Array.from(this.sessions.keys());\n }\n }\n\n async deleteSession(uuid: string) {\n if (this.sessionOption.provider?.delete) {\n this.sessionOption.provider.delete(uuid);\n } else {\n this.sessions.delete(uuid);\n }\n }\n\n async getSessionDataSet(uuid: string) {\n if (this.sessionOption.provider?.get) {\n return this.sessionOption.provider.get(uuid);\n } else {\n return this.sessions.get(uuid);\n }\n }\n\n async setSessionDataSet(uuid: string, dataSet: { access: number, data?: any }) {\n if (this.sessionOption.provider?.set) {\n this.sessionOption.provider.set(uuid, dataSet);\n } else {\n this.sessions.set(uuid, dataSet);\n }\n }\n\n isExpired(access: number, now: number = Date.now()) {\n return (now - access) >= this.option.sessionOption.expiredTime;\n }\n\n makeUUID() {\n return RandomUtils.uuid('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');\n }\n\n async session(): Promise<{ uuid: string, dataSet: { access: number, data?: any } }>;\n async session(uuid: string): Promise<{ uuid: string, dataSet: { access: number, data?: any } }>;\n async session(rr: RequestResponse): Promise<{ uuid: string, dataSet: { access: number, data?: any } }>;\n async session(rrOrUUID?: string | RequestResponse): Promise<{ uuid: string, dataSet: { access: number, data?: any } } >{\n let uuid: string;\n if (rrOrUUID instanceof RequestResponse) {\n uuid = rrOrUUID.reqCookieGet(this.sessionOption.key) ?? this.makeUUID();\n } else if (typeof rrOrUUID === 'string') {\n uuid = rrOrUUID;\n } else {\n uuid = this.makeUUID()\n }\n let dataSet = await this.getSessionDataSet(uuid);\n const now = Date.now();\n if (dataSet) {\n if (this.isExpired(dataSet.access, now)) {\n delete dataSet.data;\n }\n dataSet.access = now;\n } else {\n dataSet = {\n access: now\n }\n }\n await this.setSessionDataSet(uuid, dataSet);\n return {uuid, dataSet};\n }\n}"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA0B;AAE1B,6BAA8B;AAEvB,MAAM,eAAe;AAAA,EAIxB,YAAoB,QAA0B;AAA1B;AAHpB,SAAQ,WAAW,oBAAI,IAA4C;AAI/D,SAAK,gBAAgB,OAAO;AAC5B,gBAAY,YAAY;AACpB,YAAM,QAAS,MAAM,KAAK,gBAAgB;AAC1C,iBAAW,QAAQ,OAAO;AACtB,cAAM,UAAU,MAAM,KAAK,kBAAkB,IAAI;AACjD,YAAI,WAAW,KAAK,UAAU,QAAQ,MAAM,GAAG;AAC3C,gBAAM,KAAK,cAAc,IAAI;AAAA,QACjC;AAAA,MACJ;AAAA,IACJ,GAAG,KAAK,cAAc,WAAW;AAAA,EACrC;AAAA,EAEA,MAAM,kBAAkB;AACpB,QAAI,KAAK,cAAc,UAAU,OAAO;AACpC,aAAO,KAAK,cAAc,SAAS,MAAM;AAAA,IAC7C,OAAO;AACH,aAAO,MAAM,KAAK,KAAK,SAAS,KAAK,CAAC;AAAA,IAC1C;AAAA,EACJ;AAAA,EAEA,MAAM,cAAc,MAAc;AAC9B,QAAI,KAAK,cAAc,UAAU,QAAQ;AACrC,WAAK,cAAc,SAAS,OAAO,IAAI;AAAA,IAC3C,OAAO;AACH,WAAK,SAAS,OAAO,IAAI;AAAA,IAC7B;AAAA,EACJ;AAAA,EAEA,MAAM,kBAAkB,MAAc;AAClC,QAAI,KAAK,cAAc,UAAU,KAAK;AAClC,aAAO,KAAK,cAAc,SAAS,IAAI,IAAI;AAAA,IAC/C,OAAO;AACH,aAAO,KAAK,SAAS,IAAI,IAAI;AAAA,IACjC;AAAA,EACJ;AAAA,EAEA,MAAM,kBAAkB,MAAc,SAAyC;AAC3E,QAAI,KAAK,cAAc,UAAU,KAAK;AAClC,WAAK,cAAc,SAAS,IAAI,MAAM,OAAO;AAAA,IACjD,OAAO;AACH,WAAK,SAAS,IAAI,MAAM,OAAO;AAAA,IACnC;AAAA,EACJ;AAAA,EAEA,UAAU,QAAgB,MAAc,KAAK,IAAI,GAAG;AAChD,WAAQ,MAAM,UAAW,KAAK,OAAO,cAAc;AAAA,EACvD;AAAA,EAEA,WAAW;AACP,WAAO,wBAAY,KAAK,kCAAkC;AAAA,EAC9D;AAAA,EAKA,MAAM,QAAQ,UAAyG;AACnH,QAAI;AACJ,QAAI,oBAAoB,wCAAiB;AACrC,aAAO,SAAS,aAAa,KAAK,cAAc,GAAG,KAAK,KAAK,SAAS;AAAA,IAC1E,WAAW,OAAO,aAAa,UAAU;AACrC,aAAO;AAAA,IACX,OAAO;AACH,aAAO,KAAK,SAAS;AAAA,IACzB;AACA,QAAI,UAAU,MAAM,KAAK,kBAAkB,IAAI;AAC/C,UAAM,MAAM,KAAK,IAAI;AACrB,QAAI,SAAS;AACT,UAAI,KAAK,UAAU,QAAQ,QAAQ,GAAG,GAAG;AACrC,eAAO,QAAQ;AAAA,MACnB;AACA,cAAQ,SAAS;AAAA,IACrB,OAAO;AACH,gBAAU;AAAA,QACN,QAAQ;AAAA,MACZ;AAAA,IACJ;AACA,UAAM,KAAK,kBAAkB,MAAM,OAAO;AAC1C,WAAO,EAAC,MAAM,QAAO;AAAA,EACzB;AACJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var WebSocketClient_exports = {};
|
|
20
|
+
__export(WebSocketClient_exports, {
|
|
21
|
+
WebSocketClient: () => WebSocketClient
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(WebSocketClient_exports);
|
|
24
|
+
var import_core = require("@dooboostore/core");
|
|
25
|
+
var import_core2 = require("@dooboostore/core");
|
|
26
|
+
__reExport(WebSocketClient_exports, require("@dooboostore/core"), module.exports);
|
|
27
|
+
class WebSocketClient {
|
|
28
|
+
constructor(connection, config) {
|
|
29
|
+
this.topics = /* @__PURE__ */ new Map();
|
|
30
|
+
this.pendingMessages = [];
|
|
31
|
+
this.pendingBinaryMessages = [];
|
|
32
|
+
this.isConnected = false;
|
|
33
|
+
this._subject = new import_core2.Subject();
|
|
34
|
+
this.currentRetryCount = 0;
|
|
35
|
+
this.isManualClose = false;
|
|
36
|
+
this.isConnecting = false;
|
|
37
|
+
if (typeof connection === "string" || connection instanceof URL) {
|
|
38
|
+
this.connectionUrl = connection;
|
|
39
|
+
} else {
|
|
40
|
+
this.connectionUrl = connection.url;
|
|
41
|
+
this.connectionProtocols = connection.protocols;
|
|
42
|
+
}
|
|
43
|
+
this.retryConnectionCount = config?.retryConnectionCount ?? 0;
|
|
44
|
+
this.retryConnectionDelay = config?.retryConnectionDelay ?? 1e3;
|
|
45
|
+
this.maxPendingMessages = config?.maxPendingMessages ?? 1e3;
|
|
46
|
+
this.maxPendingBinaryMessages = config?.maxPendingBinaryMessages ?? 100;
|
|
47
|
+
this.connect();
|
|
48
|
+
}
|
|
49
|
+
get observable() {
|
|
50
|
+
return this._subject.asObservable();
|
|
51
|
+
}
|
|
52
|
+
connect() {
|
|
53
|
+
if (this.isConnecting) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (this.websocket && (this.websocket.readyState === WebSocket.OPEN || this.websocket.readyState === WebSocket.CONNECTING)) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
this.isConnecting = true;
|
|
60
|
+
if (this.connectionProtocols) {
|
|
61
|
+
this.websocket = new WebSocket(this.connectionUrl, this.connectionProtocols);
|
|
62
|
+
} else {
|
|
63
|
+
this.websocket = new WebSocket(this.connectionUrl);
|
|
64
|
+
}
|
|
65
|
+
this.websocket.binaryType = "arraybuffer";
|
|
66
|
+
this.websocket.addEventListener("open", () => {
|
|
67
|
+
this.isConnecting = false;
|
|
68
|
+
this.isConnected = true;
|
|
69
|
+
this.currentRetryCount = 0;
|
|
70
|
+
if (this.reconnectTimeout) {
|
|
71
|
+
clearTimeout(this.reconnectTimeout);
|
|
72
|
+
this.reconnectTimeout = void 0;
|
|
73
|
+
}
|
|
74
|
+
console.log("WebSocket connected");
|
|
75
|
+
this.onOpenCallback?.();
|
|
76
|
+
this.topics.forEach((topicData, uuid) => {
|
|
77
|
+
if (!topicData.subscription.closed) {
|
|
78
|
+
const subscribeTopic = {
|
|
79
|
+
type: "subscribe",
|
|
80
|
+
uuid,
|
|
81
|
+
target: topicData.target
|
|
82
|
+
};
|
|
83
|
+
this.websocket.send(JSON.stringify(subscribeTopic));
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
while (this.pendingMessages.length > 0) {
|
|
87
|
+
const message = this.pendingMessages.shift();
|
|
88
|
+
this.websocket.send(JSON.stringify(message));
|
|
89
|
+
}
|
|
90
|
+
while (this.pendingBinaryMessages.length > 0) {
|
|
91
|
+
const message = this.pendingBinaryMessages.shift();
|
|
92
|
+
if (message) {
|
|
93
|
+
this.websocket.send(message);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
this.websocket.addEventListener("close", (event) => {
|
|
98
|
+
this.isConnecting = false;
|
|
99
|
+
this.isConnected = false;
|
|
100
|
+
console.log("WebSocket closed", event.code, event.reason);
|
|
101
|
+
this.onCloseCallback?.();
|
|
102
|
+
if (!this.isManualClose) {
|
|
103
|
+
this.attemptReconnect();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
this.websocket.addEventListener("error", (error) => {
|
|
107
|
+
console.error("WebSocket error:", error);
|
|
108
|
+
});
|
|
109
|
+
this.websocket.addEventListener("message", async (event) => {
|
|
110
|
+
const topic = await this.parseIncomingTopic(event.data);
|
|
111
|
+
if (!topic) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
this._subject.next(topic);
|
|
115
|
+
this.observer?.(topic);
|
|
116
|
+
if (topic.uuid) {
|
|
117
|
+
const topicData = this.topics.get(topic.uuid);
|
|
118
|
+
if (topicData) {
|
|
119
|
+
const observer = topicData.observer;
|
|
120
|
+
const nextCallback = typeof observer === "function" ? observer : observer.next;
|
|
121
|
+
const errorCallback = typeof observer === "function" ? void 0 : observer.error;
|
|
122
|
+
const eventCallback = typeof observer === "function" ? void 0 : observer.event;
|
|
123
|
+
if ("state" in topic && topic.state === "success") {
|
|
124
|
+
await nextCallback(topic.body, { socket: this.websocket });
|
|
125
|
+
} else if ("state" in topic && topic.state === "error" && errorCallback) {
|
|
126
|
+
await errorCallback(topic.body);
|
|
127
|
+
} else if ("type" in topic && topic.type === "unsubscribe") {
|
|
128
|
+
topicData.subscription.closed = true;
|
|
129
|
+
this.topics.delete(topic.uuid);
|
|
130
|
+
topicData.onUnsubscribes.forEach((it) => it("server"));
|
|
131
|
+
} else if ("type" in topic && topic.type === "event" && eventCallback) {
|
|
132
|
+
let eventResponse = typeof eventCallback === "function" ? await eventCallback(topic.event, topic.body, { socket: this.websocket }) : await eventCallback[topic.event]?.(topic.body, { socket: this.websocket });
|
|
133
|
+
if (eventResponse !== void 0 && eventResponse !== null) {
|
|
134
|
+
const value = {
|
|
135
|
+
uuid: topic.uuid,
|
|
136
|
+
eventUUID: topic.eventUUID,
|
|
137
|
+
type: topic.type,
|
|
138
|
+
body: eventResponse
|
|
139
|
+
};
|
|
140
|
+
this.websocket.send(JSON.stringify(value));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
attemptReconnect() {
|
|
148
|
+
if (this.currentRetryCount >= this.retryConnectionCount) {
|
|
149
|
+
console.error(`WebSocket reconnection failed after ${this.retryConnectionCount} attempts`);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (this.reconnectTimeout) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
this.currentRetryCount++;
|
|
156
|
+
console.log(`Attempting to reconnect... (${this.currentRetryCount}/${this.retryConnectionCount})`);
|
|
157
|
+
this.reconnectTimeout = window.setTimeout(() => {
|
|
158
|
+
this.reconnectTimeout = void 0;
|
|
159
|
+
this.connect();
|
|
160
|
+
}, this.retryConnectionDelay);
|
|
161
|
+
}
|
|
162
|
+
sendMessage(message) {
|
|
163
|
+
if (this.isConnected && this.websocket.readyState === WebSocket.OPEN) {
|
|
164
|
+
this.websocket.send(JSON.stringify(message));
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (message.type === "subscribe" || message.type === "unsubscribe") {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (this.maxPendingMessages <= 0) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (this.pendingMessages.length >= this.maxPendingMessages) {
|
|
174
|
+
this.pendingMessages.shift();
|
|
175
|
+
}
|
|
176
|
+
this.pendingMessages.push(message);
|
|
177
|
+
}
|
|
178
|
+
sendBinary(data) {
|
|
179
|
+
if (this.isConnected && this.websocket.readyState === WebSocket.OPEN) {
|
|
180
|
+
this.websocket.send(data);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (this.maxPendingBinaryMessages <= 0) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (this.pendingBinaryMessages.length >= this.maxPendingBinaryMessages) {
|
|
187
|
+
this.pendingBinaryMessages.shift();
|
|
188
|
+
}
|
|
189
|
+
this.pendingBinaryMessages.push(data);
|
|
190
|
+
}
|
|
191
|
+
async parseIncomingTopic(data) {
|
|
192
|
+
if (typeof data === "string") {
|
|
193
|
+
try {
|
|
194
|
+
return JSON.parse(data);
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.warn("Invalid WebSocket payload:", error);
|
|
197
|
+
return void 0;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
if (data instanceof ArrayBuffer) {
|
|
201
|
+
return this.parseBinaryTopic(data);
|
|
202
|
+
}
|
|
203
|
+
if (typeof Blob !== "undefined" && data instanceof Blob) {
|
|
204
|
+
const buffer = await data.arrayBuffer();
|
|
205
|
+
return this.parseBinaryTopic(buffer);
|
|
206
|
+
}
|
|
207
|
+
return void 0;
|
|
208
|
+
}
|
|
209
|
+
parseBinaryTopic(data) {
|
|
210
|
+
if (data.byteLength < 4) {
|
|
211
|
+
return void 0;
|
|
212
|
+
}
|
|
213
|
+
const view = new DataView(data);
|
|
214
|
+
const jsonLength = view.getUint32(0, true);
|
|
215
|
+
const jsonStart = 4;
|
|
216
|
+
const jsonEnd = jsonStart + jsonLength;
|
|
217
|
+
if (data.byteLength < jsonEnd) {
|
|
218
|
+
return void 0;
|
|
219
|
+
}
|
|
220
|
+
const jsonBytes = new Uint8Array(data, jsonStart, jsonLength);
|
|
221
|
+
let meta;
|
|
222
|
+
try {
|
|
223
|
+
const decoder = new TextDecoder();
|
|
224
|
+
meta = JSON.parse(decoder.decode(jsonBytes));
|
|
225
|
+
} catch (error) {
|
|
226
|
+
console.warn("Invalid WebSocket binary payload:", error);
|
|
227
|
+
return void 0;
|
|
228
|
+
}
|
|
229
|
+
const filesMeta = Array.isArray(meta.files) ? meta.files : [];
|
|
230
|
+
const fileMap = /* @__PURE__ */ new Map();
|
|
231
|
+
filesMeta.forEach((file) => {
|
|
232
|
+
if (!file || typeof file.id !== "string" || typeof file.size !== "number" || typeof file.offset !== "number") {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const start = jsonEnd + file.offset;
|
|
236
|
+
const end = start + file.size;
|
|
237
|
+
if (start < jsonEnd || end > data.byteLength) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const slice = data.slice(start, end);
|
|
241
|
+
const mime = file.mime || "application/octet-stream";
|
|
242
|
+
let fileValue;
|
|
243
|
+
if (typeof File !== "undefined") {
|
|
244
|
+
fileValue = new File([slice], file.name || "file", { type: mime });
|
|
245
|
+
} else {
|
|
246
|
+
fileValue = { name: file.name || "file", mime, size: file.size, buffer: slice };
|
|
247
|
+
}
|
|
248
|
+
fileMap.set(file.id, fileValue);
|
|
249
|
+
});
|
|
250
|
+
const replaceFileRefs = (value) => {
|
|
251
|
+
if (value && typeof value === "object" && "$file" in value && typeof value.$file === "string") {
|
|
252
|
+
const file = fileMap.get(value.$file);
|
|
253
|
+
if (file) {
|
|
254
|
+
return file;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
if (Array.isArray(value)) {
|
|
258
|
+
return value.map((item) => replaceFileRefs(item));
|
|
259
|
+
}
|
|
260
|
+
if (value && typeof value === "object") {
|
|
261
|
+
const result = {};
|
|
262
|
+
Object.keys(value).forEach((key) => {
|
|
263
|
+
result[key] = replaceFileRefs(value[key]);
|
|
264
|
+
});
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
return value;
|
|
268
|
+
};
|
|
269
|
+
meta.body = replaceFileRefs(meta.body);
|
|
270
|
+
return meta;
|
|
271
|
+
}
|
|
272
|
+
isBinaryPayload(value) {
|
|
273
|
+
if (!value) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
if (typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer) {
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
if (typeof Uint8Array !== "undefined" && value instanceof Uint8Array) {
|
|
280
|
+
return true;
|
|
281
|
+
}
|
|
282
|
+
if (typeof Blob !== "undefined" && value instanceof Blob) {
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
if (value && typeof value === "object" && "buffer" in value) {
|
|
286
|
+
const bufferValue = value.buffer;
|
|
287
|
+
return this.isBinaryPayload(bufferValue);
|
|
288
|
+
}
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
hasBinaryPayload(value) {
|
|
292
|
+
if (this.isBinaryPayload(value)) {
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
if (Array.isArray(value)) {
|
|
296
|
+
return value.some((item) => this.hasBinaryPayload(item));
|
|
297
|
+
}
|
|
298
|
+
if (value && typeof value === "object") {
|
|
299
|
+
return Object.keys(value).some((key) => this.hasBinaryPayload(value[key]));
|
|
300
|
+
}
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
async buildBinaryMessage(body, meta) {
|
|
304
|
+
const fileRefs = /* @__PURE__ */ new Map();
|
|
305
|
+
const fileEntries = [];
|
|
306
|
+
let fileIndex = 0;
|
|
307
|
+
const registerFile = (value) => {
|
|
308
|
+
const existing = fileRefs.get(value);
|
|
309
|
+
if (existing) {
|
|
310
|
+
return existing;
|
|
311
|
+
}
|
|
312
|
+
const id = `f${++fileIndex}`;
|
|
313
|
+
fileRefs.set(value, id);
|
|
314
|
+
let name = "file";
|
|
315
|
+
let mime = "application/octet-stream";
|
|
316
|
+
let buffer;
|
|
317
|
+
if (typeof Blob !== "undefined" && value instanceof Blob) {
|
|
318
|
+
const fileLike = value;
|
|
319
|
+
if ("name" in fileLike && typeof fileLike.name === "string") {
|
|
320
|
+
name = fileLike.name || name;
|
|
321
|
+
}
|
|
322
|
+
mime = fileLike.type || mime;
|
|
323
|
+
buffer = fileLike.arrayBuffer();
|
|
324
|
+
} else if (value && typeof value === "object" && "buffer" in value) {
|
|
325
|
+
const fileLike = value;
|
|
326
|
+
if (typeof fileLike.name === "string") {
|
|
327
|
+
name = fileLike.name || name;
|
|
328
|
+
}
|
|
329
|
+
if (typeof fileLike.mime === "string") {
|
|
330
|
+
mime = fileLike.mime || mime;
|
|
331
|
+
}
|
|
332
|
+
const innerBuffer = fileLike.buffer;
|
|
333
|
+
if (typeof Blob !== "undefined" && innerBuffer instanceof Blob) {
|
|
334
|
+
buffer = innerBuffer.arrayBuffer();
|
|
335
|
+
} else if (typeof Uint8Array !== "undefined" && innerBuffer instanceof Uint8Array) {
|
|
336
|
+
const sliced = innerBuffer.buffer.slice(innerBuffer.byteOffset, innerBuffer.byteOffset + innerBuffer.byteLength);
|
|
337
|
+
buffer = Promise.resolve(sliced instanceof ArrayBuffer ? sliced : new Uint8Array(sliced).buffer);
|
|
338
|
+
} else if (typeof ArrayBuffer !== "undefined" && innerBuffer instanceof ArrayBuffer) {
|
|
339
|
+
buffer = Promise.resolve(innerBuffer);
|
|
340
|
+
} else {
|
|
341
|
+
buffer = Promise.resolve(new ArrayBuffer(0));
|
|
342
|
+
}
|
|
343
|
+
} else if (typeof Uint8Array !== "undefined" && value instanceof Uint8Array) {
|
|
344
|
+
const view = value;
|
|
345
|
+
const sliced = view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength);
|
|
346
|
+
buffer = Promise.resolve(sliced instanceof ArrayBuffer ? sliced : new Uint8Array(sliced).buffer);
|
|
347
|
+
} else if (typeof ArrayBuffer !== "undefined" && value instanceof ArrayBuffer) {
|
|
348
|
+
buffer = Promise.resolve(value);
|
|
349
|
+
} else {
|
|
350
|
+
buffer = Promise.resolve(new ArrayBuffer(0));
|
|
351
|
+
}
|
|
352
|
+
fileEntries.push({ id, name, mime, buffer });
|
|
353
|
+
return id;
|
|
354
|
+
};
|
|
355
|
+
const replaceFiles = (value) => {
|
|
356
|
+
if (this.isBinaryPayload(value)) {
|
|
357
|
+
const id = registerFile(value);
|
|
358
|
+
return { $file: id };
|
|
359
|
+
}
|
|
360
|
+
if (Array.isArray(value)) {
|
|
361
|
+
return value.map((item) => replaceFiles(item));
|
|
362
|
+
}
|
|
363
|
+
if (value && typeof value === "object") {
|
|
364
|
+
const result = {};
|
|
365
|
+
Object.keys(value).forEach((key) => {
|
|
366
|
+
result[key] = replaceFiles(value[key]);
|
|
367
|
+
});
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
370
|
+
return value;
|
|
371
|
+
};
|
|
372
|
+
const payload = replaceFiles(body);
|
|
373
|
+
const buffers = await Promise.all(fileEntries.map((entry) => entry.buffer));
|
|
374
|
+
let offset = 0;
|
|
375
|
+
const files = fileEntries.map((entry, index) => {
|
|
376
|
+
const size = buffers[index].byteLength;
|
|
377
|
+
const fileMeta = {
|
|
378
|
+
id: entry.id,
|
|
379
|
+
name: entry.name,
|
|
380
|
+
mime: entry.mime,
|
|
381
|
+
size,
|
|
382
|
+
offset
|
|
383
|
+
};
|
|
384
|
+
offset += size;
|
|
385
|
+
return fileMeta;
|
|
386
|
+
});
|
|
387
|
+
const json = JSON.stringify({
|
|
388
|
+
type: meta.type,
|
|
389
|
+
uuid: meta.uuid,
|
|
390
|
+
requestUUID: meta.requestUUID,
|
|
391
|
+
body: payload,
|
|
392
|
+
files
|
|
393
|
+
});
|
|
394
|
+
const encoder = new TextEncoder();
|
|
395
|
+
const jsonBytes = encoder.encode(json);
|
|
396
|
+
const header = new Uint8Array(4);
|
|
397
|
+
new DataView(header.buffer).setUint32(0, jsonBytes.byteLength, true);
|
|
398
|
+
const totalSize = header.byteLength + jsonBytes.byteLength + offset;
|
|
399
|
+
const combined = new Uint8Array(totalSize);
|
|
400
|
+
combined.set(header, 0);
|
|
401
|
+
combined.set(jsonBytes, header.byteLength);
|
|
402
|
+
let cursor = header.byteLength + jsonBytes.byteLength;
|
|
403
|
+
buffers.forEach((buffer) => {
|
|
404
|
+
const view = buffer instanceof ArrayBuffer ? new Uint8Array(buffer) : new Uint8Array(buffer);
|
|
405
|
+
combined.set(view, cursor);
|
|
406
|
+
cursor += buffer.byteLength;
|
|
407
|
+
});
|
|
408
|
+
return combined.buffer;
|
|
409
|
+
}
|
|
410
|
+
subject(target, option) {
|
|
411
|
+
const self = this;
|
|
412
|
+
const uuid = import_core.RandomUtils.uuid4();
|
|
413
|
+
const onUnsubscribes = [];
|
|
414
|
+
if (option?.onUnsubscribe) {
|
|
415
|
+
onUnsubscribes.push(option.onUnsubscribe);
|
|
416
|
+
}
|
|
417
|
+
if (option?.observer && typeof option.observer !== "function" && option.observer.complete) {
|
|
418
|
+
onUnsubscribes.push(() => option.observer.complete());
|
|
419
|
+
}
|
|
420
|
+
const topicSubject = new import_core2.Subject();
|
|
421
|
+
onUnsubscribes.push(() => topicSubject.complete());
|
|
422
|
+
let isClosed = false;
|
|
423
|
+
let activeSubscription;
|
|
424
|
+
const unsubscribeLogic = () => {
|
|
425
|
+
if (isClosed) return;
|
|
426
|
+
const unSubscribeTopic = { type: "unsubscribe", uuid };
|
|
427
|
+
self.sendMessage(unSubscribeTopic);
|
|
428
|
+
isClosed = true;
|
|
429
|
+
self.topics.delete(uuid);
|
|
430
|
+
onUnsubscribes.forEach((it) => it("manual"));
|
|
431
|
+
if (activeSubscription) {
|
|
432
|
+
activeSubscription.closed = true;
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
const doSubscribe = (observer) => {
|
|
436
|
+
const subscription = {
|
|
437
|
+
closed: isClosed,
|
|
438
|
+
unsubscribe: unsubscribeLogic
|
|
439
|
+
};
|
|
440
|
+
const wrappedObserver = {
|
|
441
|
+
next: (data, meta) => {
|
|
442
|
+
topicSubject.next(data);
|
|
443
|
+
if (observer) {
|
|
444
|
+
return typeof observer === "function" ? observer(data, meta) : observer.next(data, meta);
|
|
445
|
+
}
|
|
446
|
+
},
|
|
447
|
+
error: (err) => {
|
|
448
|
+
topicSubject.error(err);
|
|
449
|
+
if (observer && typeof observer !== "function" && observer.error) {
|
|
450
|
+
observer.error(err);
|
|
451
|
+
}
|
|
452
|
+
},
|
|
453
|
+
event: observer && typeof observer !== "function" ? observer.event : void 0
|
|
454
|
+
};
|
|
455
|
+
self.topics.set(uuid, { observer: wrappedObserver, target, subscription, onUnsubscribes });
|
|
456
|
+
const subscribeTopic = { type: "subscribe", uuid, target, body: option?.subScribeBody };
|
|
457
|
+
self.sendMessage(subscribeTopic);
|
|
458
|
+
activeSubscription = subscription;
|
|
459
|
+
return subscription;
|
|
460
|
+
};
|
|
461
|
+
if (option?.observer) {
|
|
462
|
+
doSubscribe(option.observer);
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
get closed() {
|
|
466
|
+
return isClosed;
|
|
467
|
+
},
|
|
468
|
+
unsubscribe: unsubscribeLogic,
|
|
469
|
+
get observable() {
|
|
470
|
+
return new import_core2.Observable((subscriber) => {
|
|
471
|
+
if (!activeSubscription && !isClosed) {
|
|
472
|
+
doSubscribe();
|
|
473
|
+
}
|
|
474
|
+
return topicSubject.subscribe({
|
|
475
|
+
next: (value) => subscriber.next(value),
|
|
476
|
+
error: (err) => subscriber.error(err),
|
|
477
|
+
complete: () => subscriber.complete()
|
|
478
|
+
});
|
|
479
|
+
});
|
|
480
|
+
},
|
|
481
|
+
send: (body) => {
|
|
482
|
+
if (!activeSubscription && !self.topics.has(uuid) && !isClosed) {
|
|
483
|
+
doSubscribe();
|
|
484
|
+
}
|
|
485
|
+
const requestUUID = import_core.RandomUtils.uuid4();
|
|
486
|
+
if (self.hasBinaryPayload(body)) {
|
|
487
|
+
self.buildBinaryMessage(body, { type: option?.type, uuid, requestUUID }).then((buffer) => self.sendBinary(buffer));
|
|
488
|
+
} else {
|
|
489
|
+
const value = { type: option?.type, uuid, requestUUID, body };
|
|
490
|
+
self.sendMessage(value);
|
|
491
|
+
}
|
|
492
|
+
return topicSubject.pipe(import_core2.MessageOperator.filter((data) => data && data.requestUUID === requestUUID));
|
|
493
|
+
},
|
|
494
|
+
onUnsubscribe: (callback) => {
|
|
495
|
+
onUnsubscribes.push(callback);
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
onOpen(callback) {
|
|
500
|
+
this.onOpenCallback = callback;
|
|
501
|
+
}
|
|
502
|
+
onClose(callback) {
|
|
503
|
+
this.onCloseCallback = callback;
|
|
504
|
+
}
|
|
505
|
+
subscribe(observer) {
|
|
506
|
+
this.observer = observer;
|
|
507
|
+
}
|
|
508
|
+
close() {
|
|
509
|
+
this.isManualClose = true;
|
|
510
|
+
if (this.reconnectTimeout) {
|
|
511
|
+
clearTimeout(this.reconnectTimeout);
|
|
512
|
+
this.reconnectTimeout = void 0;
|
|
513
|
+
}
|
|
514
|
+
this.pendingMessages = [];
|
|
515
|
+
this.pendingBinaryMessages = [];
|
|
516
|
+
this.isConnecting = false;
|
|
517
|
+
this.topics.forEach((topicData) => {
|
|
518
|
+
topicData.subscription.closed = true;
|
|
519
|
+
topicData.onUnsubscribes.forEach((it) => it("manual"));
|
|
520
|
+
});
|
|
521
|
+
this.topics.clear();
|
|
522
|
+
this.websocket.close();
|
|
523
|
+
}
|
|
524
|
+
reconnect() {
|
|
525
|
+
this.isManualClose = true;
|
|
526
|
+
if (this.reconnectTimeout) {
|
|
527
|
+
clearTimeout(this.reconnectTimeout);
|
|
528
|
+
}
|
|
529
|
+
const reconnectAfterClose = () => {
|
|
530
|
+
console.log("close websocket");
|
|
531
|
+
this.isManualClose = false;
|
|
532
|
+
this.currentRetryCount = 0;
|
|
533
|
+
this.connect();
|
|
534
|
+
};
|
|
535
|
+
if (this.websocket.readyState === WebSocket.CLOSED || this.websocket.readyState === WebSocket.CLOSING) {
|
|
536
|
+
reconnectAfterClose();
|
|
537
|
+
} else {
|
|
538
|
+
this.websocket.addEventListener("close", reconnectAfterClose, { once: true });
|
|
539
|
+
this.websocket.close();
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
getReadyState() {
|
|
543
|
+
return this.websocket.readyState;
|
|
544
|
+
}
|
|
545
|
+
isConnectionOpen() {
|
|
546
|
+
return this.isConnected && this.websocket.readyState === WebSocket.OPEN;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
550
|
+
0 && (module.exports = {
|
|
551
|
+
WebSocketClient,
|
|
552
|
+
...require("@dooboostore/core")
|
|
553
|
+
});
|
|
554
|
+
//# sourceMappingURL=WebSocketClient.js.map
|