@pisell/core 0.0.2
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 +1 -0
- package/es/app/app.d.ts +101 -0
- package/es/app/app.js +177 -0
- package/es/app/const.d.ts +4 -0
- package/es/app/const.js +6 -0
- package/es/app/index.d.ts +14 -0
- package/es/app/index.js +52 -0
- package/es/applicationManager/application.d.ts +197 -0
- package/es/applicationManager/application.js +469 -0
- package/es/applicationManager/index.d.ts +19 -0
- package/es/applicationManager/index.js +206 -0
- package/es/aws/index.d.ts +16 -0
- package/es/aws/index.js +76 -0
- package/es/cmd/const.d.ts +11 -0
- package/es/cmd/const.js +13 -0
- package/es/cmd/index.d.ts +13 -0
- package/es/cmd/index.js +91 -0
- package/es/cmd/type.d.ts +5 -0
- package/es/cmd/type.js +1 -0
- package/es/communicationManager/index.d.ts +59 -0
- package/es/communicationManager/index.js +174 -0
- package/es/config.d.ts +3 -0
- package/es/config.js +14 -0
- package/es/cookie/index.d.ts +13 -0
- package/es/cookie/index.js +47 -0
- package/es/css/global.less +73 -0
- package/es/css/index.less +31 -0
- package/es/css/variables.css +84 -0
- package/es/data/index.d.ts +8 -0
- package/es/data/index.js +16 -0
- package/es/history/config.d.ts +24 -0
- package/es/history/config.js +43 -0
- package/es/history/index.d.ts +26 -0
- package/es/history/index.js +80 -0
- package/es/history/type.d.ts +2 -0
- package/es/history/type.js +1 -0
- package/es/hooks/index.d.ts +12 -0
- package/es/hooks/index.js +13 -0
- package/es/hooks/useDelayedValue/index.d.ts +2 -0
- package/es/hooks/useDelayedValue/index.js +26 -0
- package/es/hooks/useDispatch/index.d.ts +2 -0
- package/es/hooks/useDispatch/index.js +2 -0
- package/es/hooks/useLowCode/index.d.ts +13 -0
- package/es/hooks/useLowCode/index.js +74 -0
- package/es/hooks/useStore/index.d.ts +6 -0
- package/es/hooks/useStore/index.js +11 -0
- package/es/index.d.ts +8 -0
- package/es/index.js +10 -0
- package/es/indexDB/index.d.ts +296 -0
- package/es/indexDB/index.js +1619 -0
- package/es/locales/en.d.ts +3 -0
- package/es/locales/en.js +5 -0
- package/es/locales/index.d.ts +39 -0
- package/es/locales/index.js +199 -0
- package/es/locales/original.d.ts +3 -0
- package/es/locales/original.js +7 -0
- package/es/locales/type.d.ts +19 -0
- package/es/locales/type.js +1 -0
- package/es/locales/zh-CN.d.ts +3 -0
- package/es/locales/zh-CN.js +5 -0
- package/es/locales/zh-HK.d.ts +3 -0
- package/es/locales/zh-HK.js +5 -0
- package/es/logger/feishu.d.ts +11 -0
- package/es/logger/feishu.js +50 -0
- package/es/logger/index.d.ts +135 -0
- package/es/logger/index.js +870 -0
- package/es/menuManager/hooks.d.ts +17 -0
- package/es/menuManager/hooks.js +136 -0
- package/es/menuManager/index.d.ts +28 -0
- package/es/menuManager/index.js +165 -0
- package/es/models/global.d.ts +32 -0
- package/es/models/global.js +66 -0
- package/es/models/index.d.ts +45 -0
- package/es/models/index.js +65 -0
- package/es/models/type.d.ts +2 -0
- package/es/models/type.js +1 -0
- package/es/plugin/index.d.ts +0 -0
- package/es/plugin/index.js +0 -0
- package/es/pubsub/example.d.ts +5 -0
- package/es/pubsub/example.js +92 -0
- package/es/pubsub/index.d.ts +73 -0
- package/es/pubsub/index.js +166 -0
- package/es/render/index.d.ts +0 -0
- package/es/render/index.js +0 -0
- package/es/request/cache.d.ts +46 -0
- package/es/request/cache.js +372 -0
- package/es/request/cancelToken.d.ts +38 -0
- package/es/request/cancelToken.js +59 -0
- package/es/request/config.d.ts +3 -0
- package/es/request/config.js +63 -0
- package/es/request/constants.d.ts +2 -0
- package/es/request/constants.js +6 -0
- package/es/request/index.d.ts +24 -0
- package/es/request/index.js +267 -0
- package/es/request/pisell2Request.d.ts +6 -0
- package/es/request/pisell2Request.js +62 -0
- package/es/request/type.d.ts +57 -0
- package/es/request/type.js +10 -0
- package/es/request/utils.d.ts +46 -0
- package/es/request/utils.js +147 -0
- package/es/routes/config.d.ts +7 -0
- package/es/routes/config.js +17 -0
- package/es/routes/index.d.ts +28 -0
- package/es/routes/index.js +151 -0
- package/es/socket/components/SocketMonitorPage.d.ts +6 -0
- package/es/socket/components/SocketMonitorPage.js +485 -0
- package/es/socket/components/index.d.ts +2 -0
- package/es/socket/components/index.js +2 -0
- package/es/socket/constants.d.ts +33 -0
- package/es/socket/constants.js +39 -0
- package/es/socket/events.d.ts +31 -0
- package/es/socket/events.js +19 -0
- package/es/socket/heartbeat.d.ts +66 -0
- package/es/socket/heartbeat.js +184 -0
- package/es/socket/index.d.ts +61 -0
- package/es/socket/index.js +246 -0
- package/es/socket/monitor.d.ts +169 -0
- package/es/socket/monitor.js +448 -0
- package/es/socket/reconnect.d.ts +61 -0
- package/es/socket/reconnect.js +199 -0
- package/es/socket/socket.d.ts +130 -0
- package/es/socket/socket.js +613 -0
- package/es/socket/types.d.ts +85 -0
- package/es/socket/types.js +35 -0
- package/es/storage/index.d.ts +17 -0
- package/es/storage/index.js +46 -0
- package/es/tasks/index.d.ts +127 -0
- package/es/tasks/index.js +1119 -0
- package/es/tasks/scheduledTasksExample.d.ts +61 -0
- package/es/tasks/scheduledTasksExample.js +351 -0
- package/es/tasks/type.d.ts +100 -0
- package/es/tasks/type.js +1 -0
- package/es/tasks/useTasks.d.ts +5 -0
- package/es/tasks/useTasks.js +25 -0
- package/es/type.d.ts +2 -0
- package/es/type.js +1 -0
- package/es/utils/adaptiveThrottle/index.d.ts +36 -0
- package/es/utils/adaptiveThrottle/index.js +136 -0
- package/es/variables/VariablesProvider.d.ts +7 -0
- package/es/variables/VariablesProvider.js +12 -0
- package/es/variables/config.d.ts +3 -0
- package/es/variables/config.js +16 -0
- package/es/variables/index.d.ts +6 -0
- package/es/variables/index.js +5 -0
- package/es/variables/type.d.ts +2 -0
- package/es/variables/type.js +1 -0
- package/es/website/index.d.ts +6 -0
- package/es/website/index.js +65 -0
- package/lib/app/app.d.ts +101 -0
- package/lib/app/app.js +171 -0
- package/lib/app/const.d.ts +4 -0
- package/lib/app/const.js +33 -0
- package/lib/app/index.d.ts +14 -0
- package/lib/app/index.js +76 -0
- package/lib/applicationManager/application.d.ts +197 -0
- package/lib/applicationManager/application.js +280 -0
- package/lib/applicationManager/index.d.ts +19 -0
- package/lib/applicationManager/index.js +88 -0
- package/lib/aws/index.d.ts +16 -0
- package/lib/aws/index.js +67 -0
- package/lib/cmd/const.d.ts +11 -0
- package/lib/cmd/const.js +39 -0
- package/lib/cmd/index.d.ts +13 -0
- package/lib/cmd/index.js +96 -0
- package/lib/cmd/type.d.ts +5 -0
- package/lib/cmd/type.js +17 -0
- package/lib/communicationManager/index.d.ts +59 -0
- package/lib/communicationManager/index.js +102 -0
- package/lib/config.d.ts +3 -0
- package/lib/config.js +36 -0
- package/lib/cookie/index.d.ts +13 -0
- package/lib/cookie/index.js +62 -0
- package/lib/css/global.less +73 -0
- package/lib/css/index.less +31 -0
- package/lib/css/variables.css +84 -0
- package/lib/data/index.d.ts +8 -0
- package/lib/data/index.js +38 -0
- package/lib/history/config.d.ts +24 -0
- package/lib/history/config.js +41 -0
- package/lib/history/index.d.ts +26 -0
- package/lib/history/index.js +99 -0
- package/lib/history/type.d.ts +2 -0
- package/lib/history/type.js +17 -0
- package/lib/hooks/index.d.ts +12 -0
- package/lib/hooks/index.js +44 -0
- package/lib/hooks/useDelayedValue/index.d.ts +2 -0
- package/lib/hooks/useDelayedValue/index.js +36 -0
- package/lib/hooks/useDispatch/index.d.ts +2 -0
- package/lib/hooks/useDispatch/index.js +26 -0
- package/lib/hooks/useLowCode/index.d.ts +13 -0
- package/lib/hooks/useLowCode/index.js +75 -0
- package/lib/hooks/useStore/index.d.ts +6 -0
- package/lib/hooks/useStore/index.js +33 -0
- package/lib/index.d.ts +8 -0
- package/lib/index.js +58 -0
- package/lib/indexDB/index.d.ts +296 -0
- package/lib/indexDB/index.js +767 -0
- package/lib/locales/en.d.ts +3 -0
- package/lib/locales/en.js +29 -0
- package/lib/locales/index.d.ts +39 -0
- package/lib/locales/index.js +159 -0
- package/lib/locales/original.d.ts +3 -0
- package/lib/locales/original.js +31 -0
- package/lib/locales/type.d.ts +19 -0
- package/lib/locales/type.js +17 -0
- package/lib/locales/zh-CN.d.ts +3 -0
- package/lib/locales/zh-CN.js +29 -0
- package/lib/locales/zh-HK.d.ts +3 -0
- package/lib/locales/zh-HK.js +29 -0
- package/lib/logger/feishu.d.ts +11 -0
- package/lib/logger/feishu.js +52 -0
- package/lib/logger/index.d.ts +135 -0
- package/lib/logger/index.js +476 -0
- package/lib/menuManager/hooks.d.ts +17 -0
- package/lib/menuManager/hooks.js +135 -0
- package/lib/menuManager/index.d.ts +28 -0
- package/lib/menuManager/index.js +125 -0
- package/lib/models/global.d.ts +32 -0
- package/lib/models/global.js +62 -0
- package/lib/models/index.d.ts +45 -0
- package/lib/models/index.js +69 -0
- package/lib/models/type.d.ts +2 -0
- package/lib/models/type.js +17 -0
- package/lib/plugin/index.d.ts +0 -0
- package/lib/plugin/index.js +0 -0
- package/lib/pubsub/example.d.ts +5 -0
- package/lib/pubsub/example.js +61 -0
- package/lib/pubsub/index.d.ts +73 -0
- package/lib/pubsub/index.js +141 -0
- package/lib/render/index.d.ts +0 -0
- package/lib/render/index.js +0 -0
- package/lib/request/cache.d.ts +46 -0
- package/lib/request/cache.js +195 -0
- package/lib/request/cancelToken.d.ts +38 -0
- package/lib/request/cancelToken.js +59 -0
- package/lib/request/config.d.ts +3 -0
- package/lib/request/config.js +69 -0
- package/lib/request/constants.d.ts +2 -0
- package/lib/request/constants.js +34 -0
- package/lib/request/index.d.ts +24 -0
- package/lib/request/index.js +210 -0
- package/lib/request/pisell2Request.d.ts +6 -0
- package/lib/request/pisell2Request.js +75 -0
- package/lib/request/type.d.ts +57 -0
- package/lib/request/type.js +36 -0
- package/lib/request/utils.d.ts +46 -0
- package/lib/request/utils.js +113 -0
- package/lib/routes/config.d.ts +7 -0
- package/lib/routes/config.js +50 -0
- package/lib/routes/index.d.ts +28 -0
- package/lib/routes/index.js +121 -0
- package/lib/socket/components/SocketMonitorPage.d.ts +6 -0
- package/lib/socket/components/SocketMonitorPage.js +340 -0
- package/lib/socket/components/index.d.ts +2 -0
- package/lib/socket/components/index.js +39 -0
- package/lib/socket/constants.d.ts +33 -0
- package/lib/socket/constants.js +62 -0
- package/lib/socket/events.d.ts +31 -0
- package/lib/socket/events.js +44 -0
- package/lib/socket/heartbeat.d.ts +66 -0
- package/lib/socket/heartbeat.js +157 -0
- package/lib/socket/index.d.ts +61 -0
- package/lib/socket/index.js +198 -0
- package/lib/socket/monitor.d.ts +169 -0
- package/lib/socket/monitor.js +350 -0
- package/lib/socket/reconnect.d.ts +61 -0
- package/lib/socket/reconnect.js +157 -0
- package/lib/socket/socket.d.ts +130 -0
- package/lib/socket/socket.js +426 -0
- package/lib/socket/types.d.ts +85 -0
- package/lib/socket/types.js +36 -0
- package/lib/storage/index.d.ts +17 -0
- package/lib/storage/index.js +64 -0
- package/lib/tasks/index.d.ts +127 -0
- package/lib/tasks/index.js +710 -0
- package/lib/tasks/scheduledTasksExample.d.ts +61 -0
- package/lib/tasks/scheduledTasksExample.js +267 -0
- package/lib/tasks/type.d.ts +100 -0
- package/lib/tasks/type.js +17 -0
- package/lib/tasks/useTasks.d.ts +5 -0
- package/lib/tasks/useTasks.js +37 -0
- package/lib/type.d.ts +2 -0
- package/lib/type.js +17 -0
- package/lib/utils/adaptiveThrottle/index.d.ts +36 -0
- package/lib/utils/adaptiveThrottle/index.js +121 -0
- package/lib/variables/VariablesProvider.d.ts +7 -0
- package/lib/variables/VariablesProvider.js +51 -0
- package/lib/variables/config.d.ts +3 -0
- package/lib/variables/config.js +38 -0
- package/lib/variables/index.d.ts +6 -0
- package/lib/variables/index.js +29 -0
- package/lib/variables/type.d.ts +2 -0
- package/lib/variables/type.js +17 -0
- package/lib/website/index.d.ts +6 -0
- package/lib/website/index.js +75 -0
- package/package.json +49 -0
|
@@ -0,0 +1,613 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
6
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
8
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
12
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
13
|
+
import { SocketStatus } from "./types";
|
|
14
|
+
import { DEFAULT_HEARTBEAT_MESSAGE, DEFAULT_HEARTBEAT_RESPONSE, DEFAULT_SOCKET_OPTIONS, WS_STATUS_MAP } from "./constants";
|
|
15
|
+
import { SocketEvents } from "./events";
|
|
16
|
+
import { HeartbeatManager } from "./heartbeat";
|
|
17
|
+
import { ReconnectManager } from "./reconnect";
|
|
18
|
+
import { SocketMonitor } from "./monitor";
|
|
19
|
+
import { getApp } from "../app";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Socket主类
|
|
23
|
+
* 负责管理WebSocket连接、消息收发、事件处理、心跳检测和断线重连
|
|
24
|
+
*/
|
|
25
|
+
export var Socket = /*#__PURE__*/function () {
|
|
26
|
+
/**
|
|
27
|
+
* 创建Socket实例
|
|
28
|
+
* @param options Socket配置选项
|
|
29
|
+
*/
|
|
30
|
+
function Socket(options) {
|
|
31
|
+
_classCallCheck(this, Socket);
|
|
32
|
+
_defineProperty(this, "ws", null);
|
|
33
|
+
_defineProperty(this, "url", void 0);
|
|
34
|
+
_defineProperty(this, "options", void 0);
|
|
35
|
+
_defineProperty(this, "status", SocketStatus.CLOSED);
|
|
36
|
+
_defineProperty(this, "eventHandlers", {});
|
|
37
|
+
// 心跳和重连管理器
|
|
38
|
+
_defineProperty(this, "heartbeatManager", null);
|
|
39
|
+
_defineProperty(this, "reconnectManager", null);
|
|
40
|
+
// 监控器
|
|
41
|
+
_defineProperty(this, "monitor", null);
|
|
42
|
+
// 消息ID计数器
|
|
43
|
+
_defineProperty(this, "messageIdCounter", 0);
|
|
44
|
+
this.url = options.url;
|
|
45
|
+
this.options = _objectSpread(_objectSpread({}, DEFAULT_SOCKET_OPTIONS), options);
|
|
46
|
+
|
|
47
|
+
// 如果配置了自动连接,则立即连接
|
|
48
|
+
if (this.options.autoConnect) {
|
|
49
|
+
this.connect().catch(function (error) {
|
|
50
|
+
console.warn("Socket connection failed:", error);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 建立WebSocket连接
|
|
57
|
+
*/
|
|
58
|
+
_createClass(Socket, [{
|
|
59
|
+
key: "connect",
|
|
60
|
+
value: (function () {
|
|
61
|
+
var _connect = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
62
|
+
var _this = this;
|
|
63
|
+
var app, isConnected;
|
|
64
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
65
|
+
while (1) switch (_context.prev = _context.next) {
|
|
66
|
+
case 0:
|
|
67
|
+
app = getApp();
|
|
68
|
+
isConnected = this.isConnected();
|
|
69
|
+
if (!(isConnected || this.status === SocketStatus.CONNECTING)) {
|
|
70
|
+
_context.next = 5;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
app.logger.addLog({
|
|
74
|
+
type: "info",
|
|
75
|
+
title: "socket已连接或连接中",
|
|
76
|
+
metadata: {
|
|
77
|
+
isConnected: isConnected,
|
|
78
|
+
status: this.status
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
return _context.abrupt("return");
|
|
82
|
+
case 5:
|
|
83
|
+
// 设置状态为连接中
|
|
84
|
+
this.setStatus(SocketStatus.CONNECTING);
|
|
85
|
+
_context.prev = 6;
|
|
86
|
+
// 创建WebSocket连接
|
|
87
|
+
this.ws = new WebSocket(this.url, this.options.protocols);
|
|
88
|
+
|
|
89
|
+
// 设置事件监听器
|
|
90
|
+
this.setupWebSocketListeners();
|
|
91
|
+
|
|
92
|
+
// 等待连接打开
|
|
93
|
+
_context.next = 11;
|
|
94
|
+
return new Promise(function (resolve, reject) {
|
|
95
|
+
// 连接超时
|
|
96
|
+
var timeoutId = setTimeout(function () {
|
|
97
|
+
reject(new Error("Connection timeout"));
|
|
98
|
+
}, _this.options.timeout);
|
|
99
|
+
|
|
100
|
+
// 连接成功处理
|
|
101
|
+
var onOpen = function onOpen() {
|
|
102
|
+
clearTimeout(timeoutId);
|
|
103
|
+
resolve();
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// 连接错误处理
|
|
107
|
+
var onError = function onError(error) {
|
|
108
|
+
clearTimeout(timeoutId);
|
|
109
|
+
reject(error);
|
|
110
|
+
};
|
|
111
|
+
_this.ws.addEventListener("open", onOpen, {
|
|
112
|
+
once: true
|
|
113
|
+
});
|
|
114
|
+
_this.ws.addEventListener("error", onError, {
|
|
115
|
+
once: true
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
case 11:
|
|
119
|
+
// 初始化心跳检测
|
|
120
|
+
if (this.options.heartbeat) {
|
|
121
|
+
this.initHeartbeat();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 初始化重连管理
|
|
125
|
+
if (this.options.reconnection) {
|
|
126
|
+
this.initReconnect();
|
|
127
|
+
}
|
|
128
|
+
_context.next = 19;
|
|
129
|
+
break;
|
|
130
|
+
case 15:
|
|
131
|
+
_context.prev = 15;
|
|
132
|
+
_context.t0 = _context["catch"](6);
|
|
133
|
+
// 连接失败,执行重连(如果启用)
|
|
134
|
+
this.handleConnectionFailure(_context.t0);
|
|
135
|
+
throw _context.t0;
|
|
136
|
+
case 19:
|
|
137
|
+
case "end":
|
|
138
|
+
return _context.stop();
|
|
139
|
+
}
|
|
140
|
+
}, _callee, this, [[6, 15]]);
|
|
141
|
+
}));
|
|
142
|
+
function connect() {
|
|
143
|
+
return _connect.apply(this, arguments);
|
|
144
|
+
}
|
|
145
|
+
return connect;
|
|
146
|
+
}()
|
|
147
|
+
/**
|
|
148
|
+
* 关闭WebSocket连接
|
|
149
|
+
* @param isManual 是否手动关闭
|
|
150
|
+
*/
|
|
151
|
+
)
|
|
152
|
+
}, {
|
|
153
|
+
key: "disconnect",
|
|
154
|
+
value: function disconnect() {
|
|
155
|
+
var isManual = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
156
|
+
if (!this.ws || this.status === SocketStatus.CLOSED || this.status === SocketStatus.CLOSING) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// 设置状态为关闭中
|
|
161
|
+
this.setStatus(SocketStatus.CLOSING);
|
|
162
|
+
|
|
163
|
+
// 停止心跳
|
|
164
|
+
if (this.heartbeatManager) {
|
|
165
|
+
this.heartbeatManager.stop();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 停止重连
|
|
169
|
+
if (this.reconnectManager) {
|
|
170
|
+
this.reconnectManager.stopReconnect();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// 关闭WebSocket连接
|
|
174
|
+
try {
|
|
175
|
+
this.ws.close();
|
|
176
|
+
} catch (error) {
|
|
177
|
+
console.error("WebSocket close error:", error);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// 直接设置为已关闭状态,不等待onclose事件
|
|
181
|
+
this.setStatus(SocketStatus.CLOSED);
|
|
182
|
+
this.ws = null;
|
|
183
|
+
|
|
184
|
+
// 触发断开连接事件
|
|
185
|
+
this.emit(SocketEvents.DISCONNECT, {
|
|
186
|
+
isManual: isManual
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 发送消息到服务器
|
|
192
|
+
* @param event 事件名称
|
|
193
|
+
* @param data 消息数据
|
|
194
|
+
* @param id 消息ID(可选,默认自动生成)
|
|
195
|
+
*/
|
|
196
|
+
}, {
|
|
197
|
+
key: "send",
|
|
198
|
+
value: function send(type, data, id) {
|
|
199
|
+
if (!this.isConnected()) {
|
|
200
|
+
throw new Error("WebSocket is not connected");
|
|
201
|
+
}
|
|
202
|
+
var message = {
|
|
203
|
+
type: type,
|
|
204
|
+
data: data,
|
|
205
|
+
id: id || this.generateMessageId()
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
// 发送消息
|
|
209
|
+
this.sendRaw(message);
|
|
210
|
+
|
|
211
|
+
// 触发发送事件
|
|
212
|
+
this.emit(SocketEvents.SEND, message);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 发送原始消息
|
|
217
|
+
* @param message 消息对象
|
|
218
|
+
*/
|
|
219
|
+
}, {
|
|
220
|
+
key: "sendRaw",
|
|
221
|
+
value: function sendRaw(message) {
|
|
222
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
try {
|
|
226
|
+
this.ws.send(JSON.stringify(message));
|
|
227
|
+
} catch (error) {
|
|
228
|
+
console.error("WebSocket send error:", error);
|
|
229
|
+
this.emit(SocketEvents.ERROR, error);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* 注册事件监听器
|
|
235
|
+
* @param event 事件名称
|
|
236
|
+
* @param handler 事件处理函数
|
|
237
|
+
*/
|
|
238
|
+
}, {
|
|
239
|
+
key: "on",
|
|
240
|
+
value: function on(event, handler) {
|
|
241
|
+
if (!this.eventHandlers[event]) {
|
|
242
|
+
this.eventHandlers[event] = [];
|
|
243
|
+
}
|
|
244
|
+
this.eventHandlers[event].push(handler);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 移除事件监听器
|
|
249
|
+
* @param event 事件名称
|
|
250
|
+
* @param handler 事件处理函数(可选,不提供则移除所有该事件的处理函数)
|
|
251
|
+
*/
|
|
252
|
+
}, {
|
|
253
|
+
key: "off",
|
|
254
|
+
value: function off(event, handler) {
|
|
255
|
+
if (!this.eventHandlers[event]) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (!handler) {
|
|
259
|
+
// 移除所有该事件的处理函数
|
|
260
|
+
delete this.eventHandlers[event];
|
|
261
|
+
} else {
|
|
262
|
+
// 移除特定的处理函数
|
|
263
|
+
this.eventHandlers[event] = this.eventHandlers[event].filter(function (h) {
|
|
264
|
+
return h !== handler;
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* 触发事件
|
|
271
|
+
* @param event 事件名称
|
|
272
|
+
* @param args 事件参数
|
|
273
|
+
*/
|
|
274
|
+
}, {
|
|
275
|
+
key: "emit",
|
|
276
|
+
value: function emit(event) {
|
|
277
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
278
|
+
args[_key - 1] = arguments[_key];
|
|
279
|
+
}
|
|
280
|
+
var handlers = this.eventHandlers[event];
|
|
281
|
+
if (handlers) {
|
|
282
|
+
handlers.forEach(function (handler) {
|
|
283
|
+
try {
|
|
284
|
+
handler.apply(void 0, args);
|
|
285
|
+
} catch (error) {
|
|
286
|
+
console.error("Error in event handler for ".concat(event, ":"), error);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* 获取当前连接状态
|
|
294
|
+
*/
|
|
295
|
+
}, {
|
|
296
|
+
key: "getStatus",
|
|
297
|
+
value: function getStatus() {
|
|
298
|
+
return this.status;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* 获取当前状态描述
|
|
303
|
+
*/
|
|
304
|
+
}, {
|
|
305
|
+
key: "getStatusText",
|
|
306
|
+
value: function getStatusText() {
|
|
307
|
+
return WS_STATUS_MAP[this.status] || "未知状态";
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* 检查是否已连接
|
|
312
|
+
*/
|
|
313
|
+
}, {
|
|
314
|
+
key: "isConnected",
|
|
315
|
+
value: function isConnected() {
|
|
316
|
+
return this.ws !== null && this.ws.readyState === WebSocket.OPEN;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 设置连接状态
|
|
321
|
+
*/
|
|
322
|
+
}, {
|
|
323
|
+
key: "setStatus",
|
|
324
|
+
value: function setStatus(status) {
|
|
325
|
+
this.status = status;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* 设置WebSocket事件监听器
|
|
330
|
+
*/
|
|
331
|
+
}, {
|
|
332
|
+
key: "setupWebSocketListeners",
|
|
333
|
+
value: function setupWebSocketListeners() {
|
|
334
|
+
var _this2 = this;
|
|
335
|
+
if (!this.ws) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// 连接打开事件
|
|
340
|
+
this.ws.addEventListener("open", function () {
|
|
341
|
+
_this2.setStatus(SocketStatus.OPEN);
|
|
342
|
+
_this2.emit(SocketEvents.CONNECT);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
// 连接关闭事件
|
|
346
|
+
this.ws.addEventListener("close", function (event) {
|
|
347
|
+
// 只有非主动关闭才触发断开连接事件
|
|
348
|
+
if (_this2.status !== SocketStatus.CLOSING && _this2.status !== SocketStatus.CLOSED) {
|
|
349
|
+
_this2.handleConnectionClosed(event);
|
|
350
|
+
} else {
|
|
351
|
+
_this2.setStatus(SocketStatus.CLOSED);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
// 连接错误事件
|
|
356
|
+
this.ws.addEventListener("error", function (event) {
|
|
357
|
+
_this2.emit(SocketEvents.ERROR, event);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
// 消息接收事件
|
|
361
|
+
this.ws.addEventListener("message", function (event) {
|
|
362
|
+
_this2.handleMessage(event);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* 处理接收到的消息
|
|
368
|
+
*/
|
|
369
|
+
}, {
|
|
370
|
+
key: "handleMessage",
|
|
371
|
+
value: function handleMessage(event) {
|
|
372
|
+
try {
|
|
373
|
+
// 解析消息
|
|
374
|
+
var message = JSON.parse(event.data);
|
|
375
|
+
|
|
376
|
+
// 处理心跳响应
|
|
377
|
+
if (message.type === DEFAULT_HEARTBEAT_RESPONSE) {
|
|
378
|
+
this.handleHeartbeatResponse();
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// 触发消息事件
|
|
383
|
+
this.emit(SocketEvents.MESSAGE, message);
|
|
384
|
+
|
|
385
|
+
// 触发特定类型的消息事件
|
|
386
|
+
this.emit(message.type, message.data);
|
|
387
|
+
} catch (error) {
|
|
388
|
+
console.error("Error parsing message:", error, event.data);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* 处理连接关闭
|
|
394
|
+
*/
|
|
395
|
+
}, {
|
|
396
|
+
key: "handleConnectionClosed",
|
|
397
|
+
value: function handleConnectionClosed(event) {
|
|
398
|
+
// 停止心跳
|
|
399
|
+
if (this.heartbeatManager) {
|
|
400
|
+
this.heartbeatManager.stop();
|
|
401
|
+
}
|
|
402
|
+
this.setStatus(SocketStatus.CLOSED);
|
|
403
|
+
this.ws = null;
|
|
404
|
+
|
|
405
|
+
// 触发断开连接事件
|
|
406
|
+
this.emit(SocketEvents.DISCONNECT, event);
|
|
407
|
+
|
|
408
|
+
// 如果启用了重连,则开始重连
|
|
409
|
+
this.startReconnection();
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* 处理连接失败
|
|
414
|
+
*/
|
|
415
|
+
}, {
|
|
416
|
+
key: "handleConnectionFailure",
|
|
417
|
+
value: function handleConnectionFailure(error) {
|
|
418
|
+
this.setStatus(SocketStatus.CLOSED);
|
|
419
|
+
this.ws = null;
|
|
420
|
+
|
|
421
|
+
// 触发错误事件
|
|
422
|
+
this.emit(SocketEvents.ERROR, error);
|
|
423
|
+
|
|
424
|
+
// 如果启用了重连,则开始重连
|
|
425
|
+
this.startReconnection();
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
/**
|
|
429
|
+
* 处理心跳响应
|
|
430
|
+
*/
|
|
431
|
+
}, {
|
|
432
|
+
key: "handleHeartbeatResponse",
|
|
433
|
+
value: function handleHeartbeatResponse() {
|
|
434
|
+
if (this.heartbeatManager) {
|
|
435
|
+
this.heartbeatManager.receiveHeartbeatResponse();
|
|
436
|
+
this.emit(SocketEvents.HEARTBEAT_RESPONSE);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* 初始化心跳检测
|
|
442
|
+
*/
|
|
443
|
+
}, {
|
|
444
|
+
key: "initHeartbeat",
|
|
445
|
+
value: function initHeartbeat() {
|
|
446
|
+
var _this3 = this;
|
|
447
|
+
if (!this.options.heartbeat) {
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// 创建心跳选项
|
|
452
|
+
var heartbeatOptions = {
|
|
453
|
+
interval: this.options.heartbeatInterval,
|
|
454
|
+
timeout: this.options.heartbeatTimeout,
|
|
455
|
+
message: DEFAULT_HEARTBEAT_MESSAGE
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
// 创建心跳管理器
|
|
459
|
+
this.heartbeatManager = new HeartbeatManager(heartbeatOptions, function (msg) {
|
|
460
|
+
return _this3.sendRaw(msg);
|
|
461
|
+
}, {
|
|
462
|
+
onTimeout: function onTimeout() {
|
|
463
|
+
_this3.emit(SocketEvents.HEARTBEAT_TIMEOUT);
|
|
464
|
+
// 心跳超时,断开连接并重连
|
|
465
|
+
_this3.disconnect();
|
|
466
|
+
_this3.startReconnection();
|
|
467
|
+
},
|
|
468
|
+
onResponse: function onResponse() {
|
|
469
|
+
_this3.emit(SocketEvents.HEARTBEAT_RESPONSE);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
// 启动心跳检测
|
|
474
|
+
this.heartbeatManager.start();
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* 初始化重连管理
|
|
479
|
+
*/
|
|
480
|
+
}, {
|
|
481
|
+
key: "initReconnect",
|
|
482
|
+
value: function initReconnect() {
|
|
483
|
+
var _this4 = this;
|
|
484
|
+
if (!this.options.reconnection) {
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
// 创建重连选项
|
|
489
|
+
var reconnectOptions = {
|
|
490
|
+
enabled: true,
|
|
491
|
+
attempts: this.options.reconnectionAttempts,
|
|
492
|
+
delay: this.options.reconnectionDelay,
|
|
493
|
+
delayMax: this.options.reconnectionDelayMax,
|
|
494
|
+
jitter: false
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
// 创建重连管理器
|
|
498
|
+
this.reconnectManager = new ReconnectManager(reconnectOptions, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
499
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
500
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
501
|
+
case 0:
|
|
502
|
+
_context2.prev = 0;
|
|
503
|
+
_context2.next = 3;
|
|
504
|
+
return _this4.connect();
|
|
505
|
+
case 3:
|
|
506
|
+
return _context2.abrupt("return", true);
|
|
507
|
+
case 6:
|
|
508
|
+
_context2.prev = 6;
|
|
509
|
+
_context2.t0 = _context2["catch"](0);
|
|
510
|
+
return _context2.abrupt("return", false);
|
|
511
|
+
case 9:
|
|
512
|
+
case "end":
|
|
513
|
+
return _context2.stop();
|
|
514
|
+
}
|
|
515
|
+
}, _callee2, null, [[0, 6]]);
|
|
516
|
+
})), {
|
|
517
|
+
onAttempt: function onAttempt(attempt) {
|
|
518
|
+
_this4.emit(SocketEvents.RECONNECT_ATTEMPT, attempt);
|
|
519
|
+
},
|
|
520
|
+
onSuccess: function onSuccess() {
|
|
521
|
+
_this4.emit(SocketEvents.RECONNECT);
|
|
522
|
+
},
|
|
523
|
+
onFail: function onFail(error) {
|
|
524
|
+
_this4.emit(SocketEvents.RECONNECT_ERROR, error);
|
|
525
|
+
},
|
|
526
|
+
onMaxAttemptsExceeded: function onMaxAttemptsExceeded() {
|
|
527
|
+
_this4.emit(SocketEvents.RECONNECT_FAILED);
|
|
528
|
+
}
|
|
529
|
+
});
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* 开始重连过程
|
|
534
|
+
*/
|
|
535
|
+
}, {
|
|
536
|
+
key: "startReconnection",
|
|
537
|
+
value: function startReconnection() {
|
|
538
|
+
if (this.reconnectManager && this.options.reconnection) {
|
|
539
|
+
this.setStatus(SocketStatus.RECONNECTING);
|
|
540
|
+
this.reconnectManager.startReconnect();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* 生成消息ID
|
|
546
|
+
*/
|
|
547
|
+
}, {
|
|
548
|
+
key: "generateMessageId",
|
|
549
|
+
value: function generateMessageId() {
|
|
550
|
+
this.messageIdCounter++;
|
|
551
|
+
return "msg_".concat(Date.now(), "_").concat(this.messageIdCounter);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* 启用监控功能
|
|
556
|
+
* @param options 监控配置选项
|
|
557
|
+
*/
|
|
558
|
+
}, {
|
|
559
|
+
key: "enableMonitoring",
|
|
560
|
+
value: function enableMonitoring(options) {
|
|
561
|
+
if (!this.monitor) {
|
|
562
|
+
this.monitor = new SocketMonitor(this, options);
|
|
563
|
+
} else if (!this.monitor.isActive()) {
|
|
564
|
+
this.monitor.start();
|
|
565
|
+
}
|
|
566
|
+
return this.monitor;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* 禁用监控功能
|
|
571
|
+
*/
|
|
572
|
+
}, {
|
|
573
|
+
key: "disableMonitoring",
|
|
574
|
+
value: function disableMonitoring() {
|
|
575
|
+
if (this.monitor) {
|
|
576
|
+
this.monitor.stop();
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
/**
|
|
581
|
+
* 获取监控器实例
|
|
582
|
+
*/
|
|
583
|
+
}, {
|
|
584
|
+
key: "getMonitor",
|
|
585
|
+
value: function getMonitor() {
|
|
586
|
+
return this.monitor;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* 释放资源
|
|
591
|
+
*/
|
|
592
|
+
}, {
|
|
593
|
+
key: "destroy",
|
|
594
|
+
value: function destroy() {
|
|
595
|
+
// 断开连接
|
|
596
|
+
this.disconnect(true);
|
|
597
|
+
|
|
598
|
+
// 停止监控
|
|
599
|
+
if (this.monitor) {
|
|
600
|
+
this.monitor.destroy();
|
|
601
|
+
this.monitor = null;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// 清空事件处理函数
|
|
605
|
+
this.eventHandlers = {};
|
|
606
|
+
|
|
607
|
+
// 清空引用
|
|
608
|
+
this.heartbeatManager = null;
|
|
609
|
+
this.reconnectManager = null;
|
|
610
|
+
}
|
|
611
|
+
}]);
|
|
612
|
+
return Socket;
|
|
613
|
+
}();
|