@equinor/echo-framework 0.9.11 → 0.9.14

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.
Files changed (182) hide show
  1. package/dist/components/appLinks/applinkUtils.d.ts +2 -0
  2. package/dist/components/appLinks/applinkUtils.test.d.ts +1 -0
  3. package/dist/index.js +3 -0
  4. package/package.json +42 -39
  5. package/dist/_virtual/_tslib.js +0 -67
  6. package/dist/node_modules/@babel/runtime/helpers/esm/extends.js +0 -25
  7. package/dist/node_modules/@equinor/eds-icons/dist/icons.esm.js +0 -5285
  8. package/dist/node_modules/@microsoft/signalr/dist/esm/AbortController.js +0 -54
  9. package/dist/node_modules/@microsoft/signalr/dist/esm/DefaultHttpClient.js +0 -96
  10. package/dist/node_modules/@microsoft/signalr/dist/esm/DefaultReconnectPolicy.js +0 -47
  11. package/dist/node_modules/@microsoft/signalr/dist/esm/Errors.js +0 -287
  12. package/dist/node_modules/@microsoft/signalr/dist/esm/FetchHttpClient.js +0 -283
  13. package/dist/node_modules/@microsoft/signalr/dist/esm/HandshakeProtocol.js +0 -86
  14. package/dist/node_modules/@microsoft/signalr/dist/esm/HeaderNames.js +0 -20
  15. package/dist/node_modules/@microsoft/signalr/dist/esm/HttpClient.js +0 -82
  16. package/dist/node_modules/@microsoft/signalr/dist/esm/HttpConnection.js +0 -1169
  17. package/dist/node_modules/@microsoft/signalr/dist/esm/HubConnection.js +0 -1346
  18. package/dist/node_modules/@microsoft/signalr/dist/esm/HubConnectionBuilder.js +0 -165
  19. package/dist/node_modules/@microsoft/signalr/dist/esm/IHubProtocol.js +0 -33
  20. package/dist/node_modules/@microsoft/signalr/dist/esm/ILogger.js +0 -37
  21. package/dist/node_modules/@microsoft/signalr/dist/esm/ITransport.js +0 -37
  22. package/dist/node_modules/@microsoft/signalr/dist/esm/JsonHubProtocol.js +0 -179
  23. package/dist/node_modules/@microsoft/signalr/dist/esm/Loggers.js +0 -35
  24. package/dist/node_modules/@microsoft/signalr/dist/esm/LongPollingTransport.js +0 -448
  25. package/dist/node_modules/@microsoft/signalr/dist/esm/ServerSentEventsTransport.js +0 -238
  26. package/dist/node_modules/@microsoft/signalr/dist/esm/Subject.js +0 -99
  27. package/dist/node_modules/@microsoft/signalr/dist/esm/TextMessageFormat.js +0 -45
  28. package/dist/node_modules/@microsoft/signalr/dist/esm/Utils.js +0 -435
  29. package/dist/node_modules/@microsoft/signalr/dist/esm/WebSocketTransport.js +0 -264
  30. package/dist/node_modules/@microsoft/signalr/dist/esm/XhrHttpClient.js +0 -133
  31. package/dist/node_modules/history/esm/history.js +0 -498
  32. package/dist/node_modules/resolve-pathname/esm/resolve-pathname.js +0 -73
  33. package/dist/node_modules/style-inject/dist/style-inject.es.js +0 -36
  34. package/dist/node_modules/tiny-invariant/dist/tiny-invariant.esm.js +0 -23
  35. package/dist/node_modules/tiny-warning/dist/tiny-warning.esm.js +0 -26
  36. package/dist/src/components/appLinks/AppLinks.js +0 -38
  37. package/dist/src/components/appLinks/AppLinks.module.css.js +0 -14
  38. package/dist/src/components/appLinks/linkButton/linkButton.js +0 -45
  39. package/dist/src/components/containers/layout.module.css.js +0 -25
  40. package/dist/src/components/containers/layouts.js +0 -62
  41. package/dist/src/components/contextualAppLinks/contextualAppLinks.context.js +0 -20
  42. package/dist/src/components/contextualAppLinks/contextualAppLinks.js +0 -47
  43. package/dist/src/components/contextualAppLinks/externalAppsMenu.js +0 -157
  44. package/dist/src/components/contextualAppLinks/externalAppsMenu.module.css.js +0 -16
  45. package/dist/src/components/contextualAppLinks/externalLinkButtons/allExternalLinks.js +0 -127
  46. package/dist/src/components/contextualAppLinks/externalLinkButtons/externalLinkButtons.helpers.js +0 -169
  47. package/dist/src/components/contextualAppLinks/externalLinkButtons/externalLinkToCommApp.js +0 -95
  48. package/dist/src/components/contextualAppLinks/externalLinkButtons/externalLinkToMcApp.js +0 -95
  49. package/dist/src/components/contextualAppLinks/externalLinkButtons/externalLinkToProCoSys.js +0 -84
  50. package/dist/src/components/contextualAppLinks/externalLinkButtons/externalLinkToSafeX.js +0 -38
  51. package/dist/src/components/contextualAppLinks/externalLinkButtons/externalLinkToSap.js +0 -110
  52. package/dist/src/components/contextualAppLinks/externalLinkButtons/externalLinkToSemiDoc.js +0 -59
  53. package/dist/src/components/contextualAppLinks/externalLinkButtons/externalLinkToStid.js +0 -40
  54. package/dist/src/components/contextualAppLinks/externalLinkButtons/externalLinkToTr2000.js +0 -114
  55. package/dist/src/components/contextualAppLinks/externalLinkButtons/iconButtonSpinner.js +0 -44
  56. package/dist/src/components/contextualAppLinks/externalLinkButtons/iconButtonSpinner.module.css.js +0 -15
  57. package/dist/src/components/contextualAppLinks/hooks/useContextualAppLinks.js +0 -52
  58. package/dist/src/components/contextualAppLinks/hooks/useContextualAppLinksContext.js +0 -36
  59. package/dist/src/components/contextualAppLinks/index.js +0 -22
  60. package/dist/src/components/contextualAppLinks/internalAppLinks.js +0 -115
  61. package/dist/src/components/contextualAppLinks/linkButton.js +0 -57
  62. package/dist/src/components/echoLogo/echoLogo.js +0 -30
  63. package/dist/src/components/echoLogo/echoLogo.module.css.js +0 -15
  64. package/dist/src/components/errorBoundary/components/chunkLoadErrorMessage.js +0 -64
  65. package/dist/src/components/errorBoundary/components/chunkLoadErrorMessage.module.css.js +0 -17
  66. package/dist/src/components/errorBoundary/components/errorBoundaryBaseMessage.js +0 -85
  67. package/dist/src/components/errorBoundary/components/errorBoundaryBaseMessage.module.css.js +0 -19
  68. package/dist/src/components/errorBoundary/components/notificationCardWithLogo.js +0 -55
  69. package/dist/src/components/errorBoundary/components/notificationCardWithLogo.module.css.js +0 -19
  70. package/dist/src/components/errorBoundary/errorBoundary.js +0 -100
  71. package/dist/src/components/externalLinkButton/externalLinkButton.js +0 -310
  72. package/dist/src/components/externalLinkButton/externalLinkButton.module.css.js +0 -23
  73. package/dist/src/components/footer/footer.js +0 -42
  74. package/dist/src/components/footer/footer.module.css.js +0 -17
  75. package/dist/src/components/lazyLoading/appLoadingIndicator.js +0 -34
  76. package/dist/src/components/lazyLoading/appLoadingIndicator.module.css.js +0 -15
  77. package/dist/src/components/lazyLoading/lazyLoadedAppWrapper.js +0 -40
  78. package/dist/src/components/mediator/mediator.js +0 -32
  79. package/dist/src/components/pageMenu/Navigation/applicationList.js +0 -35
  80. package/dist/src/components/pageMenu/Navigation/applicationList.module.css.js +0 -17
  81. package/dist/src/components/pageMenu/accordionItem.module.css.js +0 -16
  82. package/dist/src/components/pageMenu/defaultAccordionItem.js +0 -61
  83. package/dist/src/components/pageMenu/pageMenu.js +0 -141
  84. package/dist/src/components/pageMenu/pageMenu.module.css.js +0 -17
  85. package/dist/src/components/pageMenu/pageMenuDrawerItem.js +0 -77
  86. package/dist/src/components/pageMenu/pageMenuDrawerItem.module.css.js +0 -20
  87. package/dist/src/components/pageMenu/settings/asset.js +0 -40
  88. package/dist/src/components/pageMenu/settings/profile.js +0 -62
  89. package/dist/src/components/pageMenu/settings/settings.js +0 -41
  90. package/dist/src/components/pageMenu/settings/settings.module.css.js +0 -25
  91. package/dist/src/components/pageMenu/version/version.js +0 -88
  92. package/dist/src/components/pageMenu/version/version.module.css.js +0 -14
  93. package/dist/src/components/panel/corePanelIcon.js +0 -31
  94. package/dist/src/components/panel/corePanelLeft.js +0 -91
  95. package/dist/src/components/panel/corePanelLeft.module.css.js +0 -19
  96. package/dist/src/components/panel/corePanelRight.js +0 -95
  97. package/dist/src/components/panel/corePanelRight.module.css.js +0 -18
  98. package/dist/src/components/panelButton/panelButton.js +0 -124
  99. package/dist/src/components/panelButton/panelButton.module.css.js +0 -25
  100. package/dist/src/components/plantSelector/plantSelector.js +0 -137
  101. package/dist/src/components/projectSelector/ProcosysProjectSelector.js +0 -115
  102. package/dist/src/components/projectSelector/ProcosysProjectSelector.module.css.js +0 -14
  103. package/dist/src/components/realTimeData/RealTimePopoverButton.js +0 -168
  104. package/dist/src/components/realTimeData/components/IMSDropdown/RealTimeIMSDropdown.js +0 -83
  105. package/dist/src/components/realTimeData/components/IMSDropdown/RealTimeIMSDropdown.module.css.js +0 -15
  106. package/dist/src/components/realTimeData/components/connectorForIMSTag/IMSConnector.module.css.js +0 -17
  107. package/dist/src/components/realTimeData/components/connectorForIMSTag/RealTimeConnectorForIMSTag.js +0 -149
  108. package/dist/src/components/realTimeData/components/contextButton/RealTimeContextButton.js +0 -75
  109. package/dist/src/components/realTimeData/components/contextButton/RealTimeContextButton.module.css.js +0 -15
  110. package/dist/src/components/realTimeData/components/contextPopover/Popover.js +0 -37
  111. package/dist/src/components/realTimeData/components/contextPopover/Popover.module.css.js +0 -15
  112. package/dist/src/components/realTimeData/hooks/useRealTimeHub.js +0 -124
  113. package/dist/src/components/realTimeData/hooks/useSignalR.js +0 -175
  114. package/dist/src/components/realTimeData/hooks/useSignalRListener.js +0 -22
  115. package/dist/src/components/router/echoRoute.js +0 -45
  116. package/dist/src/components/router/echoRouter.js +0 -30
  117. package/dist/src/components/router/echoWrapper.js +0 -33
  118. package/dist/src/components/router/routes.js +0 -46
  119. package/dist/src/components/router/useLayout.js +0 -32
  120. package/dist/src/components/searchMenu/searchMenu.js +0 -46
  121. package/dist/src/components/searchMenu/searchMenu.module.css.js +0 -16
  122. package/dist/src/components/tagNumber/tagNo.module.css.js +0 -14
  123. package/dist/src/components/tagNumber/tagNumber.js +0 -38
  124. package/dist/src/components/toaster/toaster.js +0 -43
  125. package/dist/src/components/toaster/toaster.module.css.js +0 -15
  126. package/dist/src/components/toaster/toasters.js +0 -101
  127. package/dist/src/coreApplication/EchoContent.js +0 -32
  128. package/dist/src/coreApplication/EchoContentPanels.js +0 -40
  129. package/dist/src/coreApplication/EchoEventHandler.js +0 -79
  130. package/dist/src/coreApplication/EchoEventHandler.module.css.js +0 -14
  131. package/dist/src/globalStyles.css.js +0 -6
  132. package/dist/src/hooks/hookLibrary.js +0 -86
  133. package/dist/src/hooks/index.js +0 -12
  134. package/dist/src/hooks/useEchoHistory.js +0 -38
  135. package/dist/src/hooks/useLongPress.js +0 -37
  136. package/dist/src/hooks/useSemi.js +0 -100
  137. package/dist/src/hooks/useTagDetails.js +0 -153
  138. package/dist/src/icons/common/CommissionApp-icon.png.js +0 -7
  139. package/dist/src/icons/common/Evision.svg.js +0 -68
  140. package/dist/src/icons/common/Fusion.svg.js +0 -111
  141. package/dist/src/icons/common/McApp.svg.js +0 -70
  142. package/dist/src/icons/common/Notification.svg.js +0 -81
  143. package/dist/src/icons/common/ProCoSysIcon.svg.js +0 -68
  144. package/dist/src/icons/common/Robim.svg.js +0 -66
  145. package/dist/src/icons/common/SX-logo.png.js +0 -7
  146. package/dist/src/icons/common/SapLogo.svg.js +0 -95
  147. package/dist/src/icons/common/SemiIcon.svg.js +0 -82
  148. package/dist/src/icons/common/Stid.svg.js +0 -65
  149. package/dist/src/icons/common/TR2000.svg.js +0 -73
  150. package/dist/src/icons/common/WorkOrder.svg.js +0 -71
  151. package/dist/src/icons/common/Yammer.svg.js +0 -65
  152. package/dist/src/icons/common/satos-logo.png.js +0 -7
  153. package/dist/src/icons/edsIons.js +0 -15
  154. package/dist/src/icons/equinor-logo.js +0 -62
  155. package/dist/src/icons/logo_ee.js +0 -37
  156. package/dist/src/icons/search.js +0 -35
  157. package/dist/src/index.js +0 -209
  158. package/dist/src/index2.js +0 -201
  159. package/dist/src/services/api/api-manager.js +0 -190
  160. package/dist/src/services/api/api-plantinfo.js +0 -196
  161. package/dist/src/services/api/api-plants.js +0 -75
  162. package/dist/src/services/api/api-realtimedata.js +0 -55
  163. package/dist/src/services/api/api-tag-details.js +0 -69
  164. package/dist/src/services/api/api-tags.js +0 -88
  165. package/dist/src/services/api/api-version.js +0 -124
  166. package/dist/src/services/componentRegistry/componentRegistry.js +0 -69
  167. package/dist/src/services/echopediaAnalyticsModule/echopediaAnalyticsModule.js +0 -10
  168. package/dist/src/services/eventCallbacks/plantChanged.js +0 -42
  169. package/dist/src/services/eventHubActions/toastActions.js +0 -18
  170. package/dist/src/theme/themeConst.js +0 -75
  171. package/dist/src/types/extensions.js +0 -10
  172. package/dist/src/types/legend.js +0 -58
  173. package/dist/src/types/pingableSources.js +0 -11
  174. package/dist/src/utils/copyText.js +0 -67
  175. package/dist/src/utils/eventHandlerUtils.js +0 -11
  176. package/dist/src/utils/legendUtils.js +0 -168
  177. package/dist/src/utils/navigationUtils.js +0 -28
  178. package/dist/src/utils/plantInfo.js +0 -535
  179. package/dist/src/utils/plantsDataUtils.js +0 -35
  180. package/dist/src/utils/projectSelectorUtils.js +0 -19
  181. package/dist/src/utils/startup.js +0 -89
  182. package/dist/src/utils/taskCache.js +0 -89
@@ -1,1346 +0,0 @@
1
- 'use strict';
2
-
3
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
-
5
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
6
-
7
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
-
9
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
-
11
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
-
13
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
14
-
15
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
16
-
17
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
-
19
- 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 exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
20
-
21
- 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); } }
22
-
23
- 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); }); }; }
24
-
25
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
26
-
27
- 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, descriptor.key, descriptor); } }
28
-
29
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
30
-
31
- Object.defineProperty(exports, '__esModule', {
32
- value: true
33
- });
34
-
35
- var HandshakeProtocol = require('./HandshakeProtocol.js');
36
-
37
- var IHubProtocol = require('./IHubProtocol.js');
38
-
39
- var ILogger = require('./ILogger.js');
40
-
41
- var Subject = require('./Subject.js');
42
-
43
- var Utils = require('./Utils.js'); // Licensed to the .NET Foundation under one or more agreements.
44
-
45
-
46
- var DEFAULT_TIMEOUT_IN_MS = 30 * 1000;
47
- var DEFAULT_PING_INTERVAL_IN_MS = 15 * 1000;
48
- /** Describes the current state of the {@link HubConnection} to the server. */
49
-
50
- exports.HubConnectionState = void 0;
51
-
52
- (function (HubConnectionState) {
53
- /** The hub connection is disconnected. */
54
- HubConnectionState["Disconnected"] = "Disconnected";
55
- /** The hub connection is connecting. */
56
-
57
- HubConnectionState["Connecting"] = "Connecting";
58
- /** The hub connection is connected. */
59
-
60
- HubConnectionState["Connected"] = "Connected";
61
- /** The hub connection is disconnecting. */
62
-
63
- HubConnectionState["Disconnecting"] = "Disconnecting";
64
- /** The hub connection is reconnecting. */
65
-
66
- HubConnectionState["Reconnecting"] = "Reconnecting";
67
- })(exports.HubConnectionState || (exports.HubConnectionState = {}));
68
- /** Represents a connection to a SignalR Hub. */
69
-
70
-
71
- var HubConnection = /*#__PURE__*/function () {
72
- function HubConnection(connection, logger, protocol, reconnectPolicy) {
73
- var _this = this;
74
-
75
- _classCallCheck(this, HubConnection);
76
-
77
- this._nextKeepAlive = 0;
78
-
79
- this._freezeEventListener = function () {
80
- _this._logger.log(ILogger.LogLevel.Warning, "The page is being frozen, this will likely lead to the connection being closed and messages being lost. For more information see the docs at https://docs.microsoft.com/aspnet/core/signalr/javascript-client#bsleep");
81
- };
82
-
83
- Utils.Arg.isRequired(connection, "connection");
84
- Utils.Arg.isRequired(logger, "logger");
85
- Utils.Arg.isRequired(protocol, "protocol");
86
- this.serverTimeoutInMilliseconds = DEFAULT_TIMEOUT_IN_MS;
87
- this.keepAliveIntervalInMilliseconds = DEFAULT_PING_INTERVAL_IN_MS;
88
- this._logger = logger;
89
- this._protocol = protocol;
90
- this.connection = connection;
91
- this._reconnectPolicy = reconnectPolicy;
92
- this._handshakeProtocol = new HandshakeProtocol.HandshakeProtocol();
93
-
94
- this.connection.onreceive = function (data) {
95
- return _this._processIncomingData(data);
96
- };
97
-
98
- this.connection.onclose = function (error) {
99
- return _this._connectionClosed(error);
100
- };
101
-
102
- this._callbacks = {};
103
- this._methods = {};
104
- this._closedCallbacks = [];
105
- this._reconnectingCallbacks = [];
106
- this._reconnectedCallbacks = [];
107
- this._invocationId = 0;
108
- this._receivedHandshakeResponse = false;
109
- this._connectionState = exports.HubConnectionState.Disconnected;
110
- this._connectionStarted = false;
111
- this._cachedPingMessage = this._protocol.writeMessage({
112
- type: IHubProtocol.MessageType.Ping
113
- });
114
- }
115
- /** @internal */
116
- // Using a public static factory method means we can have a private constructor and an _internal_
117
- // create method that can be used by HubConnectionBuilder. An "internal" constructor would just
118
- // be stripped away and the '.d.ts' file would have no constructor, which is interpreted as a
119
- // public parameter-less constructor.
120
-
121
-
122
- _createClass(HubConnection, [{
123
- key: "state",
124
- get:
125
- /** Indicates the state of the {@link HubConnection} to the server. */
126
- function get() {
127
- return this._connectionState;
128
- }
129
- /** Represents the connection id of the {@link HubConnection} on the server. The connection id will be null when the connection is either
130
- * in the disconnected state or if the negotiation step was skipped.
131
- */
132
-
133
- }, {
134
- key: "connectionId",
135
- get: function get() {
136
- return this.connection ? this.connection.connectionId || null : null;
137
- }
138
- /** Indicates the url of the {@link HubConnection} to the server. */
139
-
140
- }, {
141
- key: "baseUrl",
142
- get: function get() {
143
- return this.connection.baseUrl || "";
144
- }
145
- /**
146
- * Sets a new url for the HubConnection. Note that the url can only be changed when the connection is in either the Disconnected or
147
- * Reconnecting states.
148
- * @param {string} url The url to connect to.
149
- */
150
- ,
151
- set: function set(url) {
152
- if (this._connectionState !== exports.HubConnectionState.Disconnected && this._connectionState !== exports.HubConnectionState.Reconnecting) {
153
- throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url.");
154
- }
155
-
156
- if (!url) {
157
- throw new Error("The HubConnection url must be a valid url.");
158
- }
159
-
160
- this.connection.baseUrl = url;
161
- }
162
- /** Starts the connection.
163
- *
164
- * @returns {Promise<void>} A Promise that resolves when the connection has been successfully established, or rejects with an error.
165
- */
166
-
167
- }, {
168
- key: "start",
169
- value: function start() {
170
- this._startPromise = this._startWithStateTransitions();
171
- return this._startPromise;
172
- }
173
- }, {
174
- key: "_startWithStateTransitions",
175
- value: function () {
176
- var _startWithStateTransitions2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
177
- return _regeneratorRuntime().wrap(function _callee$(_context) {
178
- while (1) {
179
- switch (_context.prev = _context.next) {
180
- case 0:
181
- if (!(this._connectionState !== exports.HubConnectionState.Disconnected)) {
182
- _context.next = 2;
183
- break;
184
- }
185
-
186
- return _context.abrupt("return", Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state.")));
187
-
188
- case 2:
189
- this._connectionState = exports.HubConnectionState.Connecting;
190
-
191
- this._logger.log(ILogger.LogLevel.Debug, "Starting HubConnection.");
192
-
193
- _context.prev = 4;
194
- _context.next = 7;
195
- return this._startInternal();
196
-
197
- case 7:
198
- if (Utils.Platform.isBrowser) {
199
- // Log when the browser freezes the tab so users know why their connection unexpectedly stopped working
200
- window.document.addEventListener("freeze", this._freezeEventListener);
201
- }
202
-
203
- this._connectionState = exports.HubConnectionState.Connected;
204
- this._connectionStarted = true;
205
-
206
- this._logger.log(ILogger.LogLevel.Debug, "HubConnection connected successfully.");
207
-
208
- _context.next = 18;
209
- break;
210
-
211
- case 13:
212
- _context.prev = 13;
213
- _context.t0 = _context["catch"](4);
214
- this._connectionState = exports.HubConnectionState.Disconnected;
215
-
216
- this._logger.log(ILogger.LogLevel.Debug, "HubConnection failed to start successfully because of error '".concat(_context.t0, "'."));
217
-
218
- return _context.abrupt("return", Promise.reject(_context.t0));
219
-
220
- case 18:
221
- case "end":
222
- return _context.stop();
223
- }
224
- }
225
- }, _callee, this, [[4, 13]]);
226
- }));
227
-
228
- function _startWithStateTransitions() {
229
- return _startWithStateTransitions2.apply(this, arguments);
230
- }
231
-
232
- return _startWithStateTransitions;
233
- }()
234
- }, {
235
- key: "_startInternal",
236
- value: function () {
237
- var _startInternal2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
238
- var _this2 = this;
239
-
240
- var handshakePromise, handshakeRequest;
241
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
242
- while (1) {
243
- switch (_context2.prev = _context2.next) {
244
- case 0:
245
- this._stopDuringStartError = undefined;
246
- this._receivedHandshakeResponse = false; // Set up the promise before any connection is (re)started otherwise it could race with received messages
247
-
248
- handshakePromise = new Promise(function (resolve, reject) {
249
- _this2._handshakeResolver = resolve;
250
- _this2._handshakeRejecter = reject;
251
- });
252
- _context2.next = 5;
253
- return this.connection.start(this._protocol.transferFormat);
254
-
255
- case 5:
256
- _context2.prev = 5;
257
- handshakeRequest = {
258
- protocol: this._protocol.name,
259
- version: this._protocol.version
260
- };
261
-
262
- this._logger.log(ILogger.LogLevel.Debug, "Sending handshake request.");
263
-
264
- _context2.next = 10;
265
- return this._sendMessage(this._handshakeProtocol.writeHandshakeRequest(handshakeRequest));
266
-
267
- case 10:
268
- this._logger.log(ILogger.LogLevel.Information, "Using HubProtocol '".concat(this._protocol.name, "'.")); // defensively cleanup timeout in case we receive a message from the server before we finish start
269
-
270
-
271
- this._cleanupTimeout();
272
-
273
- this._resetTimeoutPeriod();
274
-
275
- this._resetKeepAliveInterval();
276
-
277
- _context2.next = 16;
278
- return handshakePromise;
279
-
280
- case 16:
281
- if (!this._stopDuringStartError) {
282
- _context2.next = 18;
283
- break;
284
- }
285
-
286
- throw this._stopDuringStartError;
287
-
288
- case 18:
289
- _context2.next = 28;
290
- break;
291
-
292
- case 20:
293
- _context2.prev = 20;
294
- _context2.t0 = _context2["catch"](5);
295
-
296
- this._logger.log(ILogger.LogLevel.Debug, "Hub handshake failed with error '".concat(_context2.t0, "' during start(). Stopping HubConnection."));
297
-
298
- this._cleanupTimeout();
299
-
300
- this._cleanupPingTimer(); // HttpConnection.stop() should not complete until after the onclose callback is invoked.
301
- // This will transition the HubConnection to the disconnected state before HttpConnection.stop() completes.
302
-
303
-
304
- _context2.next = 27;
305
- return this.connection.stop(_context2.t0);
306
-
307
- case 27:
308
- throw _context2.t0;
309
-
310
- case 28:
311
- case "end":
312
- return _context2.stop();
313
- }
314
- }
315
- }, _callee2, this, [[5, 20]]);
316
- }));
317
-
318
- function _startInternal() {
319
- return _startInternal2.apply(this, arguments);
320
- }
321
-
322
- return _startInternal;
323
- }()
324
- /** Stops the connection.
325
- *
326
- * @returns {Promise<void>} A Promise that resolves when the connection has been successfully terminated, or rejects with an error.
327
- */
328
-
329
- }, {
330
- key: "stop",
331
- value: function () {
332
- var _stop = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
333
- var startPromise;
334
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
335
- while (1) {
336
- switch (_context3.prev = _context3.next) {
337
- case 0:
338
- // Capture the start promise before the connection might be restarted in an onclose callback.
339
- startPromise = this._startPromise;
340
- this._stopPromise = this._stopInternal();
341
- _context3.next = 4;
342
- return this._stopPromise;
343
-
344
- case 4:
345
- _context3.prev = 4;
346
- _context3.next = 7;
347
- return startPromise;
348
-
349
- case 7:
350
- _context3.next = 11;
351
- break;
352
-
353
- case 9:
354
- _context3.prev = 9;
355
- _context3.t0 = _context3["catch"](4);
356
-
357
- case 11:
358
- case "end":
359
- return _context3.stop();
360
- }
361
- }
362
- }, _callee3, this, [[4, 9]]);
363
- }));
364
-
365
- function stop() {
366
- return _stop.apply(this, arguments);
367
- }
368
-
369
- return stop;
370
- }()
371
- }, {
372
- key: "_stopInternal",
373
- value: function _stopInternal(error) {
374
- if (this._connectionState === exports.HubConnectionState.Disconnected) {
375
- this._logger.log(ILogger.LogLevel.Debug, "Call to HubConnection.stop(".concat(error, ") ignored because it is already in the disconnected state."));
376
-
377
- return Promise.resolve();
378
- }
379
-
380
- if (this._connectionState === exports.HubConnectionState.Disconnecting) {
381
- this._logger.log(ILogger.LogLevel.Debug, "Call to HttpConnection.stop(".concat(error, ") ignored because the connection is already in the disconnecting state."));
382
-
383
- return this._stopPromise;
384
- }
385
-
386
- this._connectionState = exports.HubConnectionState.Disconnecting;
387
-
388
- this._logger.log(ILogger.LogLevel.Debug, "Stopping HubConnection.");
389
-
390
- if (this._reconnectDelayHandle) {
391
- // We're in a reconnect delay which means the underlying connection is currently already stopped.
392
- // Just clear the handle to stop the reconnect loop (which no one is waiting on thankfully) and
393
- // fire the onclose callbacks.
394
- this._logger.log(ILogger.LogLevel.Debug, "Connection stopped during reconnect delay. Done reconnecting.");
395
-
396
- clearTimeout(this._reconnectDelayHandle);
397
- this._reconnectDelayHandle = undefined;
398
-
399
- this._completeClose();
400
-
401
- return Promise.resolve();
402
- }
403
-
404
- this._cleanupTimeout();
405
-
406
- this._cleanupPingTimer();
407
-
408
- this._stopDuringStartError = error || new Error("The connection was stopped before the hub handshake could complete."); // HttpConnection.stop() should not complete until after either HttpConnection.start() fails
409
- // or the onclose callback is invoked. The onclose callback will transition the HubConnection
410
- // to the disconnected state if need be before HttpConnection.stop() completes.
411
-
412
- return this.connection.stop(error);
413
- }
414
- /** Invokes a streaming hub method on the server using the specified name and arguments.
415
- *
416
- * @typeparam T The type of the items returned by the server.
417
- * @param {string} methodName The name of the server method to invoke.
418
- * @param {any[]} args The arguments used to invoke the server method.
419
- * @returns {IStreamResult<T>} An object that yields results from the server as they are received.
420
- */
421
-
422
- }, {
423
- key: "stream",
424
- value: function stream(methodName) {
425
- var _this3 = this;
426
-
427
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
428
- args[_key - 1] = arguments[_key];
429
- }
430
-
431
- var _this$_replaceStreami = this._replaceStreamingParams(args),
432
- _this$_replaceStreami2 = _slicedToArray(_this$_replaceStreami, 2),
433
- streams = _this$_replaceStreami2[0],
434
- streamIds = _this$_replaceStreami2[1];
435
-
436
- var invocationDescriptor = this._createStreamInvocation(methodName, args, streamIds); // eslint-disable-next-line prefer-const
437
-
438
-
439
- var promiseQueue;
440
- var subject = new Subject.Subject();
441
-
442
- subject.cancelCallback = function () {
443
- var cancelInvocation = _this3._createCancelInvocation(invocationDescriptor.invocationId);
444
-
445
- delete _this3._callbacks[invocationDescriptor.invocationId];
446
- return promiseQueue.then(function () {
447
- return _this3._sendWithProtocol(cancelInvocation);
448
- });
449
- };
450
-
451
- this._callbacks[invocationDescriptor.invocationId] = function (invocationEvent, error) {
452
- if (error) {
453
- subject.error(error);
454
- return;
455
- } else if (invocationEvent) {
456
- // invocationEvent will not be null when an error is not passed to the callback
457
- if (invocationEvent.type === IHubProtocol.MessageType.Completion) {
458
- if (invocationEvent.error) {
459
- subject.error(new Error(invocationEvent.error));
460
- } else {
461
- subject.complete();
462
- }
463
- } else {
464
- subject.next(invocationEvent.item);
465
- }
466
- }
467
- };
468
-
469
- promiseQueue = this._sendWithProtocol(invocationDescriptor)["catch"](function (e) {
470
- subject.error(e);
471
- delete _this3._callbacks[invocationDescriptor.invocationId];
472
- });
473
-
474
- this._launchStreams(streams, promiseQueue);
475
-
476
- return subject;
477
- }
478
- }, {
479
- key: "_sendMessage",
480
- value: function _sendMessage(message) {
481
- this._resetKeepAliveInterval();
482
-
483
- return this.connection.send(message);
484
- }
485
- /**
486
- * Sends a js object to the server.
487
- * @param message The js object to serialize and send.
488
- */
489
-
490
- }, {
491
- key: "_sendWithProtocol",
492
- value: function _sendWithProtocol(message) {
493
- return this._sendMessage(this._protocol.writeMessage(message));
494
- }
495
- /** Invokes a hub method on the server using the specified name and arguments. Does not wait for a response from the receiver.
496
- *
497
- * The Promise returned by this method resolves when the client has sent the invocation to the server. The server may still
498
- * be processing the invocation.
499
- *
500
- * @param {string} methodName The name of the server method to invoke.
501
- * @param {any[]} args The arguments used to invoke the server method.
502
- * @returns {Promise<void>} A Promise that resolves when the invocation has been successfully sent, or rejects with an error.
503
- */
504
-
505
- }, {
506
- key: "send",
507
- value: function send(methodName) {
508
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
509
- args[_key2 - 1] = arguments[_key2];
510
- }
511
-
512
- var _this$_replaceStreami3 = this._replaceStreamingParams(args),
513
- _this$_replaceStreami4 = _slicedToArray(_this$_replaceStreami3, 2),
514
- streams = _this$_replaceStreami4[0],
515
- streamIds = _this$_replaceStreami4[1];
516
-
517
- var sendPromise = this._sendWithProtocol(this._createInvocation(methodName, args, true, streamIds));
518
-
519
- this._launchStreams(streams, sendPromise);
520
-
521
- return sendPromise;
522
- }
523
- /** Invokes a hub method on the server using the specified name and arguments.
524
- *
525
- * The Promise returned by this method resolves when the server indicates it has finished invoking the method. When the promise
526
- * resolves, the server has finished invoking the method. If the server method returns a result, it is produced as the result of
527
- * resolving the Promise.
528
- *
529
- * @typeparam T The expected return type.
530
- * @param {string} methodName The name of the server method to invoke.
531
- * @param {any[]} args The arguments used to invoke the server method.
532
- * @returns {Promise<T>} A Promise that resolves with the result of the server method (if any), or rejects with an error.
533
- */
534
-
535
- }, {
536
- key: "invoke",
537
- value: function invoke(methodName) {
538
- var _this4 = this;
539
-
540
- for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
541
- args[_key3 - 1] = arguments[_key3];
542
- }
543
-
544
- var _this$_replaceStreami5 = this._replaceStreamingParams(args),
545
- _this$_replaceStreami6 = _slicedToArray(_this$_replaceStreami5, 2),
546
- streams = _this$_replaceStreami6[0],
547
- streamIds = _this$_replaceStreami6[1];
548
-
549
- var invocationDescriptor = this._createInvocation(methodName, args, false, streamIds);
550
-
551
- var p = new Promise(function (resolve, reject) {
552
- // invocationId will always have a value for a non-blocking invocation
553
- _this4._callbacks[invocationDescriptor.invocationId] = function (invocationEvent, error) {
554
- if (error) {
555
- reject(error);
556
- return;
557
- } else if (invocationEvent) {
558
- // invocationEvent will not be null when an error is not passed to the callback
559
- if (invocationEvent.type === IHubProtocol.MessageType.Completion) {
560
- if (invocationEvent.error) {
561
- reject(new Error(invocationEvent.error));
562
- } else {
563
- resolve(invocationEvent.result);
564
- }
565
- } else {
566
- reject(new Error("Unexpected message type: ".concat(invocationEvent.type)));
567
- }
568
- }
569
- };
570
-
571
- var promiseQueue = _this4._sendWithProtocol(invocationDescriptor)["catch"](function (e) {
572
- reject(e); // invocationId will always have a value for a non-blocking invocation
573
-
574
- delete _this4._callbacks[invocationDescriptor.invocationId];
575
- });
576
-
577
- _this4._launchStreams(streams, promiseQueue);
578
- });
579
- return p;
580
- }
581
- /** Registers a handler that will be invoked when the hub method with the specified method name is invoked.
582
- *
583
- * @param {string} methodName The name of the hub method to define.
584
- * @param {Function} newMethod The handler that will be raised when the hub method is invoked.
585
- */
586
-
587
- }, {
588
- key: "on",
589
- value: function on(methodName, newMethod) {
590
- if (!methodName || !newMethod) {
591
- return;
592
- }
593
-
594
- methodName = methodName.toLowerCase();
595
-
596
- if (!this._methods[methodName]) {
597
- this._methods[methodName] = [];
598
- } // Preventing adding the same handler multiple times.
599
-
600
-
601
- if (this._methods[methodName].indexOf(newMethod) !== -1) {
602
- return;
603
- }
604
-
605
- this._methods[methodName].push(newMethod);
606
- }
607
- }, {
608
- key: "off",
609
- value: function off(methodName, method) {
610
- if (!methodName) {
611
- return;
612
- }
613
-
614
- methodName = methodName.toLowerCase();
615
- var handlers = this._methods[methodName];
616
-
617
- if (!handlers) {
618
- return;
619
- }
620
-
621
- if (method) {
622
- var removeIdx = handlers.indexOf(method);
623
-
624
- if (removeIdx !== -1) {
625
- handlers.splice(removeIdx, 1);
626
-
627
- if (handlers.length === 0) {
628
- delete this._methods[methodName];
629
- }
630
- }
631
- } else {
632
- delete this._methods[methodName];
633
- }
634
- }
635
- /** Registers a handler that will be invoked when the connection is closed.
636
- *
637
- * @param {Function} callback The handler that will be invoked when the connection is closed. Optionally receives a single argument containing the error that caused the connection to close (if any).
638
- */
639
-
640
- }, {
641
- key: "onclose",
642
- value: function onclose(callback) {
643
- if (callback) {
644
- this._closedCallbacks.push(callback);
645
- }
646
- }
647
- /** Registers a handler that will be invoked when the connection starts reconnecting.
648
- *
649
- * @param {Function} callback The handler that will be invoked when the connection starts reconnecting. Optionally receives a single argument containing the error that caused the connection to start reconnecting (if any).
650
- */
651
-
652
- }, {
653
- key: "onreconnecting",
654
- value: function onreconnecting(callback) {
655
- if (callback) {
656
- this._reconnectingCallbacks.push(callback);
657
- }
658
- }
659
- /** Registers a handler that will be invoked when the connection successfully reconnects.
660
- *
661
- * @param {Function} callback The handler that will be invoked when the connection successfully reconnects.
662
- */
663
-
664
- }, {
665
- key: "onreconnected",
666
- value: function onreconnected(callback) {
667
- if (callback) {
668
- this._reconnectedCallbacks.push(callback);
669
- }
670
- }
671
- }, {
672
- key: "_processIncomingData",
673
- value: function _processIncomingData(data) {
674
- this._cleanupTimeout();
675
-
676
- if (!this._receivedHandshakeResponse) {
677
- data = this._processHandshakeResponse(data);
678
- this._receivedHandshakeResponse = true;
679
- } // Data may have all been read when processing handshake response
680
-
681
-
682
- if (data) {
683
- // Parse the messages
684
- var messages = this._protocol.parseMessages(data, this._logger);
685
-
686
- var _iterator = _createForOfIteratorHelper(messages),
687
- _step;
688
-
689
- try {
690
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
691
- var message = _step.value;
692
-
693
- switch (message.type) {
694
- case IHubProtocol.MessageType.Invocation:
695
- this._invokeClientMethod(message);
696
-
697
- break;
698
-
699
- case IHubProtocol.MessageType.StreamItem:
700
- case IHubProtocol.MessageType.Completion:
701
- {
702
- var callback = this._callbacks[message.invocationId];
703
-
704
- if (callback) {
705
- if (message.type === IHubProtocol.MessageType.Completion) {
706
- delete this._callbacks[message.invocationId];
707
- }
708
-
709
- try {
710
- callback(message);
711
- } catch (e) {
712
- this._logger.log(ILogger.LogLevel.Error, "Stream callback threw error: ".concat(Utils.getErrorString(e)));
713
- }
714
- }
715
-
716
- break;
717
- }
718
-
719
- case IHubProtocol.MessageType.Ping:
720
- // Don't care about pings
721
- break;
722
-
723
- case IHubProtocol.MessageType.Close:
724
- {
725
- this._logger.log(ILogger.LogLevel.Information, "Close message received from server.");
726
-
727
- var error = message.error ? new Error("Server returned an error on close: " + message.error) : undefined;
728
-
729
- if (message.allowReconnect === true) {
730
- // It feels wrong not to await connection.stop() here, but processIncomingData is called as part of an onreceive callback which is not async,
731
- // this is already the behavior for serverTimeout(), and HttpConnection.Stop() should catch and log all possible exceptions.
732
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
733
- this.connection.stop(error);
734
- } else {
735
- // We cannot await stopInternal() here, but subsequent calls to stop() will await this if stopInternal() is still ongoing.
736
- this._stopPromise = this._stopInternal(error);
737
- }
738
-
739
- break;
740
- }
741
-
742
- default:
743
- this._logger.log(ILogger.LogLevel.Warning, "Invalid message type: ".concat(message.type, "."));
744
-
745
- break;
746
- }
747
- }
748
- } catch (err) {
749
- _iterator.e(err);
750
- } finally {
751
- _iterator.f();
752
- }
753
- }
754
-
755
- this._resetTimeoutPeriod();
756
- }
757
- }, {
758
- key: "_processHandshakeResponse",
759
- value: function _processHandshakeResponse(data) {
760
- var responseMessage;
761
- var remainingData;
762
-
763
- try {
764
- var _this$_handshakeProto = this._handshakeProtocol.parseHandshakeResponse(data);
765
-
766
- var _this$_handshakeProto2 = _slicedToArray(_this$_handshakeProto, 2);
767
-
768
- remainingData = _this$_handshakeProto2[0];
769
- responseMessage = _this$_handshakeProto2[1];
770
- } catch (e) {
771
- var message = "Error parsing handshake response: " + e;
772
-
773
- this._logger.log(ILogger.LogLevel.Error, message);
774
-
775
- var error = new Error(message);
776
-
777
- this._handshakeRejecter(error);
778
-
779
- throw error;
780
- }
781
-
782
- if (responseMessage.error) {
783
- var _message = "Server returned handshake error: " + responseMessage.error;
784
-
785
- this._logger.log(ILogger.LogLevel.Error, _message);
786
-
787
- var _error = new Error(_message);
788
-
789
- this._handshakeRejecter(_error);
790
-
791
- throw _error;
792
- } else {
793
- this._logger.log(ILogger.LogLevel.Debug, "Server handshake complete.");
794
- }
795
-
796
- this._handshakeResolver();
797
-
798
- return remainingData;
799
- }
800
- }, {
801
- key: "_resetKeepAliveInterval",
802
- value: function _resetKeepAliveInterval() {
803
- if (this.connection.features.inherentKeepAlive) {
804
- return;
805
- } // Set the time we want the next keep alive to be sent
806
- // Timer will be setup on next message receive
807
-
808
-
809
- this._nextKeepAlive = new Date().getTime() + this.keepAliveIntervalInMilliseconds;
810
-
811
- this._cleanupPingTimer();
812
- }
813
- }, {
814
- key: "_resetTimeoutPeriod",
815
- value: function _resetTimeoutPeriod() {
816
- var _this5 = this;
817
-
818
- if (!this.connection.features || !this.connection.features.inherentKeepAlive) {
819
- // Set the timeout timer
820
- this._timeoutHandle = setTimeout(function () {
821
- return _this5.serverTimeout();
822
- }, this.serverTimeoutInMilliseconds); // Set keepAlive timer if there isn't one
823
-
824
- if (this._pingServerHandle === undefined) {
825
- var nextPing = this._nextKeepAlive - new Date().getTime();
826
-
827
- if (nextPing < 0) {
828
- nextPing = 0;
829
- } // The timer needs to be set from a networking callback to avoid Chrome timer throttling from causing timers to run once a minute
830
-
831
-
832
- this._pingServerHandle = setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
833
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
834
- while (1) {
835
- switch (_context4.prev = _context4.next) {
836
- case 0:
837
- if (!(_this5._connectionState === exports.HubConnectionState.Connected)) {
838
- _context4.next = 9;
839
- break;
840
- }
841
-
842
- _context4.prev = 1;
843
- _context4.next = 4;
844
- return _this5._sendMessage(_this5._cachedPingMessage);
845
-
846
- case 4:
847
- _context4.next = 9;
848
- break;
849
-
850
- case 6:
851
- _context4.prev = 6;
852
- _context4.t0 = _context4["catch"](1);
853
-
854
- // We don't care about the error. It should be seen elsewhere in the client.
855
- // The connection is probably in a bad or closed state now, cleanup the timer so it stops triggering
856
- _this5._cleanupPingTimer();
857
-
858
- case 9:
859
- case "end":
860
- return _context4.stop();
861
- }
862
- }
863
- }, _callee4, null, [[1, 6]]);
864
- })), nextPing);
865
- }
866
- }
867
- } // eslint-disable-next-line @typescript-eslint/naming-convention
868
-
869
- }, {
870
- key: "serverTimeout",
871
- value: function serverTimeout() {
872
- // The server hasn't talked to us in a while. It doesn't like us anymore ... :(
873
- // Terminate the connection, but we don't need to wait on the promise. This could trigger reconnecting.
874
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
875
- this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."));
876
- }
877
- }, {
878
- key: "_invokeClientMethod",
879
- value: function _invokeClientMethod(invocationMessage) {
880
- var _this6 = this;
881
-
882
- var methods = this._methods[invocationMessage.target.toLowerCase()];
883
-
884
- if (methods) {
885
- try {
886
- methods.forEach(function (m) {
887
- return m.apply(_this6, invocationMessage.arguments);
888
- });
889
- } catch (e) {
890
- this._logger.log(ILogger.LogLevel.Error, "A callback for the method ".concat(invocationMessage.target.toLowerCase(), " threw error '").concat(e, "'."));
891
- }
892
-
893
- if (invocationMessage.invocationId) {
894
- // This is not supported in v1. So we return an error to avoid blocking the server waiting for the response.
895
- var message = "Server requested a response, which is not supported in this version of the client.";
896
-
897
- this._logger.log(ILogger.LogLevel.Error, message); // We don't want to wait on the stop itself.
898
-
899
-
900
- this._stopPromise = this._stopInternal(new Error(message));
901
- }
902
- } else {
903
- this._logger.log(ILogger.LogLevel.Warning, "No client method with the name '".concat(invocationMessage.target, "' found."));
904
- }
905
- }
906
- }, {
907
- key: "_connectionClosed",
908
- value: function _connectionClosed(error) {
909
- this._logger.log(ILogger.LogLevel.Debug, "HubConnection.connectionClosed(".concat(error, ") called while in state ").concat(this._connectionState, ".")); // Triggering this.handshakeRejecter is insufficient because it could already be resolved without the continuation having run yet.
910
-
911
-
912
- this._stopDuringStartError = this._stopDuringStartError || error || new Error("The underlying connection was closed before the hub handshake could complete."); // If the handshake is in progress, start will be waiting for the handshake promise, so we complete it.
913
- // If it has already completed, this should just noop.
914
-
915
- if (this._handshakeResolver) {
916
- this._handshakeResolver();
917
- }
918
-
919
- this._cancelCallbacksWithError(error || new Error("Invocation canceled due to the underlying connection being closed."));
920
-
921
- this._cleanupTimeout();
922
-
923
- this._cleanupPingTimer();
924
-
925
- if (this._connectionState === exports.HubConnectionState.Disconnecting) {
926
- this._completeClose(error);
927
- } else if (this._connectionState === exports.HubConnectionState.Connected && this._reconnectPolicy) {
928
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
929
- this._reconnect(error);
930
- } else if (this._connectionState === exports.HubConnectionState.Connected) {
931
- this._completeClose(error);
932
- } // If none of the above if conditions were true were called the HubConnection must be in either:
933
- // 1. The Connecting state in which case the handshakeResolver will complete it and stopDuringStartError will fail it.
934
- // 2. The Reconnecting state in which case the handshakeResolver will complete it and stopDuringStartError will fail the current reconnect attempt
935
- // and potentially continue the reconnect() loop.
936
- // 3. The Disconnected state in which case we're already done.
937
-
938
- }
939
- }, {
940
- key: "_completeClose",
941
- value: function _completeClose(error) {
942
- var _this7 = this;
943
-
944
- if (this._connectionStarted) {
945
- this._connectionState = exports.HubConnectionState.Disconnected;
946
- this._connectionStarted = false;
947
-
948
- if (Utils.Platform.isBrowser) {
949
- window.document.removeEventListener("freeze", this._freezeEventListener);
950
- }
951
-
952
- try {
953
- this._closedCallbacks.forEach(function (c) {
954
- return c.apply(_this7, [error]);
955
- });
956
- } catch (e) {
957
- this._logger.log(ILogger.LogLevel.Error, "An onclose callback called with error '".concat(error, "' threw error '").concat(e, "'."));
958
- }
959
- }
960
- }
961
- }, {
962
- key: "_reconnect",
963
- value: function () {
964
- var _reconnect2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(error) {
965
- var _this8 = this;
966
-
967
- var reconnectStartTime, previousReconnectAttempts, retryError, nextRetryDelay;
968
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
969
- while (1) {
970
- switch (_context5.prev = _context5.next) {
971
- case 0:
972
- reconnectStartTime = Date.now();
973
- previousReconnectAttempts = 0;
974
- retryError = error !== undefined ? error : new Error("Attempting to reconnect due to a unknown error.");
975
- nextRetryDelay = this._getNextRetryDelay(previousReconnectAttempts++, 0, retryError);
976
-
977
- if (!(nextRetryDelay === null)) {
978
- _context5.next = 8;
979
- break;
980
- }
981
-
982
- this._logger.log(ILogger.LogLevel.Debug, "Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt.");
983
-
984
- this._completeClose(error);
985
-
986
- return _context5.abrupt("return");
987
-
988
- case 8:
989
- this._connectionState = exports.HubConnectionState.Reconnecting;
990
-
991
- if (error) {
992
- this._logger.log(ILogger.LogLevel.Information, "Connection reconnecting because of error '".concat(error, "'."));
993
- } else {
994
- this._logger.log(ILogger.LogLevel.Information, "Connection reconnecting.");
995
- }
996
-
997
- if (!(this._reconnectingCallbacks.length !== 0)) {
998
- _context5.next = 15;
999
- break;
1000
- }
1001
-
1002
- try {
1003
- this._reconnectingCallbacks.forEach(function (c) {
1004
- return c.apply(_this8, [error]);
1005
- });
1006
- } catch (e) {
1007
- this._logger.log(ILogger.LogLevel.Error, "An onreconnecting callback called with error '".concat(error, "' threw error '").concat(e, "'."));
1008
- } // Exit early if an onreconnecting callback called connection.stop().
1009
-
1010
-
1011
- if (!(this._connectionState !== exports.HubConnectionState.Reconnecting)) {
1012
- _context5.next = 15;
1013
- break;
1014
- }
1015
-
1016
- this._logger.log(ILogger.LogLevel.Debug, "Connection left the reconnecting state in onreconnecting callback. Done reconnecting.");
1017
-
1018
- return _context5.abrupt("return");
1019
-
1020
- case 15:
1021
- if (!(nextRetryDelay !== null)) {
1022
- _context5.next = 43;
1023
- break;
1024
- }
1025
-
1026
- this._logger.log(ILogger.LogLevel.Information, "Reconnect attempt number ".concat(previousReconnectAttempts, " will start in ").concat(nextRetryDelay, " ms."));
1027
-
1028
- _context5.next = 19;
1029
- return new Promise(function (resolve) {
1030
- _this8._reconnectDelayHandle = setTimeout(resolve, nextRetryDelay);
1031
- });
1032
-
1033
- case 19:
1034
- this._reconnectDelayHandle = undefined;
1035
-
1036
- if (!(this._connectionState !== exports.HubConnectionState.Reconnecting)) {
1037
- _context5.next = 23;
1038
- break;
1039
- }
1040
-
1041
- this._logger.log(ILogger.LogLevel.Debug, "Connection left the reconnecting state during reconnect delay. Done reconnecting.");
1042
-
1043
- return _context5.abrupt("return");
1044
-
1045
- case 23:
1046
- _context5.prev = 23;
1047
- _context5.next = 26;
1048
- return this._startInternal();
1049
-
1050
- case 26:
1051
- this._connectionState = exports.HubConnectionState.Connected;
1052
-
1053
- this._logger.log(ILogger.LogLevel.Information, "HubConnection reconnected successfully.");
1054
-
1055
- if (this._reconnectedCallbacks.length !== 0) {
1056
- try {
1057
- this._reconnectedCallbacks.forEach(function (c) {
1058
- return c.apply(_this8, [_this8.connection.connectionId]);
1059
- });
1060
- } catch (e) {
1061
- this._logger.log(ILogger.LogLevel.Error, "An onreconnected callback called with connectionId '".concat(this.connection.connectionId, "; threw error '").concat(e, "'."));
1062
- }
1063
- }
1064
-
1065
- return _context5.abrupt("return");
1066
-
1067
- case 32:
1068
- _context5.prev = 32;
1069
- _context5.t0 = _context5["catch"](23);
1070
-
1071
- this._logger.log(ILogger.LogLevel.Information, "Reconnect attempt failed because of error '".concat(_context5.t0, "'."));
1072
-
1073
- if (!(this._connectionState !== exports.HubConnectionState.Reconnecting)) {
1074
- _context5.next = 39;
1075
- break;
1076
- }
1077
-
1078
- this._logger.log(ILogger.LogLevel.Debug, "Connection moved to the '".concat(this._connectionState, "' from the reconnecting state during reconnect attempt. Done reconnecting.")); // The TypeScript compiler thinks that connectionState must be Connected here. The TypeScript compiler is wrong.
1079
-
1080
-
1081
- if (this._connectionState === exports.HubConnectionState.Disconnecting) {
1082
- this._completeClose();
1083
- }
1084
-
1085
- return _context5.abrupt("return");
1086
-
1087
- case 39:
1088
- retryError = _context5.t0 instanceof Error ? _context5.t0 : new Error(_context5.t0.toString());
1089
- nextRetryDelay = this._getNextRetryDelay(previousReconnectAttempts++, Date.now() - reconnectStartTime, retryError);
1090
-
1091
- case 41:
1092
- _context5.next = 15;
1093
- break;
1094
-
1095
- case 43:
1096
- this._logger.log(ILogger.LogLevel.Information, "Reconnect retries have been exhausted after ".concat(Date.now() - reconnectStartTime, " ms and ").concat(previousReconnectAttempts, " failed attempts. Connection disconnecting."));
1097
-
1098
- this._completeClose();
1099
-
1100
- case 45:
1101
- case "end":
1102
- return _context5.stop();
1103
- }
1104
- }
1105
- }, _callee5, this, [[23, 32]]);
1106
- }));
1107
-
1108
- function _reconnect(_x) {
1109
- return _reconnect2.apply(this, arguments);
1110
- }
1111
-
1112
- return _reconnect;
1113
- }()
1114
- }, {
1115
- key: "_getNextRetryDelay",
1116
- value: function _getNextRetryDelay(previousRetryCount, elapsedMilliseconds, retryReason) {
1117
- try {
1118
- return this._reconnectPolicy.nextRetryDelayInMilliseconds({
1119
- elapsedMilliseconds: elapsedMilliseconds,
1120
- previousRetryCount: previousRetryCount,
1121
- retryReason: retryReason
1122
- });
1123
- } catch (e) {
1124
- this._logger.log(ILogger.LogLevel.Error, "IRetryPolicy.nextRetryDelayInMilliseconds(".concat(previousRetryCount, ", ").concat(elapsedMilliseconds, ") threw error '").concat(e, "'."));
1125
-
1126
- return null;
1127
- }
1128
- }
1129
- }, {
1130
- key: "_cancelCallbacksWithError",
1131
- value: function _cancelCallbacksWithError(error) {
1132
- var _this9 = this;
1133
-
1134
- var callbacks = this._callbacks;
1135
- this._callbacks = {};
1136
- Object.keys(callbacks).forEach(function (key) {
1137
- var callback = callbacks[key];
1138
-
1139
- try {
1140
- callback(null, error);
1141
- } catch (e) {
1142
- _this9._logger.log(ILogger.LogLevel.Error, "Stream 'error' callback called with '".concat(error, "' threw error: ").concat(Utils.getErrorString(e)));
1143
- }
1144
- });
1145
- }
1146
- }, {
1147
- key: "_cleanupPingTimer",
1148
- value: function _cleanupPingTimer() {
1149
- if (this._pingServerHandle) {
1150
- clearTimeout(this._pingServerHandle);
1151
- this._pingServerHandle = undefined;
1152
- }
1153
- }
1154
- }, {
1155
- key: "_cleanupTimeout",
1156
- value: function _cleanupTimeout() {
1157
- if (this._timeoutHandle) {
1158
- clearTimeout(this._timeoutHandle);
1159
- }
1160
- }
1161
- }, {
1162
- key: "_createInvocation",
1163
- value: function _createInvocation(methodName, args, nonblocking, streamIds) {
1164
- if (nonblocking) {
1165
- if (streamIds.length !== 0) {
1166
- return {
1167
- arguments: args,
1168
- streamIds: streamIds,
1169
- target: methodName,
1170
- type: IHubProtocol.MessageType.Invocation
1171
- };
1172
- } else {
1173
- return {
1174
- arguments: args,
1175
- target: methodName,
1176
- type: IHubProtocol.MessageType.Invocation
1177
- };
1178
- }
1179
- } else {
1180
- var invocationId = this._invocationId;
1181
- this._invocationId++;
1182
-
1183
- if (streamIds.length !== 0) {
1184
- return {
1185
- arguments: args,
1186
- invocationId: invocationId.toString(),
1187
- streamIds: streamIds,
1188
- target: methodName,
1189
- type: IHubProtocol.MessageType.Invocation
1190
- };
1191
- } else {
1192
- return {
1193
- arguments: args,
1194
- invocationId: invocationId.toString(),
1195
- target: methodName,
1196
- type: IHubProtocol.MessageType.Invocation
1197
- };
1198
- }
1199
- }
1200
- }
1201
- }, {
1202
- key: "_launchStreams",
1203
- value: function _launchStreams(streams, promiseQueue) {
1204
- var _this10 = this;
1205
-
1206
- if (streams.length === 0) {
1207
- return;
1208
- } // Synchronize stream data so they arrive in-order on the server
1209
-
1210
-
1211
- if (!promiseQueue) {
1212
- promiseQueue = Promise.resolve();
1213
- } // We want to iterate over the keys, since the keys are the stream ids
1214
- // eslint-disable-next-line guard-for-in
1215
-
1216
-
1217
- var _loop = function _loop(streamId) {
1218
- streams[streamId].subscribe({
1219
- complete: function complete() {
1220
- promiseQueue = promiseQueue.then(function () {
1221
- return _this10._sendWithProtocol(_this10._createCompletionMessage(streamId));
1222
- });
1223
- },
1224
- error: function error(err) {
1225
- var message;
1226
-
1227
- if (err instanceof Error) {
1228
- message = err.message;
1229
- } else if (err && err.toString) {
1230
- message = err.toString();
1231
- } else {
1232
- message = "Unknown error";
1233
- }
1234
-
1235
- promiseQueue = promiseQueue.then(function () {
1236
- return _this10._sendWithProtocol(_this10._createCompletionMessage(streamId, message));
1237
- });
1238
- },
1239
- next: function next(item) {
1240
- promiseQueue = promiseQueue.then(function () {
1241
- return _this10._sendWithProtocol(_this10._createStreamItemMessage(streamId, item));
1242
- });
1243
- }
1244
- });
1245
- };
1246
-
1247
- for (var streamId in streams) {
1248
- _loop(streamId);
1249
- }
1250
- }
1251
- }, {
1252
- key: "_replaceStreamingParams",
1253
- value: function _replaceStreamingParams(args) {
1254
- var streams = [];
1255
- var streamIds = [];
1256
-
1257
- for (var i = 0; i < args.length; i++) {
1258
- var argument = args[i];
1259
-
1260
- if (this._isObservable(argument)) {
1261
- var streamId = this._invocationId;
1262
- this._invocationId++; // Store the stream for later use
1263
-
1264
- streams[streamId] = argument;
1265
- streamIds.push(streamId.toString()); // remove stream from args
1266
-
1267
- args.splice(i, 1);
1268
- }
1269
- }
1270
-
1271
- return [streams, streamIds];
1272
- }
1273
- }, {
1274
- key: "_isObservable",
1275
- value: function _isObservable(arg) {
1276
- // This allows other stream implementations to just work (like rxjs)
1277
- return arg && arg.subscribe && typeof arg.subscribe === "function";
1278
- }
1279
- }, {
1280
- key: "_createStreamInvocation",
1281
- value: function _createStreamInvocation(methodName, args, streamIds) {
1282
- var invocationId = this._invocationId;
1283
- this._invocationId++;
1284
-
1285
- if (streamIds.length !== 0) {
1286
- return {
1287
- arguments: args,
1288
- invocationId: invocationId.toString(),
1289
- streamIds: streamIds,
1290
- target: methodName,
1291
- type: IHubProtocol.MessageType.StreamInvocation
1292
- };
1293
- } else {
1294
- return {
1295
- arguments: args,
1296
- invocationId: invocationId.toString(),
1297
- target: methodName,
1298
- type: IHubProtocol.MessageType.StreamInvocation
1299
- };
1300
- }
1301
- }
1302
- }, {
1303
- key: "_createCancelInvocation",
1304
- value: function _createCancelInvocation(id) {
1305
- return {
1306
- invocationId: id,
1307
- type: IHubProtocol.MessageType.CancelInvocation
1308
- };
1309
- }
1310
- }, {
1311
- key: "_createStreamItemMessage",
1312
- value: function _createStreamItemMessage(id, item) {
1313
- return {
1314
- invocationId: id,
1315
- item: item,
1316
- type: IHubProtocol.MessageType.StreamItem
1317
- };
1318
- }
1319
- }, {
1320
- key: "_createCompletionMessage",
1321
- value: function _createCompletionMessage(id, error, result) {
1322
- if (error) {
1323
- return {
1324
- error: error,
1325
- invocationId: id,
1326
- type: IHubProtocol.MessageType.Completion
1327
- };
1328
- }
1329
-
1330
- return {
1331
- invocationId: id,
1332
- result: result,
1333
- type: IHubProtocol.MessageType.Completion
1334
- };
1335
- }
1336
- }], [{
1337
- key: "create",
1338
- value: function create(connection, logger, protocol, reconnectPolicy) {
1339
- return new HubConnection(connection, logger, protocol, reconnectPolicy);
1340
- }
1341
- }]);
1342
-
1343
- return HubConnection;
1344
- }();
1345
-
1346
- exports.HubConnection = HubConnection;