@vc-shell/framework 1.1.46 → 1.1.48

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 (360) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/core/plugins/modularity/loader.ts +126 -97
  3. package/dist/assets/042c75b764bc78a7.svg +1 -0
  4. package/dist/assets/0ba156439a339f2a.svg +1 -0
  5. package/dist/assets/0be560bfb22d0e72.woff2 +0 -0
  6. package/dist/assets/0f590f8a94577092.svg +1 -0
  7. package/dist/assets/0fc5820f8be53a1b.svg +1 -0
  8. package/dist/assets/10768e2cc79fc60b.svg +1 -0
  9. package/dist/assets/11b3d25a56fd9a21.woff2 +0 -0
  10. package/dist/assets/157b8721e0600ea8.svg +1 -0
  11. package/dist/assets/15e91cdd649cde9a.svg +1 -0
  12. package/dist/assets/1a3e84b2457f709a.woff +0 -0
  13. package/dist/assets/1de63eb118636cce.svg +1 -0
  14. package/dist/assets/1ea01de36eb5491b.svg +1 -0
  15. package/dist/assets/204eaf512fde2023.svg +1 -0
  16. package/dist/assets/2088983edf42e153.svg +1 -0
  17. package/dist/assets/208f810a9321a327.svg +1 -0
  18. package/dist/assets/21220a9d10e6c558.svg +1 -0
  19. package/dist/assets/220db345a102045d.woff2 +0 -0
  20. package/dist/assets/225da11d23968333.svg +1 -0
  21. package/dist/assets/226f862dd81bdc13.woff2 +0 -0
  22. package/dist/assets/23a2d53395ddb14f.woff +0 -0
  23. package/dist/assets/259e6ad461a52ad7.svg +1 -0
  24. package/dist/assets/261e6dec4d53b9ac.woff +0 -0
  25. package/dist/assets/262f46a0b6d94bb6.svg +1 -0
  26. package/dist/assets/2857c513073467da.svg +1 -0
  27. package/dist/assets/2b3be7889467d98f.woff +0 -0
  28. package/dist/assets/2d4e6190eec72737.svg +1 -0
  29. package/dist/assets/2eba973185078bc8.woff +0 -0
  30. package/dist/assets/327511cd4a7ba7f9.woff +0 -0
  31. package/dist/assets/334d3f6bc766c516.woff +0 -0
  32. package/dist/assets/34ff7dd0c2285956.svg +1 -0
  33. package/dist/assets/3d26b7c1ab78bbe2.woff +0 -0
  34. package/dist/assets/3f8c4cc8099e34b6.woff2 +0 -0
  35. package/dist/assets/40a0e53b79ce63c6.woff2 +0 -0
  36. package/dist/assets/41275bcb979cb650.svg +1 -0
  37. package/dist/assets/42df4e2d6fa3fd2a.woff2 +0 -0
  38. package/dist/assets/434f7982590e462f.woff +0 -0
  39. package/dist/assets/4ae5f23e0ca888e7.woff2 +0 -0
  40. package/dist/assets/4d7a77b0e5373992.svg +1 -0
  41. package/dist/assets/4e43c74354534fb3.svg +1 -0
  42. package/dist/assets/4fe75f5117100705.svg +1 -0
  43. package/dist/assets/52610491f372cb0c.woff2 +0 -0
  44. package/dist/assets/52e261a005074e1b.woff +0 -0
  45. package/dist/assets/5304c3d05a5f9789.woff2 +0 -0
  46. package/dist/assets/572bb1bb4156a9c1.svg +1 -0
  47. package/dist/assets/5b3661be8be679d0.woff2 +0 -0
  48. package/dist/assets/5d96cfcc5bedd917.woff2 +0 -0
  49. package/dist/assets/6075995d7e74da46.woff2 +0 -0
  50. package/dist/assets/617c4736236e199e.woff +0 -0
  51. package/dist/assets/6619e9e10beea0e7.woff2 +0 -0
  52. package/dist/assets/67230f05dc94a265.svg +1 -0
  53. package/dist/assets/6798e4dd4add9b48.svg +1 -0
  54. package/dist/assets/698ec6c722d4cb05.woff2 +0 -0
  55. package/dist/assets/6a3e73faf406cf33.svg +1 -0
  56. package/dist/assets/72de3a63bc0b70dd.svg +1 -0
  57. package/dist/assets/74c6a6ab81bb6340.woff2 +0 -0
  58. package/dist/assets/74ed5f8a78e71106.svg +1 -0
  59. package/dist/assets/7ce0c166fd6a1204.woff +0 -0
  60. package/dist/assets/7d55399c2a7bc985.svg +1 -0
  61. package/dist/assets/7d970675c69fca1d.woff +0 -0
  62. package/dist/assets/7eda727273fd98d3.svg +1 -0
  63. package/dist/assets/7f6ebfd707b76ca2.woff +0 -0
  64. package/dist/assets/7fa898d213fcc7bc.woff2 +0 -0
  65. package/dist/assets/861e6b7192b3b6c7.woff +0 -0
  66. package/dist/assets/8bbcde81ba21ecb2.woff2 +0 -0
  67. package/dist/assets/8f6657e5e0b8d3e4.woff +0 -0
  68. package/dist/assets/910b0d99b9e26568.svg +1 -0
  69. package/dist/assets/91eee1aa81f72683.woff +0 -0
  70. package/dist/assets/92508f8707159b51.svg +1 -0
  71. package/dist/assets/9392bf1d591e1abb.svg +1 -0
  72. package/dist/assets/97e8d4984ba0713a.woff2 +0 -0
  73. package/dist/assets/9cb83236f6bb7ab1.svg +1 -0
  74. package/dist/assets/9d37314695c0b68d.woff +0 -0
  75. package/dist/assets/a18404194e3f9047.svg +1 -0
  76. package/dist/assets/a2017fe7f0a26510.svg +1 -0
  77. package/dist/assets/a47034e65dbcc3d7.woff +0 -0
  78. package/dist/assets/a617e11804bbacb7.woff +0 -0
  79. package/dist/assets/ab6e7190bb1492d5.woff2 +0 -0
  80. package/dist/assets/abf88f301a0730f4.svg +1 -0
  81. package/dist/assets/aed17cb6fdad2ada.woff2 +0 -0
  82. package/dist/assets/b1a596e31ad1185a.svg +1 -0
  83. package/dist/assets/b27767411c8427be.woff +0 -0
  84. package/dist/assets/b291dc35a17511f7.woff +0 -0
  85. package/dist/assets/b325adcae33bbe7a.svg +1 -0
  86. package/dist/assets/b372390551ca2fa1.svg +1 -0
  87. package/dist/assets/b5bb1e8fc975decd.svg +1 -0
  88. package/dist/assets/b645a4a2181b9dc1.svg +1 -0
  89. package/dist/assets/b6499ddce0a4ef7d.svg +1 -0
  90. package/dist/assets/b94421fadd23b0f2.svg +1 -0
  91. package/dist/assets/bb28fb0f27f1c11b.svg +1 -0
  92. package/dist/assets/bfbe205759295eca.woff2 +0 -0
  93. package/dist/assets/ca791c5ca5848a03.svg +1 -0
  94. package/dist/assets/cb32840ce330103f.woff +0 -0
  95. package/dist/assets/d084bda16abe8a56.svg +1 -0
  96. package/dist/assets/d32b129cae2fffd6.svg +1 -0
  97. package/dist/assets/d35a4c7113315758.woff2 +0 -0
  98. package/dist/assets/d3f792f54ae4c307.svg +1 -0
  99. package/dist/assets/d5a5b8630120073d.svg +1 -0
  100. package/dist/assets/d5f9664ebbfb104b.svg +1 -0
  101. package/dist/assets/d80b05788e407de7.woff2 +0 -0
  102. package/dist/assets/d84247b59449dd88.woff2 +0 -0
  103. package/dist/assets/dd05d43ff0df2fc7.svg +1 -0
  104. package/dist/assets/e38acaa1757232e0.svg +1 -0
  105. package/dist/assets/e4a8550f1c7ffe36.svg +1 -0
  106. package/dist/assets/e5adb5ae3a3698f6.svg +1 -0
  107. package/dist/assets/e61a1889bac955f4.woff2 +0 -0
  108. package/dist/assets/e72bb11356af94c7.svg +1 -0
  109. package/dist/assets/e98196a9f8dcb2f0.svg +1 -0
  110. package/dist/assets/ebec912a42ad49ff.woff +0 -0
  111. package/dist/assets/f09d89268e4c0317.svg +1 -0
  112. package/dist/assets/f276d55184e05a07.woff +0 -0
  113. package/dist/assets/f5722262b6e7214e.woff2 +0 -0
  114. package/dist/assets/f7fc8bf46089d8b2.svg +1 -0
  115. package/dist/assets/fcb1c1ffb5640194.woff +0 -0
  116. package/dist/assets/fe141d99763f5d2b.woff +0 -0
  117. package/dist/assets/fed13b0d59903483.svg +1 -0
  118. package/dist/assets/fed757d2c2344ead.woff2 +0 -0
  119. package/dist/assets/ffc438f20e79ce73.woff +0 -0
  120. package/dist/core/plugins/modularity/loader.d.ts.map +1 -1
  121. package/dist/framework.js +16544 -25878
  122. package/dist/index.css +1 -1
  123. package/dist/index.d.ts +5 -8
  124. package/dist/index.d.ts.map +1 -1
  125. package/dist/tsconfig.tsbuildinfo +1 -1
  126. package/dist/ui/components/atoms/vc-icon/vc-lucide-icon.vue.d.ts.map +1 -1
  127. package/dist/vendor-boolbase-Bgn9I6iN.js +21 -0
  128. package/dist/vendor-cheerio-CleDsuQZ.js +1053 -0
  129. package/dist/vendor-cheerio-select-CVkYl3Z-.js +191 -0
  130. package/dist/vendor-css-select-CtIzVIiG.js +622 -0
  131. package/dist/vendor-css-what-CZZaquJM.js +267 -0
  132. package/dist/vendor-cypress-signalr-mock-CdKwIhWw.js +769 -0
  133. package/dist/vendor-date-fns-CdFbeoHV.js +2989 -0
  134. package/dist/vendor-dom-serializer-CugO0RdN.js +213 -0
  135. package/dist/vendor-dom7-wvIUV9pT.js +529 -0
  136. package/dist/vendor-domelementtype-B3sFIGaC.js +21 -0
  137. package/dist/vendor-domhandler-CL40eeX9.js +311 -0
  138. package/dist/vendor-dompurify-eYFoHPwR.js +528 -0
  139. package/dist/vendor-domutils-D3Y2YQFR.js +386 -0
  140. package/dist/vendor-entities-v26HW8wW.js +363 -0
  141. package/dist/vendor-floating-ui-core-C9uEvi1M.js +349 -0
  142. package/dist/vendor-floating-ui-dom-CZkYGmv4.js +393 -0
  143. package/dist/vendor-floating-ui-utils-Bx3BTd6_.js +259 -0
  144. package/dist/vendor-floating-ui-vue-CLOiVYP7.js +107 -0
  145. package/dist/vendor-headlessui-vue-Dg0Llidi.js +961 -0
  146. package/dist/vendor-htmlparser2-CXL_uhMI.js +735 -0
  147. package/dist/vendor-iconify-vue-D4fihzvl.js +1205 -0
  148. package/dist/vendor-intlify-core-base-Bvt2vJFV.js +1129 -0
  149. package/dist/vendor-intlify-message-compiler-1VxNzq21.js +945 -0
  150. package/dist/vendor-intlify-shared-D7kiPMOG.js +130 -0
  151. package/dist/vendor-iso-639-1-dVGfSUIM.js +781 -0
  152. package/dist/vendor-linkify-it-LzoUhj6C.js +199 -0
  153. package/dist/vendor-linkifyjs-DTu7SY_Y.js +705 -0
  154. package/dist/vendor-lodash-es-CrYlgAi8.js +4816 -0
  155. package/dist/vendor-markdown-it-4AJoRTAg.js +2263 -0
  156. package/dist/vendor-markdown-it-task-lists-Byg1-ms9.js +69 -0
  157. package/dist/vendor-mdurl-DZFDNdqC.js +192 -0
  158. package/dist/vendor-microsoft-applicationinsights-analytics-js-DA-ctcAL.js +1105 -0
  159. package/dist/vendor-microsoft-applicationinsights-cfgsync-js-COfRj-2q.js +261 -0
  160. package/dist/vendor-microsoft-applicationinsights-channel-js-MTPYhH-I.js +1809 -0
  161. package/dist/vendor-microsoft-applicationinsights-common-CDVnJ6MR.js +1921 -0
  162. package/dist/vendor-microsoft-applicationinsights-core-js-D7Aicf8S.js +4127 -0
  163. package/dist/vendor-microsoft-applicationinsights-dependencies-js-CvQWWraU.js +1399 -0
  164. package/dist/vendor-microsoft-applicationinsights-properties-js-C0Iv1cZE.js +572 -0
  165. package/dist/vendor-microsoft-applicationinsights-shims-CxtPYiwp.js +43 -0
  166. package/dist/vendor-microsoft-applicationinsights-web-BRuQAzjU.js +487 -0
  167. package/dist/vendor-microsoft-dynamicproto-js-DSkQkH3T.js +147 -0
  168. package/dist/vendor-microsoft-signalr-qIrag5xx.js +1761 -0
  169. package/dist/vendor-moment-CwOqp704.js +2589 -0
  170. package/dist/vendor-nevware21-ts-async-FAyg3c9V.js +260 -0
  171. package/dist/vendor-nevware21-ts-utils-Dy41wRhA.js +853 -0
  172. package/dist/vendor-nth-check-BE7AeBMg.js +45 -0
  173. package/dist/vendor-orderedmap-B3SOk52B.js +103 -0
  174. package/dist/vendor-parse5-DqztJOGh.js +5747 -0
  175. package/dist/vendor-parse5-htmlparser2-tree-adapter-CNubfdOP.js +143 -0
  176. package/dist/vendor-popperjs-core-LGjf7Wza.js +905 -0
  177. package/dist/vendor-prettier-D8C9GG-0.js +4858 -0
  178. package/dist/vendor-prosemirror-commands-BqYcdumy.js +344 -0
  179. package/dist/vendor-prosemirror-dropcursor-zknUsW5x.js +86 -0
  180. package/dist/vendor-prosemirror-gapcursor-DjOZhP78.js +200 -0
  181. package/dist/vendor-prosemirror-history-l8l3CFac.js +248 -0
  182. package/dist/vendor-prosemirror-keymap-C17r08p-.js +62 -0
  183. package/dist/vendor-prosemirror-markdown-WJEDhc-w.js +650 -0
  184. package/dist/vendor-prosemirror-model-BN5TnJD_.js +2736 -0
  185. package/dist/vendor-prosemirror-schema-list-CR0gi7aY.js +87 -0
  186. package/dist/vendor-prosemirror-state-B0bFP8WI.js +821 -0
  187. package/dist/vendor-prosemirror-tables-B1txTKlC.js +1711 -0
  188. package/dist/vendor-prosemirror-transform-Bo7kNPme.js +1507 -0
  189. package/dist/vendor-prosemirror-view--C7TZvmQ.js +3746 -0
  190. package/dist/vendor-punycode-js-CNI-zL6U.js +133 -0
  191. package/dist/vendor-rope-sequence-sEGCUMi8.js +100 -0
  192. package/dist/vendor-semver-BoKYtkQw.js +1021 -0
  193. package/dist/vendor-ssr-window-D4k3p53c.js +133 -0
  194. package/dist/vendor-swiper-CMVLTGu0.js +2825 -0
  195. package/dist/vendor-tippy-js-BGdgwGX-.js +812 -0
  196. package/dist/vendor-tiptap-core-BRY37Sb2.js +2806 -0
  197. package/dist/vendor-tiptap-extension-blockquote-CPd5qv-9.js +43 -0
  198. package/dist/vendor-tiptap-extension-bold-B0GwBNks.js +71 -0
  199. package/dist/vendor-tiptap-extension-bubble-menu-B0sZZld7.js +128 -0
  200. package/dist/vendor-tiptap-extension-bullet-list-CQm4ReOu.js +53 -0
  201. package/dist/vendor-tiptap-extension-code-C8cy6bRj.js +51 -0
  202. package/dist/vendor-tiptap-extension-code-block-BqTchNEf.js +133 -0
  203. package/dist/vendor-tiptap-extension-document-Dka1Uu0g.js +9 -0
  204. package/dist/vendor-tiptap-extension-dropcursor-CFSh-BuE.js +20 -0
  205. package/dist/vendor-tiptap-extension-floating-menu-H8PB4zeI.js +99 -0
  206. package/dist/vendor-tiptap-extension-gapcursor-CzwfD_IT.js +24 -0
  207. package/dist/vendor-tiptap-extension-hard-break-Rm6aVcrK.js +55 -0
  208. package/dist/vendor-tiptap-extension-heading-CavI6u1v.js +54 -0
  209. package/dist/vendor-tiptap-extension-history-WEN1_74D.js +35 -0
  210. package/dist/vendor-tiptap-extension-horizontal-rule-DZkUEL6s.js +58 -0
  211. package/dist/vendor-tiptap-extension-image-B67_mxGM.js +64 -0
  212. package/dist/vendor-tiptap-extension-italic-BshxBFou.js +70 -0
  213. package/dist/vendor-tiptap-extension-link-CJAQIgui.js +262 -0
  214. package/dist/vendor-tiptap-extension-list-item-DF-iMpqO.js +33 -0
  215. package/dist/vendor-tiptap-extension-ordered-list-CN8MF-kN.js +71 -0
  216. package/dist/vendor-tiptap-extension-paragraph-DI577lM5.js +33 -0
  217. package/dist/vendor-tiptap-extension-placeholder-DwAtlfAF.js +52 -0
  218. package/dist/vendor-tiptap-extension-strike-CIty09KN.js +61 -0
  219. package/dist/vendor-tiptap-extension-table-C5nv-GUb.js +213 -0
  220. package/dist/vendor-tiptap-extension-table-cell-DXbBhJW3.js +40 -0
  221. package/dist/vendor-tiptap-extension-table-header-rtggsYXA.js +40 -0
  222. package/dist/vendor-tiptap-extension-table-row-67khjMDt.js +22 -0
  223. package/dist/vendor-tiptap-extension-text-D1OHb_a1.js +8 -0
  224. package/dist/vendor-tiptap-extension-underline-IqWixw3m.js +40 -0
  225. package/dist/vendor-tiptap-markdown-DVxB1hbO.js +825 -0
  226. package/dist/vendor-tiptap-starter-kit-CPH9gu2X.js +29 -0
  227. package/dist/vendor-tiptap-vue-3-CkBe4_xM.js +225 -0
  228. package/dist/vendor-truncate-html-Bx1HJzRq.js +145 -0
  229. package/dist/vendor-uc-micro-4lbSaZOs.js +17 -0
  230. package/dist/vendor-vee-validate-i18n-zT8NxX3R.js +93 -0
  231. package/dist/vendor-vee-validate-rules-DDeNM2Gc.js +314 -0
  232. package/dist/vendor-vue-currency-input-DxWnS-HB.js +315 -0
  233. package/dist/vendor-vue-devtools-api-aVYGocXp.js +93 -0
  234. package/dist/vendor-vue-i18n-DPtOLen3.js +1359 -0
  235. package/dist/vendor-vue3-application-insights-dAGGfA_M.js +69 -0
  236. package/dist/vendor-vue3-touch-events-8Pa3HHlV.js +169 -0
  237. package/dist/vendor-vuepic-vue-datepicker-DglsiNYa.js +4997 -0
  238. package/dist/vendor-vueuse-components-DtK_mxpP.js +219 -0
  239. package/dist/vendor-vueuse-core-cB-c7DzH.js +5129 -0
  240. package/dist/vendor-vueuse-shared-Dg7PMM0z.js +1169 -0
  241. package/dist/vendor-w3c-keyname-CLxH8j-f.js +92 -0
  242. package/dist/vendor-whatwg-fetch-l0sNRNKZ.js +1 -0
  243. package/package.json +5 -4
  244. package/ui/components/atoms/vc-icon/vc-lucide-icon.vue +2 -1
  245. package/dist/vendor-boolbase-Cp9L0GAZ.js +0 -25
  246. package/dist/vendor-cheerio-HN9zIPZn.js +0 -3135
  247. package/dist/vendor-cheerio-select-5Ry0HvBq.js +0 -306
  248. package/dist/vendor-css-select-DRIZ9kfZ.js +0 -966
  249. package/dist/vendor-css-what-DuPJ1HEF.js +0 -448
  250. package/dist/vendor-cypress-signalr-mock-BKdBJpdt.js +0 -778
  251. package/dist/vendor-date-fns-515YWkk-.js +0 -6724
  252. package/dist/vendor-dom-serializer-nQMsqjYW.js +0 -286
  253. package/dist/vendor-dom7-CJLPMwy5.js +0 -941
  254. package/dist/vendor-domelementtype-CjSzQey5.js +0 -53
  255. package/dist/vendor-domhandler-9z8cS16a.js +0 -484
  256. package/dist/vendor-dompurify-CRFzu7ib.js +0 -1336
  257. package/dist/vendor-domutils-Bc-Opz-v.js +0 -981
  258. package/dist/vendor-entities-Bfsx4xOQ.js +0 -636
  259. package/dist/vendor-floating-ui-core-wV8u8QP4.js +0 -511
  260. package/dist/vendor-floating-ui-dom-DDnRPs17.js +0 -706
  261. package/dist/vendor-floating-ui-utils-OMIFy1QU.js +0 -296
  262. package/dist/vendor-floating-ui-vue-D-tCDAMm.js +0 -167
  263. package/dist/vendor-fontsource-plus-jakarta-sans.css +0 -1
  264. package/dist/vendor-headlessui-vue-CY9FRgTb.js +0 -83
  265. package/dist/vendor-htmlparser2-B1dhFPOs.js +0 -1426
  266. package/dist/vendor-iconify-vue-DfRGgyNu.js +0 -1840
  267. package/dist/vendor-intlify-core-base-BuknsFQe.js +0 -1876
  268. package/dist/vendor-intlify-message-compiler-CuOQDWx1.js +0 -1508
  269. package/dist/vendor-intlify-shared-Cz4YRMuC.js +0 -241
  270. package/dist/vendor-iso-639-1-BJCk9DvE.js +0 -819
  271. package/dist/vendor-linkify-it-CKUf4vsc.js +0 -830
  272. package/dist/vendor-linkifyjs-BfyGgbCh.js +0 -1756
  273. package/dist/vendor-lodash-es-BySUOlwf.js +0 -18333
  274. package/dist/vendor-markdown-it-D-apazHa.js +0 -6000
  275. package/dist/vendor-markdown-it-task-lists-rxMVH6Ku.js +0 -131
  276. package/dist/vendor-mdurl-BNh2CCgT.js +0 -537
  277. package/dist/vendor-microsoft-applicationinsights-analytics-js-kG3lLg8X.js +0 -1275
  278. package/dist/vendor-microsoft-applicationinsights-cfgsync-js-C0uQkiQq.js +0 -591
  279. package/dist/vendor-microsoft-applicationinsights-channel-js-Dyd_PXA3.js +0 -2153
  280. package/dist/vendor-microsoft-applicationinsights-common-CfmP1_Qr.js +0 -2470
  281. package/dist/vendor-microsoft-applicationinsights-core-js-Cq4YSEvZ.js +0 -6589
  282. package/dist/vendor-microsoft-applicationinsights-dependencies-js-C56OBFr4.js +0 -1510
  283. package/dist/vendor-microsoft-applicationinsights-properties-js-CBJTBawx.js +0 -761
  284. package/dist/vendor-microsoft-applicationinsights-shims-CX8sJgar.js +0 -70
  285. package/dist/vendor-microsoft-applicationinsights-web-pim2ri-g.js +0 -667
  286. package/dist/vendor-microsoft-dynamicproto-js-CFBBUu9p.js +0 -520
  287. package/dist/vendor-microsoft-signalr-dUnlRsGm.js +0 -3339
  288. package/dist/vendor-moment-Mki5YqAR.js +0 -5679
  289. package/dist/vendor-nevware21-ts-async-CLMApQ9E.js +0 -395
  290. package/dist/vendor-nevware21-ts-utils-e8v8Jty3.js +0 -1160
  291. package/dist/vendor-nth-check-Bx8TxtJt.js +0 -157
  292. package/dist/vendor-orderedmap-dGG6uMFJ.js +0 -137
  293. package/dist/vendor-parse5-Bt2NhSzR.js +0 -8432
  294. package/dist/vendor-parse5-htmlparser2-tree-adapter-BUUtKzf8.js +0 -216
  295. package/dist/vendor-popperjs-core-Cr2byIky.js +0 -1790
  296. package/dist/vendor-prettier-B4PaeWRQ.js +0 -98
  297. package/dist/vendor-prosemirror-commands-BH9lWGpW.js +0 -561
  298. package/dist/vendor-prosemirror-dropcursor-CeyPcxrA.js +0 -146
  299. package/dist/vendor-prosemirror-gapcursor-U8UoUJII.js +0 -236
  300. package/dist/vendor-prosemirror-history-BDaJkvNx.js +0 -414
  301. package/dist/vendor-prosemirror-keymap-BbWvIWmH.js +0 -128
  302. package/dist/vendor-prosemirror-markdown-gB0PXBbz.js +0 -866
  303. package/dist/vendor-prosemirror-model-BZu3WVcD.js +0 -3463
  304. package/dist/vendor-prosemirror-schema-list-Bl9NpKA7.js +0 -158
  305. package/dist/vendor-prosemirror-state-BvL9Pxph.js +0 -1003
  306. package/dist/vendor-prosemirror-tables-17qAnviK.js +0 -2159
  307. package/dist/vendor-prosemirror-transform-CE9VV3qg.js +0 -2156
  308. package/dist/vendor-prosemirror-view-CU2WTHT7.js +0 -5811
  309. package/dist/vendor-punycode-js-iAs5RxMf.js +0 -441
  310. package/dist/vendor-rope-sequence-BdXDKoGt.js +0 -207
  311. package/dist/vendor-semver-CVLMK-S4.js +0 -2702
  312. package/dist/vendor-ssr-window-s6OpKa3O.js +0 -150
  313. package/dist/vendor-swiper-CdiyNHVt.js +0 -5679
  314. package/dist/vendor-tippy-js-DWFe2TfK.js +0 -1647
  315. package/dist/vendor-tiptap-core-NfwGfaQk.js +0 -4910
  316. package/dist/vendor-tiptap-extension-blockquote-jmWBTtsI.js +0 -57
  317. package/dist/vendor-tiptap-extension-bold-p5frh4ak.js +0 -97
  318. package/dist/vendor-tiptap-extension-bubble-menu-KUhZSfrs.js +0 -218
  319. package/dist/vendor-tiptap-extension-bullet-list-COmZRoSB.js +0 -73
  320. package/dist/vendor-tiptap-extension-code-block-DyTARZss.js +0 -221
  321. package/dist/vendor-tiptap-extension-code-jVv6CXpX.js +0 -75
  322. package/dist/vendor-tiptap-extension-document-DssuotYs.js +0 -13
  323. package/dist/vendor-tiptap-extension-dropcursor-BoO0Qv91.js +0 -26
  324. package/dist/vendor-tiptap-extension-floating-menu-CrO8CN5w.js +0 -165
  325. package/dist/vendor-tiptap-extension-gapcursor-KpsWEoMD.js +0 -30
  326. package/dist/vendor-tiptap-extension-hard-break-ldOzhSvf.js +0 -68
  327. package/dist/vendor-tiptap-extension-heading-CKz2llX0.js +0 -77
  328. package/dist/vendor-tiptap-extension-history-DeKZ2VQ9.js +0 -48
  329. package/dist/vendor-tiptap-extension-horizontal-rule-CAjWRyDS.js +0 -92
  330. package/dist/vendor-tiptap-extension-image-ZagcEYuk.js +0 -76
  331. package/dist/vendor-tiptap-extension-italic-CM4xdznY.js +0 -96
  332. package/dist/vendor-tiptap-extension-link-Z-AMC4Ri.js +0 -414
  333. package/dist/vendor-tiptap-extension-list-item-BJi5QpXc.js +0 -37
  334. package/dist/vendor-tiptap-extension-ordered-list-C_TMrfBE.js +0 -97
  335. package/dist/vendor-tiptap-extension-paragraph-CQw0E0Au.js +0 -39
  336. package/dist/vendor-tiptap-extension-placeholder-BBNVKfa_.js +0 -66
  337. package/dist/vendor-tiptap-extension-strike-DUyMYX1Z.js +0 -79
  338. package/dist/vendor-tiptap-extension-table-cell-CoDIMPA5.js +0 -47
  339. package/dist/vendor-tiptap-extension-table-header-DvbGHnmw.js +0 -47
  340. package/dist/vendor-tiptap-extension-table-row-D1uqN5Aj.js +0 -26
  341. package/dist/vendor-tiptap-extension-table-tKS4MOM4.js +0 -354
  342. package/dist/vendor-tiptap-extension-text-DtRBhKB2.js +0 -12
  343. package/dist/vendor-tiptap-extension-underline-DqaSFp_P.js +0 -50
  344. package/dist/vendor-tiptap-markdown-7-PCADTU.js +0 -1017
  345. package/dist/vendor-tiptap-starter-kit-CDSV_Zuu.js +0 -88
  346. package/dist/vendor-tiptap-vue-3-DZg2fjq_.js +0 -268
  347. package/dist/vendor-truncate-html-3qQY0Djo.js +0 -196
  348. package/dist/vendor-uc-micro-jjt6LQ65.js +0 -23
  349. package/dist/vendor-vee-validate-i18n-v_gHjRmD.js +0 -154
  350. package/dist/vendor-vee-validate-rules-DzV3VY3N.js +0 -536
  351. package/dist/vendor-vue-currency-input-DGAkEFBO.js +0 -545
  352. package/dist/vendor-vue-devtools-api-DXYR8qBG.js +0 -169
  353. package/dist/vendor-vue-i18n-Co752uk3.js +0 -1897
  354. package/dist/vendor-vue3-application-insights-CYWFCr_J.js +0 -119
  355. package/dist/vendor-vue3-touch-events-BJEAiSa3.js +0 -416
  356. package/dist/vendor-vuepic-vue-datepicker-BSWXRSiu.js +0 -5019
  357. package/dist/vendor-vueuse-components-l1bL12mE.js +0 -339
  358. package/dist/vendor-vueuse-core-DGcJOmwG.js +0 -7743
  359. package/dist/vendor-vueuse-shared-_mOXsFuM.js +0 -1568
  360. package/dist/vendor-w3c-keyname-BOm2dtJm.js +0 -121
@@ -1,3339 +0,0 @@
1
- // Licensed to the .NET Foundation under one or more agreements.
2
- // The .NET Foundation licenses this file to you under the MIT license.
3
- /** Error thrown when an HTTP request fails. */
4
- class HttpError extends Error {
5
- /** Constructs a new instance of {@link @microsoft/signalr.HttpError}.
6
- *
7
- * @param {string} errorMessage A descriptive error message.
8
- * @param {number} statusCode The HTTP status code represented by this error.
9
- */
10
- constructor(errorMessage, statusCode) {
11
- const trueProto = new.target.prototype;
12
- super(`${errorMessage}: Status code '${statusCode}'`);
13
- this.statusCode = statusCode;
14
- // Workaround issue in Typescript compiler
15
- // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
16
- this.__proto__ = trueProto;
17
- }
18
- }
19
- /** Error thrown when a timeout elapses. */
20
- class TimeoutError extends Error {
21
- /** Constructs a new instance of {@link @microsoft/signalr.TimeoutError}.
22
- *
23
- * @param {string} errorMessage A descriptive error message.
24
- */
25
- constructor(errorMessage = "A timeout occurred.") {
26
- const trueProto = new.target.prototype;
27
- super(errorMessage);
28
- // Workaround issue in Typescript compiler
29
- // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
30
- this.__proto__ = trueProto;
31
- }
32
- }
33
- /** Error thrown when an action is aborted. */
34
- class AbortError extends Error {
35
- /** Constructs a new instance of {@link AbortError}.
36
- *
37
- * @param {string} errorMessage A descriptive error message.
38
- */
39
- constructor(errorMessage = "An abort occurred.") {
40
- const trueProto = new.target.prototype;
41
- super(errorMessage);
42
- // Workaround issue in Typescript compiler
43
- // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
44
- this.__proto__ = trueProto;
45
- }
46
- }
47
- /** Error thrown when the selected transport is unsupported by the browser. */
48
- /** @private */
49
- class UnsupportedTransportError extends Error {
50
- /** Constructs a new instance of {@link @microsoft/signalr.UnsupportedTransportError}.
51
- *
52
- * @param {string} message A descriptive error message.
53
- * @param {HttpTransportType} transport The {@link @microsoft/signalr.HttpTransportType} this error occurred on.
54
- */
55
- constructor(message, transport) {
56
- const trueProto = new.target.prototype;
57
- super(message);
58
- this.transport = transport;
59
- this.errorType = 'UnsupportedTransportError';
60
- // Workaround issue in Typescript compiler
61
- // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
62
- this.__proto__ = trueProto;
63
- }
64
- }
65
- /** Error thrown when the selected transport is disabled by the browser. */
66
- /** @private */
67
- class DisabledTransportError extends Error {
68
- /** Constructs a new instance of {@link @microsoft/signalr.DisabledTransportError}.
69
- *
70
- * @param {string} message A descriptive error message.
71
- * @param {HttpTransportType} transport The {@link @microsoft/signalr.HttpTransportType} this error occurred on.
72
- */
73
- constructor(message, transport) {
74
- const trueProto = new.target.prototype;
75
- super(message);
76
- this.transport = transport;
77
- this.errorType = 'DisabledTransportError';
78
- // Workaround issue in Typescript compiler
79
- // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
80
- this.__proto__ = trueProto;
81
- }
82
- }
83
- /** Error thrown when the selected transport cannot be started. */
84
- /** @private */
85
- class FailedToStartTransportError extends Error {
86
- /** Constructs a new instance of {@link @microsoft/signalr.FailedToStartTransportError}.
87
- *
88
- * @param {string} message A descriptive error message.
89
- * @param {HttpTransportType} transport The {@link @microsoft/signalr.HttpTransportType} this error occurred on.
90
- */
91
- constructor(message, transport) {
92
- const trueProto = new.target.prototype;
93
- super(message);
94
- this.transport = transport;
95
- this.errorType = 'FailedToStartTransportError';
96
- // Workaround issue in Typescript compiler
97
- // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
98
- this.__proto__ = trueProto;
99
- }
100
- }
101
- /** Error thrown when the negotiation with the server failed to complete. */
102
- /** @private */
103
- class FailedToNegotiateWithServerError extends Error {
104
- /** Constructs a new instance of {@link @microsoft/signalr.FailedToNegotiateWithServerError}.
105
- *
106
- * @param {string} message A descriptive error message.
107
- */
108
- constructor(message) {
109
- const trueProto = new.target.prototype;
110
- super(message);
111
- this.errorType = 'FailedToNegotiateWithServerError';
112
- // Workaround issue in Typescript compiler
113
- // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
114
- this.__proto__ = trueProto;
115
- }
116
- }
117
- /** Error thrown when multiple errors have occurred. */
118
- /** @private */
119
- class AggregateErrors extends Error {
120
- /** Constructs a new instance of {@link @microsoft/signalr.AggregateErrors}.
121
- *
122
- * @param {string} message A descriptive error message.
123
- * @param {Error[]} innerErrors The collection of errors this error is aggregating.
124
- */
125
- constructor(message, innerErrors) {
126
- const trueProto = new.target.prototype;
127
- super(message);
128
- this.innerErrors = innerErrors;
129
- // Workaround issue in Typescript compiler
130
- // https://github.com/Microsoft/TypeScript/issues/13965#issuecomment-278570200
131
- this.__proto__ = trueProto;
132
- }
133
- }
134
-
135
- // Licensed to the .NET Foundation under one or more agreements.
136
- // The .NET Foundation licenses this file to you under the MIT license.
137
- /** Represents an HTTP response. */
138
- class HttpResponse {
139
- constructor(statusCode, statusText, content) {
140
- this.statusCode = statusCode;
141
- this.statusText = statusText;
142
- this.content = content;
143
- }
144
- }
145
- /** Abstraction over an HTTP client.
146
- *
147
- * This class provides an abstraction over an HTTP client so that a different implementation can be provided on different platforms.
148
- */
149
- class HttpClient {
150
- get(url, options) {
151
- return this.send({
152
- ...options,
153
- method: "GET",
154
- url,
155
- });
156
- }
157
- post(url, options) {
158
- return this.send({
159
- ...options,
160
- method: "POST",
161
- url,
162
- });
163
- }
164
- delete(url, options) {
165
- return this.send({
166
- ...options,
167
- method: "DELETE",
168
- url,
169
- });
170
- }
171
- /** Gets all cookies that apply to the specified URL.
172
- *
173
- * @param url The URL that the cookies are valid for.
174
- * @returns {string} A string containing all the key-value cookie pairs for the specified URL.
175
- */
176
- // @ts-ignore
177
- getCookieString(url) {
178
- return "";
179
- }
180
- }
181
-
182
- // Licensed to the .NET Foundation under one or more agreements.
183
- // The .NET Foundation licenses this file to you under the MIT license.
184
- // These values are designed to match the ASP.NET Log Levels since that's the pattern we're emulating here.
185
- /** Indicates the severity of a log message.
186
- *
187
- * Log Levels are ordered in increasing severity. So `Debug` is more severe than `Trace`, etc.
188
- */
189
- var LogLevel;
190
- (function (LogLevel) {
191
- /** Log level for very low severity diagnostic messages. */
192
- LogLevel[LogLevel["Trace"] = 0] = "Trace";
193
- /** Log level for low severity diagnostic messages. */
194
- LogLevel[LogLevel["Debug"] = 1] = "Debug";
195
- /** Log level for informational diagnostic messages. */
196
- LogLevel[LogLevel["Information"] = 2] = "Information";
197
- /** Log level for diagnostic messages that indicate a non-fatal problem. */
198
- LogLevel[LogLevel["Warning"] = 3] = "Warning";
199
- /** Log level for diagnostic messages that indicate a failure in the current operation. */
200
- LogLevel[LogLevel["Error"] = 4] = "Error";
201
- /** Log level for diagnostic messages that indicate a failure that will terminate the entire application. */
202
- LogLevel[LogLevel["Critical"] = 5] = "Critical";
203
- /** The highest possible log level. Used when configuring logging to indicate that no log messages should be emitted. */
204
- LogLevel[LogLevel["None"] = 6] = "None";
205
- })(LogLevel || (LogLevel = {}));
206
-
207
- // Licensed to the .NET Foundation under one or more agreements.
208
- // The .NET Foundation licenses this file to you under the MIT license.
209
- /** A logger that does nothing when log messages are sent to it. */
210
- class NullLogger {
211
- constructor() { }
212
- /** @inheritDoc */
213
- // eslint-disable-next-line
214
- log(_logLevel, _message) {
215
- }
216
- }
217
- /** The singleton instance of the {@link @microsoft/signalr.NullLogger}. */
218
- NullLogger.instance = new NullLogger();
219
-
220
- // Licensed to the .NET Foundation under one or more agreements.
221
- // The .NET Foundation licenses this file to you under the MIT license.
222
- // Version token that will be replaced by the prepack command
223
- /** The version of the SignalR client. */
224
- const VERSION = "8.0.7";
225
- /** @private */
226
- class Arg {
227
- static isRequired(val, name) {
228
- if (val === null || val === undefined) {
229
- throw new Error(`The '${name}' argument is required.`);
230
- }
231
- }
232
- static isNotEmpty(val, name) {
233
- if (!val || val.match(/^\s*$/)) {
234
- throw new Error(`The '${name}' argument should not be empty.`);
235
- }
236
- }
237
- static isIn(val, values, name) {
238
- // TypeScript enums have keys for **both** the name and the value of each enum member on the type itself.
239
- if (!(val in values)) {
240
- throw new Error(`Unknown ${name} value: ${val}.`);
241
- }
242
- }
243
- }
244
- /** @private */
245
- class Platform {
246
- // react-native has a window but no document so we should check both
247
- static get isBrowser() {
248
- return !Platform.isNode && typeof window === "object" && typeof window.document === "object";
249
- }
250
- // WebWorkers don't have a window object so the isBrowser check would fail
251
- static get isWebWorker() {
252
- return !Platform.isNode && typeof self === "object" && "importScripts" in self;
253
- }
254
- // react-native has a window but no document
255
- static get isReactNative() {
256
- return !Platform.isNode && typeof window === "object" && typeof window.document === "undefined";
257
- }
258
- // Node apps shouldn't have a window object, but WebWorkers don't either
259
- // so we need to check for both WebWorker and window
260
- static get isNode() {
261
- return typeof process !== "undefined" && process.release && process.release.name === "node";
262
- }
263
- }
264
- /** @private */
265
- function getDataDetail(data, includeContent) {
266
- let detail = "";
267
- if (isArrayBuffer(data)) {
268
- detail = `Binary data of length ${data.byteLength}`;
269
- if (includeContent) {
270
- detail += `. Content: '${formatArrayBuffer(data)}'`;
271
- }
272
- }
273
- else if (typeof data === "string") {
274
- detail = `String data of length ${data.length}`;
275
- if (includeContent) {
276
- detail += `. Content: '${data}'`;
277
- }
278
- }
279
- return detail;
280
- }
281
- /** @private */
282
- function formatArrayBuffer(data) {
283
- const view = new Uint8Array(data);
284
- // Uint8Array.map only supports returning another Uint8Array?
285
- let str = "";
286
- view.forEach((num) => {
287
- const pad = num < 16 ? "0" : "";
288
- str += `0x${pad}${num.toString(16)} `;
289
- });
290
- // Trim of trailing space.
291
- return str.substr(0, str.length - 1);
292
- }
293
- // Also in signalr-protocol-msgpack/Utils.ts
294
- /** @private */
295
- function isArrayBuffer(val) {
296
- return val && typeof ArrayBuffer !== "undefined" &&
297
- (val instanceof ArrayBuffer ||
298
- // Sometimes we get an ArrayBuffer that doesn't satisfy instanceof
299
- (val.constructor && val.constructor.name === "ArrayBuffer"));
300
- }
301
- /** @private */
302
- async function sendMessage(logger, transportName, httpClient, url, content, options) {
303
- const headers = {};
304
- const [name, value] = getUserAgentHeader();
305
- headers[name] = value;
306
- logger.log(LogLevel.Trace, `(${transportName} transport) sending data. ${getDataDetail(content, options.logMessageContent)}.`);
307
- const responseType = isArrayBuffer(content) ? "arraybuffer" : "text";
308
- const response = await httpClient.post(url, {
309
- content,
310
- headers: { ...headers, ...options.headers },
311
- responseType,
312
- timeout: options.timeout,
313
- withCredentials: options.withCredentials,
314
- });
315
- logger.log(LogLevel.Trace, `(${transportName} transport) request complete. Response status: ${response.statusCode}.`);
316
- }
317
- /** @private */
318
- function createLogger(logger) {
319
- if (logger === undefined) {
320
- return new ConsoleLogger(LogLevel.Information);
321
- }
322
- if (logger === null) {
323
- return NullLogger.instance;
324
- }
325
- if (logger.log !== undefined) {
326
- return logger;
327
- }
328
- return new ConsoleLogger(logger);
329
- }
330
- /** @private */
331
- class SubjectSubscription {
332
- constructor(subject, observer) {
333
- this._subject = subject;
334
- this._observer = observer;
335
- }
336
- dispose() {
337
- const index = this._subject.observers.indexOf(this._observer);
338
- if (index > -1) {
339
- this._subject.observers.splice(index, 1);
340
- }
341
- if (this._subject.observers.length === 0 && this._subject.cancelCallback) {
342
- this._subject.cancelCallback().catch((_) => { });
343
- }
344
- }
345
- }
346
- /** @private */
347
- class ConsoleLogger {
348
- constructor(minimumLogLevel) {
349
- this._minLevel = minimumLogLevel;
350
- this.out = console;
351
- }
352
- log(logLevel, message) {
353
- if (logLevel >= this._minLevel) {
354
- const msg = `[${new Date().toISOString()}] ${LogLevel[logLevel]}: ${message}`;
355
- switch (logLevel) {
356
- case LogLevel.Critical:
357
- case LogLevel.Error:
358
- this.out.error(msg);
359
- break;
360
- case LogLevel.Warning:
361
- this.out.warn(msg);
362
- break;
363
- case LogLevel.Information:
364
- this.out.info(msg);
365
- break;
366
- default:
367
- // console.debug only goes to attached debuggers in Node, so we use console.log for Trace and Debug
368
- this.out.log(msg);
369
- break;
370
- }
371
- }
372
- }
373
- }
374
- /** @private */
375
- function getUserAgentHeader() {
376
- let userAgentHeaderName = "X-SignalR-User-Agent";
377
- if (Platform.isNode) {
378
- userAgentHeaderName = "User-Agent";
379
- }
380
- return [userAgentHeaderName, constructUserAgent(VERSION, getOsName(), getRuntime(), getRuntimeVersion())];
381
- }
382
- /** @private */
383
- function constructUserAgent(version, os, runtime, runtimeVersion) {
384
- // Microsoft SignalR/[Version] ([Detailed Version]; [Operating System]; [Runtime]; [Runtime Version])
385
- let userAgent = "Microsoft SignalR/";
386
- const majorAndMinor = version.split(".");
387
- userAgent += `${majorAndMinor[0]}.${majorAndMinor[1]}`;
388
- userAgent += ` (${version}; `;
389
- if (os && os !== "") {
390
- userAgent += `${os}; `;
391
- }
392
- else {
393
- userAgent += "Unknown OS; ";
394
- }
395
- userAgent += `${runtime}`;
396
- if (runtimeVersion) {
397
- userAgent += `; ${runtimeVersion}`;
398
- }
399
- else {
400
- userAgent += "; Unknown Runtime Version";
401
- }
402
- userAgent += ")";
403
- return userAgent;
404
- }
405
- // eslint-disable-next-line spaced-comment
406
- function getOsName() {
407
- if (Platform.isNode) {
408
- switch (process.platform) {
409
- case "win32":
410
- return "Windows NT";
411
- case "darwin":
412
- return "macOS";
413
- case "linux":
414
- return "Linux";
415
- default:
416
- return process.platform;
417
- }
418
- }
419
- else {
420
- return "";
421
- }
422
- }
423
- // eslint-disable-next-line spaced-comment
424
- function getRuntimeVersion() {
425
- if (Platform.isNode) {
426
- return process.versions.node;
427
- }
428
- return undefined;
429
- }
430
- function getRuntime() {
431
- if (Platform.isNode) {
432
- return "NodeJS";
433
- }
434
- else {
435
- return "Browser";
436
- }
437
- }
438
- /** @private */
439
- function getErrorString(e) {
440
- if (e.stack) {
441
- return e.stack;
442
- }
443
- else if (e.message) {
444
- return e.message;
445
- }
446
- return `${e}`;
447
- }
448
- /** @private */
449
- function getGlobalThis() {
450
- // globalThis is semi-new and not available in Node until v12
451
- if (typeof globalThis !== "undefined") {
452
- return globalThis;
453
- }
454
- if (typeof self !== "undefined") {
455
- return self;
456
- }
457
- if (typeof window !== "undefined") {
458
- return window;
459
- }
460
- if (typeof global !== "undefined") {
461
- return global;
462
- }
463
- throw new Error("could not find global");
464
- }
465
-
466
- // Licensed to the .NET Foundation under one or more agreements.
467
- // The .NET Foundation licenses this file to you under the MIT license.
468
- class FetchHttpClient extends HttpClient {
469
- constructor(logger) {
470
- super();
471
- this._logger = logger;
472
- // Node added a fetch implementation to the global scope starting in v18.
473
- // We need to add a cookie jar in node to be able to share cookies with WebSocket
474
- if (typeof fetch === "undefined" || Platform.isNode) {
475
- // In order to ignore the dynamic require in webpack builds we need to do this magic
476
- // @ts-ignore: TS doesn't know about these names
477
- const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
478
- // Cookies aren't automatically handled in Node so we need to add a CookieJar to preserve cookies across requests
479
- this._jar = new (requireFunc("tough-cookie")).CookieJar();
480
- if (typeof fetch === "undefined") {
481
- this._fetchType = requireFunc("node-fetch");
482
- }
483
- else {
484
- // Use fetch from Node if available
485
- this._fetchType = fetch;
486
- }
487
- // node-fetch doesn't have a nice API for getting and setting cookies
488
- // fetch-cookie will wrap a fetch implementation with a default CookieJar or a provided one
489
- this._fetchType = requireFunc("fetch-cookie")(this._fetchType, this._jar);
490
- }
491
- else {
492
- this._fetchType = fetch.bind(getGlobalThis());
493
- }
494
- if (typeof AbortController === "undefined") {
495
- // In order to ignore the dynamic require in webpack builds we need to do this magic
496
- // @ts-ignore: TS doesn't know about these names
497
- const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
498
- // Node needs EventListener methods on AbortController which our custom polyfill doesn't provide
499
- this._abortControllerType = requireFunc("abort-controller");
500
- }
501
- else {
502
- this._abortControllerType = AbortController;
503
- }
504
- }
505
- /** @inheritDoc */
506
- async send(request) {
507
- // Check that abort was not signaled before calling send
508
- if (request.abortSignal && request.abortSignal.aborted) {
509
- throw new AbortError();
510
- }
511
- if (!request.method) {
512
- throw new Error("No method defined.");
513
- }
514
- if (!request.url) {
515
- throw new Error("No url defined.");
516
- }
517
- const abortController = new this._abortControllerType();
518
- let error;
519
- // Hook our abortSignal into the abort controller
520
- if (request.abortSignal) {
521
- request.abortSignal.onabort = () => {
522
- abortController.abort();
523
- error = new AbortError();
524
- };
525
- }
526
- // If a timeout has been passed in, setup a timeout to call abort
527
- // Type needs to be any to fit window.setTimeout and NodeJS.setTimeout
528
- let timeoutId = null;
529
- if (request.timeout) {
530
- const msTimeout = request.timeout;
531
- timeoutId = setTimeout(() => {
532
- abortController.abort();
533
- this._logger.log(LogLevel.Warning, `Timeout from HTTP request.`);
534
- error = new TimeoutError();
535
- }, msTimeout);
536
- }
537
- if (request.content === "") {
538
- request.content = undefined;
539
- }
540
- if (request.content) {
541
- // Explicitly setting the Content-Type header for React Native on Android platform.
542
- request.headers = request.headers || {};
543
- if (isArrayBuffer(request.content)) {
544
- request.headers["Content-Type"] = "application/octet-stream";
545
- }
546
- else {
547
- request.headers["Content-Type"] = "text/plain;charset=UTF-8";
548
- }
549
- }
550
- let response;
551
- try {
552
- response = await this._fetchType(request.url, {
553
- body: request.content,
554
- cache: "no-cache",
555
- credentials: request.withCredentials === true ? "include" : "same-origin",
556
- headers: {
557
- "X-Requested-With": "XMLHttpRequest",
558
- ...request.headers,
559
- },
560
- method: request.method,
561
- mode: "cors",
562
- redirect: "follow",
563
- signal: abortController.signal,
564
- });
565
- }
566
- catch (e) {
567
- if (error) {
568
- throw error;
569
- }
570
- this._logger.log(LogLevel.Warning, `Error from HTTP request. ${e}.`);
571
- throw e;
572
- }
573
- finally {
574
- if (timeoutId) {
575
- clearTimeout(timeoutId);
576
- }
577
- if (request.abortSignal) {
578
- request.abortSignal.onabort = null;
579
- }
580
- }
581
- if (!response.ok) {
582
- const errorMessage = await deserializeContent(response, "text");
583
- throw new HttpError(errorMessage || response.statusText, response.status);
584
- }
585
- const content = deserializeContent(response, request.responseType);
586
- const payload = await content;
587
- return new HttpResponse(response.status, response.statusText, payload);
588
- }
589
- getCookieString(url) {
590
- let cookies = "";
591
- if (Platform.isNode && this._jar) {
592
- // @ts-ignore: unused variable
593
- this._jar.getCookies(url, (e, c) => cookies = c.join("; "));
594
- }
595
- return cookies;
596
- }
597
- }
598
- function deserializeContent(response, responseType) {
599
- let content;
600
- switch (responseType) {
601
- case "arraybuffer":
602
- content = response.arrayBuffer();
603
- break;
604
- case "text":
605
- content = response.text();
606
- break;
607
- case "blob":
608
- case "document":
609
- case "json":
610
- throw new Error(`${responseType} is not supported.`);
611
- default:
612
- content = response.text();
613
- break;
614
- }
615
- return content;
616
- }
617
-
618
- // Licensed to the .NET Foundation under one or more agreements.
619
- // The .NET Foundation licenses this file to you under the MIT license.
620
- class XhrHttpClient extends HttpClient {
621
- constructor(logger) {
622
- super();
623
- this._logger = logger;
624
- }
625
- /** @inheritDoc */
626
- send(request) {
627
- // Check that abort was not signaled before calling send
628
- if (request.abortSignal && request.abortSignal.aborted) {
629
- return Promise.reject(new AbortError());
630
- }
631
- if (!request.method) {
632
- return Promise.reject(new Error("No method defined."));
633
- }
634
- if (!request.url) {
635
- return Promise.reject(new Error("No url defined."));
636
- }
637
- return new Promise((resolve, reject) => {
638
- const xhr = new XMLHttpRequest();
639
- xhr.open(request.method, request.url, true);
640
- xhr.withCredentials = request.withCredentials === undefined ? true : request.withCredentials;
641
- xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
642
- if (request.content === "") {
643
- request.content = undefined;
644
- }
645
- if (request.content) {
646
- // Explicitly setting the Content-Type header for React Native on Android platform.
647
- if (isArrayBuffer(request.content)) {
648
- xhr.setRequestHeader("Content-Type", "application/octet-stream");
649
- }
650
- else {
651
- xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
652
- }
653
- }
654
- const headers = request.headers;
655
- if (headers) {
656
- Object.keys(headers)
657
- .forEach((header) => {
658
- xhr.setRequestHeader(header, headers[header]);
659
- });
660
- }
661
- if (request.responseType) {
662
- xhr.responseType = request.responseType;
663
- }
664
- if (request.abortSignal) {
665
- request.abortSignal.onabort = () => {
666
- xhr.abort();
667
- reject(new AbortError());
668
- };
669
- }
670
- if (request.timeout) {
671
- xhr.timeout = request.timeout;
672
- }
673
- xhr.onload = () => {
674
- if (request.abortSignal) {
675
- request.abortSignal.onabort = null;
676
- }
677
- if (xhr.status >= 200 && xhr.status < 300) {
678
- resolve(new HttpResponse(xhr.status, xhr.statusText, xhr.response || xhr.responseText));
679
- }
680
- else {
681
- reject(new HttpError(xhr.response || xhr.responseText || xhr.statusText, xhr.status));
682
- }
683
- };
684
- xhr.onerror = () => {
685
- this._logger.log(LogLevel.Warning, `Error from HTTP request. ${xhr.status}: ${xhr.statusText}.`);
686
- reject(new HttpError(xhr.statusText, xhr.status));
687
- };
688
- xhr.ontimeout = () => {
689
- this._logger.log(LogLevel.Warning, `Timeout from HTTP request.`);
690
- reject(new TimeoutError());
691
- };
692
- xhr.send(request.content);
693
- });
694
- }
695
- }
696
-
697
- // Licensed to the .NET Foundation under one or more agreements.
698
- // The .NET Foundation licenses this file to you under the MIT license.
699
- /** Default implementation of {@link @microsoft/signalr.HttpClient}. */
700
- class DefaultHttpClient extends HttpClient {
701
- /** Creates a new instance of the {@link @microsoft/signalr.DefaultHttpClient}, using the provided {@link @microsoft/signalr.ILogger} to log messages. */
702
- constructor(logger) {
703
- super();
704
- if (typeof fetch !== "undefined" || Platform.isNode) {
705
- this._httpClient = new FetchHttpClient(logger);
706
- }
707
- else if (typeof XMLHttpRequest !== "undefined") {
708
- this._httpClient = new XhrHttpClient(logger);
709
- }
710
- else {
711
- throw new Error("No usable HttpClient found.");
712
- }
713
- }
714
- /** @inheritDoc */
715
- send(request) {
716
- // Check that abort was not signaled before calling send
717
- if (request.abortSignal && request.abortSignal.aborted) {
718
- return Promise.reject(new AbortError());
719
- }
720
- if (!request.method) {
721
- return Promise.reject(new Error("No method defined."));
722
- }
723
- if (!request.url) {
724
- return Promise.reject(new Error("No url defined."));
725
- }
726
- return this._httpClient.send(request);
727
- }
728
- getCookieString(url) {
729
- return this._httpClient.getCookieString(url);
730
- }
731
- }
732
-
733
- // Licensed to the .NET Foundation under one or more agreements.
734
- // The .NET Foundation licenses this file to you under the MIT license.
735
- // Not exported from index
736
- /** @private */
737
- class TextMessageFormat {
738
- static write(output) {
739
- return `${output}${TextMessageFormat.RecordSeparator}`;
740
- }
741
- static parse(input) {
742
- if (input[input.length - 1] !== TextMessageFormat.RecordSeparator) {
743
- throw new Error("Message is incomplete.");
744
- }
745
- const messages = input.split(TextMessageFormat.RecordSeparator);
746
- messages.pop();
747
- return messages;
748
- }
749
- }
750
- TextMessageFormat.RecordSeparatorCode = 0x1e;
751
- TextMessageFormat.RecordSeparator = String.fromCharCode(TextMessageFormat.RecordSeparatorCode);
752
-
753
- // Licensed to the .NET Foundation under one or more agreements.
754
- // The .NET Foundation licenses this file to you under the MIT license.
755
- /** @private */
756
- class HandshakeProtocol {
757
- // Handshake request is always JSON
758
- writeHandshakeRequest(handshakeRequest) {
759
- return TextMessageFormat.write(JSON.stringify(handshakeRequest));
760
- }
761
- parseHandshakeResponse(data) {
762
- let messageData;
763
- let remainingData;
764
- if (isArrayBuffer(data)) {
765
- // Format is binary but still need to read JSON text from handshake response
766
- const binaryData = new Uint8Array(data);
767
- const separatorIndex = binaryData.indexOf(TextMessageFormat.RecordSeparatorCode);
768
- if (separatorIndex === -1) {
769
- throw new Error("Message is incomplete.");
770
- }
771
- // content before separator is handshake response
772
- // optional content after is additional messages
773
- const responseLength = separatorIndex + 1;
774
- messageData = String.fromCharCode.apply(null, Array.prototype.slice.call(binaryData.slice(0, responseLength)));
775
- remainingData = (binaryData.byteLength > responseLength) ? binaryData.slice(responseLength).buffer : null;
776
- }
777
- else {
778
- const textData = data;
779
- const separatorIndex = textData.indexOf(TextMessageFormat.RecordSeparator);
780
- if (separatorIndex === -1) {
781
- throw new Error("Message is incomplete.");
782
- }
783
- // content before separator is handshake response
784
- // optional content after is additional messages
785
- const responseLength = separatorIndex + 1;
786
- messageData = textData.substring(0, responseLength);
787
- remainingData = (textData.length > responseLength) ? textData.substring(responseLength) : null;
788
- }
789
- // At this point we should have just the single handshake message
790
- const messages = TextMessageFormat.parse(messageData);
791
- const response = JSON.parse(messages[0]);
792
- if (response.type) {
793
- throw new Error("Expected a handshake response from the server.");
794
- }
795
- const responseMessage = response;
796
- // multiple messages could have arrived with handshake
797
- // return additional data to be parsed as usual, or null if all parsed
798
- return [remainingData, responseMessage];
799
- }
800
- }
801
-
802
- // Licensed to the .NET Foundation under one or more agreements.
803
- // The .NET Foundation licenses this file to you under the MIT license.
804
- /** Defines the type of a Hub Message. */
805
- var MessageType;
806
- (function (MessageType) {
807
- /** Indicates the message is an Invocation message and implements the {@link @microsoft/signalr.InvocationMessage} interface. */
808
- MessageType[MessageType["Invocation"] = 1] = "Invocation";
809
- /** Indicates the message is a StreamItem message and implements the {@link @microsoft/signalr.StreamItemMessage} interface. */
810
- MessageType[MessageType["StreamItem"] = 2] = "StreamItem";
811
- /** Indicates the message is a Completion message and implements the {@link @microsoft/signalr.CompletionMessage} interface. */
812
- MessageType[MessageType["Completion"] = 3] = "Completion";
813
- /** Indicates the message is a Stream Invocation message and implements the {@link @microsoft/signalr.StreamInvocationMessage} interface. */
814
- MessageType[MessageType["StreamInvocation"] = 4] = "StreamInvocation";
815
- /** Indicates the message is a Cancel Invocation message and implements the {@link @microsoft/signalr.CancelInvocationMessage} interface. */
816
- MessageType[MessageType["CancelInvocation"] = 5] = "CancelInvocation";
817
- /** Indicates the message is a Ping message and implements the {@link @microsoft/signalr.PingMessage} interface. */
818
- MessageType[MessageType["Ping"] = 6] = "Ping";
819
- /** Indicates the message is a Close message and implements the {@link @microsoft/signalr.CloseMessage} interface. */
820
- MessageType[MessageType["Close"] = 7] = "Close";
821
- MessageType[MessageType["Ack"] = 8] = "Ack";
822
- MessageType[MessageType["Sequence"] = 9] = "Sequence";
823
- })(MessageType || (MessageType = {}));
824
-
825
- // Licensed to the .NET Foundation under one or more agreements.
826
- // The .NET Foundation licenses this file to you under the MIT license.
827
- /** Stream implementation to stream items to the server. */
828
- class Subject {
829
- constructor() {
830
- this.observers = [];
831
- }
832
- next(item) {
833
- for (const observer of this.observers) {
834
- observer.next(item);
835
- }
836
- }
837
- error(err) {
838
- for (const observer of this.observers) {
839
- if (observer.error) {
840
- observer.error(err);
841
- }
842
- }
843
- }
844
- complete() {
845
- for (const observer of this.observers) {
846
- if (observer.complete) {
847
- observer.complete();
848
- }
849
- }
850
- }
851
- subscribe(observer) {
852
- this.observers.push(observer);
853
- return new SubjectSubscription(this, observer);
854
- }
855
- }
856
-
857
- // Licensed to the .NET Foundation under one or more agreements.
858
- // The .NET Foundation licenses this file to you under the MIT license.
859
- /** @private */
860
- class MessageBuffer {
861
- constructor(protocol, connection, bufferSize) {
862
- this._bufferSize = 100000;
863
- this._messages = [];
864
- this._totalMessageCount = 0;
865
- this._waitForSequenceMessage = false;
866
- // Message IDs start at 1 and always increment by 1
867
- this._nextReceivingSequenceId = 1;
868
- this._latestReceivedSequenceId = 0;
869
- this._bufferedByteCount = 0;
870
- this._reconnectInProgress = false;
871
- this._protocol = protocol;
872
- this._connection = connection;
873
- this._bufferSize = bufferSize;
874
- }
875
- async _send(message) {
876
- const serializedMessage = this._protocol.writeMessage(message);
877
- let backpressurePromise = Promise.resolve();
878
- // Only count invocation messages. Acks, pings, etc. don't need to be resent on reconnect
879
- if (this._isInvocationMessage(message)) {
880
- this._totalMessageCount++;
881
- let backpressurePromiseResolver = () => { };
882
- let backpressurePromiseRejector = () => { };
883
- if (isArrayBuffer(serializedMessage)) {
884
- this._bufferedByteCount += serializedMessage.byteLength;
885
- }
886
- else {
887
- this._bufferedByteCount += serializedMessage.length;
888
- }
889
- if (this._bufferedByteCount >= this._bufferSize) {
890
- backpressurePromise = new Promise((resolve, reject) => {
891
- backpressurePromiseResolver = resolve;
892
- backpressurePromiseRejector = reject;
893
- });
894
- }
895
- this._messages.push(new BufferedItem(serializedMessage, this._totalMessageCount, backpressurePromiseResolver, backpressurePromiseRejector));
896
- }
897
- try {
898
- // If this is set it means we are reconnecting or resending
899
- // We don't want to send on a disconnected connection
900
- // And we don't want to send if resend is running since that would mean sending
901
- // this message twice
902
- if (!this._reconnectInProgress) {
903
- await this._connection.send(serializedMessage);
904
- }
905
- }
906
- catch {
907
- this._disconnected();
908
- }
909
- await backpressurePromise;
910
- }
911
- _ack(ackMessage) {
912
- let newestAckedMessage = -1;
913
- // Find index of newest message being acked
914
- for (let index = 0; index < this._messages.length; index++) {
915
- const element = this._messages[index];
916
- if (element._id <= ackMessage.sequenceId) {
917
- newestAckedMessage = index;
918
- if (isArrayBuffer(element._message)) {
919
- this._bufferedByteCount -= element._message.byteLength;
920
- }
921
- else {
922
- this._bufferedByteCount -= element._message.length;
923
- }
924
- // resolve items that have already been sent and acked
925
- element._resolver();
926
- }
927
- else if (this._bufferedByteCount < this._bufferSize) {
928
- // resolve items that now fall under the buffer limit but haven't been acked
929
- element._resolver();
930
- }
931
- else {
932
- break;
933
- }
934
- }
935
- if (newestAckedMessage !== -1) {
936
- // We're removing everything including the message pointed to, so add 1
937
- this._messages = this._messages.slice(newestAckedMessage + 1);
938
- }
939
- }
940
- _shouldProcessMessage(message) {
941
- if (this._waitForSequenceMessage) {
942
- if (message.type !== MessageType.Sequence) {
943
- return false;
944
- }
945
- else {
946
- this._waitForSequenceMessage = false;
947
- return true;
948
- }
949
- }
950
- // No special processing for acks, pings, etc.
951
- if (!this._isInvocationMessage(message)) {
952
- return true;
953
- }
954
- const currentId = this._nextReceivingSequenceId;
955
- this._nextReceivingSequenceId++;
956
- if (currentId <= this._latestReceivedSequenceId) {
957
- if (currentId === this._latestReceivedSequenceId) {
958
- // Should only hit this if we just reconnected and the server is sending
959
- // Messages it has buffered, which would mean it hasn't seen an Ack for these messages
960
- this._ackTimer();
961
- }
962
- // Ignore, this is a duplicate message
963
- return false;
964
- }
965
- this._latestReceivedSequenceId = currentId;
966
- // Only start the timer for sending an Ack message when we have a message to ack. This also conveniently solves
967
- // timer throttling by not having a recursive timer, and by starting the timer via a network call (recv)
968
- this._ackTimer();
969
- return true;
970
- }
971
- _resetSequence(message) {
972
- if (message.sequenceId > this._nextReceivingSequenceId) {
973
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
974
- this._connection.stop(new Error("Sequence ID greater than amount of messages we've received."));
975
- return;
976
- }
977
- this._nextReceivingSequenceId = message.sequenceId;
978
- }
979
- _disconnected() {
980
- this._reconnectInProgress = true;
981
- this._waitForSequenceMessage = true;
982
- }
983
- async _resend() {
984
- const sequenceId = this._messages.length !== 0
985
- ? this._messages[0]._id
986
- : this._totalMessageCount + 1;
987
- await this._connection.send(this._protocol.writeMessage({ type: MessageType.Sequence, sequenceId }));
988
- // Get a local variable to the _messages, just in case messages are acked while resending
989
- // Which would slice the _messages array (which creates a new copy)
990
- const messages = this._messages;
991
- for (const element of messages) {
992
- await this._connection.send(element._message);
993
- }
994
- this._reconnectInProgress = false;
995
- }
996
- _dispose(error) {
997
- error !== null && error !== void 0 ? error : (error = new Error("Unable to reconnect to server."));
998
- // Unblock backpressure if any
999
- for (const element of this._messages) {
1000
- element._rejector(error);
1001
- }
1002
- }
1003
- _isInvocationMessage(message) {
1004
- // There is no way to check if something implements an interface.
1005
- // So we individually check the messages in a switch statement.
1006
- // To make sure we don't miss any message types we rely on the compiler
1007
- // seeing the function returns a value and it will do the
1008
- // exhaustive check for us on the switch statement, since we don't use 'case default'
1009
- switch (message.type) {
1010
- case MessageType.Invocation:
1011
- case MessageType.StreamItem:
1012
- case MessageType.Completion:
1013
- case MessageType.StreamInvocation:
1014
- case MessageType.CancelInvocation:
1015
- return true;
1016
- case MessageType.Close:
1017
- case MessageType.Sequence:
1018
- case MessageType.Ping:
1019
- case MessageType.Ack:
1020
- return false;
1021
- }
1022
- }
1023
- _ackTimer() {
1024
- if (this._ackTimerHandle === undefined) {
1025
- this._ackTimerHandle = setTimeout(async () => {
1026
- try {
1027
- if (!this._reconnectInProgress) {
1028
- await this._connection.send(this._protocol.writeMessage({ type: MessageType.Ack, sequenceId: this._latestReceivedSequenceId }));
1029
- }
1030
- // Ignore errors, that means the connection is closed and we don't care about the Ack message anymore.
1031
- }
1032
- catch { }
1033
- clearTimeout(this._ackTimerHandle);
1034
- this._ackTimerHandle = undefined;
1035
- // 1 second delay so we don't spam Ack messages if there are many messages being received at once.
1036
- }, 1000);
1037
- }
1038
- }
1039
- }
1040
- class BufferedItem {
1041
- constructor(message, id, resolver, rejector) {
1042
- this._message = message;
1043
- this._id = id;
1044
- this._resolver = resolver;
1045
- this._rejector = rejector;
1046
- }
1047
- }
1048
-
1049
- // Licensed to the .NET Foundation under one or more agreements.
1050
- // The .NET Foundation licenses this file to you under the MIT license.
1051
- const DEFAULT_TIMEOUT_IN_MS = 30 * 1000;
1052
- const DEFAULT_PING_INTERVAL_IN_MS = 15 * 1000;
1053
- const DEFAULT_STATEFUL_RECONNECT_BUFFER_SIZE = 100000;
1054
- /** Describes the current state of the {@link HubConnection} to the server. */
1055
- var HubConnectionState;
1056
- (function (HubConnectionState) {
1057
- /** The hub connection is disconnected. */
1058
- HubConnectionState["Disconnected"] = "Disconnected";
1059
- /** The hub connection is connecting. */
1060
- HubConnectionState["Connecting"] = "Connecting";
1061
- /** The hub connection is connected. */
1062
- HubConnectionState["Connected"] = "Connected";
1063
- /** The hub connection is disconnecting. */
1064
- HubConnectionState["Disconnecting"] = "Disconnecting";
1065
- /** The hub connection is reconnecting. */
1066
- HubConnectionState["Reconnecting"] = "Reconnecting";
1067
- })(HubConnectionState || (HubConnectionState = {}));
1068
- /** Represents a connection to a SignalR Hub. */
1069
- class HubConnection {
1070
- /** @internal */
1071
- // Using a public static factory method means we can have a private constructor and an _internal_
1072
- // create method that can be used by HubConnectionBuilder. An "internal" constructor would just
1073
- // be stripped away and the '.d.ts' file would have no constructor, which is interpreted as a
1074
- // public parameter-less constructor.
1075
- static create(connection, logger, protocol, reconnectPolicy, serverTimeoutInMilliseconds, keepAliveIntervalInMilliseconds, statefulReconnectBufferSize) {
1076
- return new HubConnection(connection, logger, protocol, reconnectPolicy, serverTimeoutInMilliseconds, keepAliveIntervalInMilliseconds, statefulReconnectBufferSize);
1077
- }
1078
- constructor(connection, logger, protocol, reconnectPolicy, serverTimeoutInMilliseconds, keepAliveIntervalInMilliseconds, statefulReconnectBufferSize) {
1079
- this._nextKeepAlive = 0;
1080
- this._freezeEventListener = () => {
1081
- this._logger.log(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://learn.microsoft.com/aspnet/core/signalr/javascript-client#bsleep");
1082
- };
1083
- Arg.isRequired(connection, "connection");
1084
- Arg.isRequired(logger, "logger");
1085
- Arg.isRequired(protocol, "protocol");
1086
- this.serverTimeoutInMilliseconds = serverTimeoutInMilliseconds !== null && serverTimeoutInMilliseconds !== void 0 ? serverTimeoutInMilliseconds : DEFAULT_TIMEOUT_IN_MS;
1087
- this.keepAliveIntervalInMilliseconds = keepAliveIntervalInMilliseconds !== null && keepAliveIntervalInMilliseconds !== void 0 ? keepAliveIntervalInMilliseconds : DEFAULT_PING_INTERVAL_IN_MS;
1088
- this._statefulReconnectBufferSize = statefulReconnectBufferSize !== null && statefulReconnectBufferSize !== void 0 ? statefulReconnectBufferSize : DEFAULT_STATEFUL_RECONNECT_BUFFER_SIZE;
1089
- this._logger = logger;
1090
- this._protocol = protocol;
1091
- this.connection = connection;
1092
- this._reconnectPolicy = reconnectPolicy;
1093
- this._handshakeProtocol = new HandshakeProtocol();
1094
- this.connection.onreceive = (data) => this._processIncomingData(data);
1095
- this.connection.onclose = (error) => this._connectionClosed(error);
1096
- this._callbacks = {};
1097
- this._methods = {};
1098
- this._closedCallbacks = [];
1099
- this._reconnectingCallbacks = [];
1100
- this._reconnectedCallbacks = [];
1101
- this._invocationId = 0;
1102
- this._receivedHandshakeResponse = false;
1103
- this._connectionState = HubConnectionState.Disconnected;
1104
- this._connectionStarted = false;
1105
- this._cachedPingMessage = this._protocol.writeMessage({ type: MessageType.Ping });
1106
- }
1107
- /** Indicates the state of the {@link HubConnection} to the server. */
1108
- get state() {
1109
- return this._connectionState;
1110
- }
1111
- /** Represents the connection id of the {@link HubConnection} on the server. The connection id will be null when the connection is either
1112
- * in the disconnected state or if the negotiation step was skipped.
1113
- */
1114
- get connectionId() {
1115
- return this.connection ? (this.connection.connectionId || null) : null;
1116
- }
1117
- /** Indicates the url of the {@link HubConnection} to the server. */
1118
- get baseUrl() {
1119
- return this.connection.baseUrl || "";
1120
- }
1121
- /**
1122
- * Sets a new url for the HubConnection. Note that the url can only be changed when the connection is in either the Disconnected or
1123
- * Reconnecting states.
1124
- * @param {string} url The url to connect to.
1125
- */
1126
- set baseUrl(url) {
1127
- if (this._connectionState !== HubConnectionState.Disconnected && this._connectionState !== HubConnectionState.Reconnecting) {
1128
- throw new Error("The HubConnection must be in the Disconnected or Reconnecting state to change the url.");
1129
- }
1130
- if (!url) {
1131
- throw new Error("The HubConnection url must be a valid url.");
1132
- }
1133
- this.connection.baseUrl = url;
1134
- }
1135
- /** Starts the connection.
1136
- *
1137
- * @returns {Promise<void>} A Promise that resolves when the connection has been successfully established, or rejects with an error.
1138
- */
1139
- start() {
1140
- this._startPromise = this._startWithStateTransitions();
1141
- return this._startPromise;
1142
- }
1143
- async _startWithStateTransitions() {
1144
- if (this._connectionState !== HubConnectionState.Disconnected) {
1145
- return Promise.reject(new Error("Cannot start a HubConnection that is not in the 'Disconnected' state."));
1146
- }
1147
- this._connectionState = HubConnectionState.Connecting;
1148
- this._logger.log(LogLevel.Debug, "Starting HubConnection.");
1149
- try {
1150
- await this._startInternal();
1151
- if (Platform.isBrowser) {
1152
- // Log when the browser freezes the tab so users know why their connection unexpectedly stopped working
1153
- window.document.addEventListener("freeze", this._freezeEventListener);
1154
- }
1155
- this._connectionState = HubConnectionState.Connected;
1156
- this._connectionStarted = true;
1157
- this._logger.log(LogLevel.Debug, "HubConnection connected successfully.");
1158
- }
1159
- catch (e) {
1160
- this._connectionState = HubConnectionState.Disconnected;
1161
- this._logger.log(LogLevel.Debug, `HubConnection failed to start successfully because of error '${e}'.`);
1162
- return Promise.reject(e);
1163
- }
1164
- }
1165
- async _startInternal() {
1166
- this._stopDuringStartError = undefined;
1167
- this._receivedHandshakeResponse = false;
1168
- // Set up the promise before any connection is (re)started otherwise it could race with received messages
1169
- const handshakePromise = new Promise((resolve, reject) => {
1170
- this._handshakeResolver = resolve;
1171
- this._handshakeRejecter = reject;
1172
- });
1173
- await this.connection.start(this._protocol.transferFormat);
1174
- try {
1175
- let version = this._protocol.version;
1176
- if (!this.connection.features.reconnect) {
1177
- // Stateful Reconnect starts with HubProtocol version 2, newer clients connecting to older servers will fail to connect due to
1178
- // the handshake only supporting version 1, so we will try to send version 1 during the handshake to keep old servers working.
1179
- version = 1;
1180
- }
1181
- const handshakeRequest = {
1182
- protocol: this._protocol.name,
1183
- version,
1184
- };
1185
- this._logger.log(LogLevel.Debug, "Sending handshake request.");
1186
- await this._sendMessage(this._handshakeProtocol.writeHandshakeRequest(handshakeRequest));
1187
- this._logger.log(LogLevel.Information, `Using HubProtocol '${this._protocol.name}'.`);
1188
- // defensively cleanup timeout in case we receive a message from the server before we finish start
1189
- this._cleanupTimeout();
1190
- this._resetTimeoutPeriod();
1191
- this._resetKeepAliveInterval();
1192
- await handshakePromise;
1193
- // It's important to check the stopDuringStartError instead of just relying on the handshakePromise
1194
- // being rejected on close, because this continuation can run after both the handshake completed successfully
1195
- // and the connection was closed.
1196
- if (this._stopDuringStartError) {
1197
- // It's important to throw instead of returning a rejected promise, because we don't want to allow any state
1198
- // transitions to occur between now and the calling code observing the exceptions. Returning a rejected promise
1199
- // will cause the calling continuation to get scheduled to run later.
1200
- // eslint-disable-next-line @typescript-eslint/no-throw-literal
1201
- throw this._stopDuringStartError;
1202
- }
1203
- const useStatefulReconnect = this.connection.features.reconnect || false;
1204
- if (useStatefulReconnect) {
1205
- this._messageBuffer = new MessageBuffer(this._protocol, this.connection, this._statefulReconnectBufferSize);
1206
- this.connection.features.disconnected = this._messageBuffer._disconnected.bind(this._messageBuffer);
1207
- this.connection.features.resend = () => {
1208
- if (this._messageBuffer) {
1209
- return this._messageBuffer._resend();
1210
- }
1211
- };
1212
- }
1213
- if (!this.connection.features.inherentKeepAlive) {
1214
- await this._sendMessage(this._cachedPingMessage);
1215
- }
1216
- }
1217
- catch (e) {
1218
- this._logger.log(LogLevel.Debug, `Hub handshake failed with error '${e}' during start(). Stopping HubConnection.`);
1219
- this._cleanupTimeout();
1220
- this._cleanupPingTimer();
1221
- // HttpConnection.stop() should not complete until after the onclose callback is invoked.
1222
- // This will transition the HubConnection to the disconnected state before HttpConnection.stop() completes.
1223
- await this.connection.stop(e);
1224
- throw e;
1225
- }
1226
- }
1227
- /** Stops the connection.
1228
- *
1229
- * @returns {Promise<void>} A Promise that resolves when the connection has been successfully terminated, or rejects with an error.
1230
- */
1231
- async stop() {
1232
- // Capture the start promise before the connection might be restarted in an onclose callback.
1233
- const startPromise = this._startPromise;
1234
- this.connection.features.reconnect = false;
1235
- this._stopPromise = this._stopInternal();
1236
- await this._stopPromise;
1237
- try {
1238
- // Awaiting undefined continues immediately
1239
- await startPromise;
1240
- }
1241
- catch (e) {
1242
- // This exception is returned to the user as a rejected Promise from the start method.
1243
- }
1244
- }
1245
- _stopInternal(error) {
1246
- if (this._connectionState === HubConnectionState.Disconnected) {
1247
- this._logger.log(LogLevel.Debug, `Call to HubConnection.stop(${error}) ignored because it is already in the disconnected state.`);
1248
- return Promise.resolve();
1249
- }
1250
- if (this._connectionState === HubConnectionState.Disconnecting) {
1251
- this._logger.log(LogLevel.Debug, `Call to HttpConnection.stop(${error}) ignored because the connection is already in the disconnecting state.`);
1252
- return this._stopPromise;
1253
- }
1254
- const state = this._connectionState;
1255
- this._connectionState = HubConnectionState.Disconnecting;
1256
- this._logger.log(LogLevel.Debug, "Stopping HubConnection.");
1257
- if (this._reconnectDelayHandle) {
1258
- // We're in a reconnect delay which means the underlying connection is currently already stopped.
1259
- // Just clear the handle to stop the reconnect loop (which no one is waiting on thankfully) and
1260
- // fire the onclose callbacks.
1261
- this._logger.log(LogLevel.Debug, "Connection stopped during reconnect delay. Done reconnecting.");
1262
- clearTimeout(this._reconnectDelayHandle);
1263
- this._reconnectDelayHandle = undefined;
1264
- this._completeClose();
1265
- return Promise.resolve();
1266
- }
1267
- if (state === HubConnectionState.Connected) {
1268
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
1269
- this._sendCloseMessage();
1270
- }
1271
- this._cleanupTimeout();
1272
- this._cleanupPingTimer();
1273
- this._stopDuringStartError = error || new AbortError("The connection was stopped before the hub handshake could complete.");
1274
- // HttpConnection.stop() should not complete until after either HttpConnection.start() fails
1275
- // or the onclose callback is invoked. The onclose callback will transition the HubConnection
1276
- // to the disconnected state if need be before HttpConnection.stop() completes.
1277
- return this.connection.stop(error);
1278
- }
1279
- async _sendCloseMessage() {
1280
- try {
1281
- await this._sendWithProtocol(this._createCloseMessage());
1282
- }
1283
- catch {
1284
- // Ignore, this is a best effort attempt to let the server know the client closed gracefully.
1285
- }
1286
- }
1287
- /** Invokes a streaming hub method on the server using the specified name and arguments.
1288
- *
1289
- * @typeparam T The type of the items returned by the server.
1290
- * @param {string} methodName The name of the server method to invoke.
1291
- * @param {any[]} args The arguments used to invoke the server method.
1292
- * @returns {IStreamResult<T>} An object that yields results from the server as they are received.
1293
- */
1294
- stream(methodName, ...args) {
1295
- const [streams, streamIds] = this._replaceStreamingParams(args);
1296
- const invocationDescriptor = this._createStreamInvocation(methodName, args, streamIds);
1297
- // eslint-disable-next-line prefer-const
1298
- let promiseQueue;
1299
- const subject = new Subject();
1300
- subject.cancelCallback = () => {
1301
- const cancelInvocation = this._createCancelInvocation(invocationDescriptor.invocationId);
1302
- delete this._callbacks[invocationDescriptor.invocationId];
1303
- return promiseQueue.then(() => {
1304
- return this._sendWithProtocol(cancelInvocation);
1305
- });
1306
- };
1307
- this._callbacks[invocationDescriptor.invocationId] = (invocationEvent, error) => {
1308
- if (error) {
1309
- subject.error(error);
1310
- return;
1311
- }
1312
- else if (invocationEvent) {
1313
- // invocationEvent will not be null when an error is not passed to the callback
1314
- if (invocationEvent.type === MessageType.Completion) {
1315
- if (invocationEvent.error) {
1316
- subject.error(new Error(invocationEvent.error));
1317
- }
1318
- else {
1319
- subject.complete();
1320
- }
1321
- }
1322
- else {
1323
- subject.next((invocationEvent.item));
1324
- }
1325
- }
1326
- };
1327
- promiseQueue = this._sendWithProtocol(invocationDescriptor)
1328
- .catch((e) => {
1329
- subject.error(e);
1330
- delete this._callbacks[invocationDescriptor.invocationId];
1331
- });
1332
- this._launchStreams(streams, promiseQueue);
1333
- return subject;
1334
- }
1335
- _sendMessage(message) {
1336
- this._resetKeepAliveInterval();
1337
- return this.connection.send(message);
1338
- }
1339
- /**
1340
- * Sends a js object to the server.
1341
- * @param message The js object to serialize and send.
1342
- */
1343
- _sendWithProtocol(message) {
1344
- if (this._messageBuffer) {
1345
- return this._messageBuffer._send(message);
1346
- }
1347
- else {
1348
- return this._sendMessage(this._protocol.writeMessage(message));
1349
- }
1350
- }
1351
- /** Invokes a hub method on the server using the specified name and arguments. Does not wait for a response from the receiver.
1352
- *
1353
- * The Promise returned by this method resolves when the client has sent the invocation to the server. The server may still
1354
- * be processing the invocation.
1355
- *
1356
- * @param {string} methodName The name of the server method to invoke.
1357
- * @param {any[]} args The arguments used to invoke the server method.
1358
- * @returns {Promise<void>} A Promise that resolves when the invocation has been successfully sent, or rejects with an error.
1359
- */
1360
- send(methodName, ...args) {
1361
- const [streams, streamIds] = this._replaceStreamingParams(args);
1362
- const sendPromise = this._sendWithProtocol(this._createInvocation(methodName, args, true, streamIds));
1363
- this._launchStreams(streams, sendPromise);
1364
- return sendPromise;
1365
- }
1366
- /** Invokes a hub method on the server using the specified name and arguments.
1367
- *
1368
- * The Promise returned by this method resolves when the server indicates it has finished invoking the method. When the promise
1369
- * resolves, the server has finished invoking the method. If the server method returns a result, it is produced as the result of
1370
- * resolving the Promise.
1371
- *
1372
- * @typeparam T The expected return type.
1373
- * @param {string} methodName The name of the server method to invoke.
1374
- * @param {any[]} args The arguments used to invoke the server method.
1375
- * @returns {Promise<T>} A Promise that resolves with the result of the server method (if any), or rejects with an error.
1376
- */
1377
- invoke(methodName, ...args) {
1378
- const [streams, streamIds] = this._replaceStreamingParams(args);
1379
- const invocationDescriptor = this._createInvocation(methodName, args, false, streamIds);
1380
- const p = new Promise((resolve, reject) => {
1381
- // invocationId will always have a value for a non-blocking invocation
1382
- this._callbacks[invocationDescriptor.invocationId] = (invocationEvent, error) => {
1383
- if (error) {
1384
- reject(error);
1385
- return;
1386
- }
1387
- else if (invocationEvent) {
1388
- // invocationEvent will not be null when an error is not passed to the callback
1389
- if (invocationEvent.type === MessageType.Completion) {
1390
- if (invocationEvent.error) {
1391
- reject(new Error(invocationEvent.error));
1392
- }
1393
- else {
1394
- resolve(invocationEvent.result);
1395
- }
1396
- }
1397
- else {
1398
- reject(new Error(`Unexpected message type: ${invocationEvent.type}`));
1399
- }
1400
- }
1401
- };
1402
- const promiseQueue = this._sendWithProtocol(invocationDescriptor)
1403
- .catch((e) => {
1404
- reject(e);
1405
- // invocationId will always have a value for a non-blocking invocation
1406
- delete this._callbacks[invocationDescriptor.invocationId];
1407
- });
1408
- this._launchStreams(streams, promiseQueue);
1409
- });
1410
- return p;
1411
- }
1412
- on(methodName, newMethod) {
1413
- if (!methodName || !newMethod) {
1414
- return;
1415
- }
1416
- methodName = methodName.toLowerCase();
1417
- if (!this._methods[methodName]) {
1418
- this._methods[methodName] = [];
1419
- }
1420
- // Preventing adding the same handler multiple times.
1421
- if (this._methods[methodName].indexOf(newMethod) !== -1) {
1422
- return;
1423
- }
1424
- this._methods[methodName].push(newMethod);
1425
- }
1426
- off(methodName, method) {
1427
- if (!methodName) {
1428
- return;
1429
- }
1430
- methodName = methodName.toLowerCase();
1431
- const handlers = this._methods[methodName];
1432
- if (!handlers) {
1433
- return;
1434
- }
1435
- if (method) {
1436
- const removeIdx = handlers.indexOf(method);
1437
- if (removeIdx !== -1) {
1438
- handlers.splice(removeIdx, 1);
1439
- if (handlers.length === 0) {
1440
- delete this._methods[methodName];
1441
- }
1442
- }
1443
- }
1444
- else {
1445
- delete this._methods[methodName];
1446
- }
1447
- }
1448
- /** Registers a handler that will be invoked when the connection is closed.
1449
- *
1450
- * @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).
1451
- */
1452
- onclose(callback) {
1453
- if (callback) {
1454
- this._closedCallbacks.push(callback);
1455
- }
1456
- }
1457
- /** Registers a handler that will be invoked when the connection starts reconnecting.
1458
- *
1459
- * @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).
1460
- */
1461
- onreconnecting(callback) {
1462
- if (callback) {
1463
- this._reconnectingCallbacks.push(callback);
1464
- }
1465
- }
1466
- /** Registers a handler that will be invoked when the connection successfully reconnects.
1467
- *
1468
- * @param {Function} callback The handler that will be invoked when the connection successfully reconnects.
1469
- */
1470
- onreconnected(callback) {
1471
- if (callback) {
1472
- this._reconnectedCallbacks.push(callback);
1473
- }
1474
- }
1475
- _processIncomingData(data) {
1476
- this._cleanupTimeout();
1477
- if (!this._receivedHandshakeResponse) {
1478
- data = this._processHandshakeResponse(data);
1479
- this._receivedHandshakeResponse = true;
1480
- }
1481
- // Data may have all been read when processing handshake response
1482
- if (data) {
1483
- // Parse the messages
1484
- const messages = this._protocol.parseMessages(data, this._logger);
1485
- for (const message of messages) {
1486
- if (this._messageBuffer && !this._messageBuffer._shouldProcessMessage(message)) {
1487
- // Don't process the message, we are either waiting for a SequenceMessage or received a duplicate message
1488
- continue;
1489
- }
1490
- switch (message.type) {
1491
- case MessageType.Invocation:
1492
- this._invokeClientMethod(message)
1493
- .catch((e) => {
1494
- this._logger.log(LogLevel.Error, `Invoke client method threw error: ${getErrorString(e)}`);
1495
- });
1496
- break;
1497
- case MessageType.StreamItem:
1498
- case MessageType.Completion: {
1499
- const callback = this._callbacks[message.invocationId];
1500
- if (callback) {
1501
- if (message.type === MessageType.Completion) {
1502
- delete this._callbacks[message.invocationId];
1503
- }
1504
- try {
1505
- callback(message);
1506
- }
1507
- catch (e) {
1508
- this._logger.log(LogLevel.Error, `Stream callback threw error: ${getErrorString(e)}`);
1509
- }
1510
- }
1511
- break;
1512
- }
1513
- case MessageType.Ping:
1514
- // Don't care about pings
1515
- break;
1516
- case MessageType.Close: {
1517
- this._logger.log(LogLevel.Information, "Close message received from server.");
1518
- const error = message.error ? new Error("Server returned an error on close: " + message.error) : undefined;
1519
- if (message.allowReconnect === true) {
1520
- // It feels wrong not to await connection.stop() here, but processIncomingData is called as part of an onreceive callback which is not async,
1521
- // this is already the behavior for serverTimeout(), and HttpConnection.Stop() should catch and log all possible exceptions.
1522
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
1523
- this.connection.stop(error);
1524
- }
1525
- else {
1526
- // We cannot await stopInternal() here, but subsequent calls to stop() will await this if stopInternal() is still ongoing.
1527
- this._stopPromise = this._stopInternal(error);
1528
- }
1529
- break;
1530
- }
1531
- case MessageType.Ack:
1532
- if (this._messageBuffer) {
1533
- this._messageBuffer._ack(message);
1534
- }
1535
- break;
1536
- case MessageType.Sequence:
1537
- if (this._messageBuffer) {
1538
- this._messageBuffer._resetSequence(message);
1539
- }
1540
- break;
1541
- default:
1542
- this._logger.log(LogLevel.Warning, `Invalid message type: ${message.type}.`);
1543
- break;
1544
- }
1545
- }
1546
- }
1547
- this._resetTimeoutPeriod();
1548
- }
1549
- _processHandshakeResponse(data) {
1550
- let responseMessage;
1551
- let remainingData;
1552
- try {
1553
- [remainingData, responseMessage] = this._handshakeProtocol.parseHandshakeResponse(data);
1554
- }
1555
- catch (e) {
1556
- const message = "Error parsing handshake response: " + e;
1557
- this._logger.log(LogLevel.Error, message);
1558
- const error = new Error(message);
1559
- this._handshakeRejecter(error);
1560
- throw error;
1561
- }
1562
- if (responseMessage.error) {
1563
- const message = "Server returned handshake error: " + responseMessage.error;
1564
- this._logger.log(LogLevel.Error, message);
1565
- const error = new Error(message);
1566
- this._handshakeRejecter(error);
1567
- throw error;
1568
- }
1569
- else {
1570
- this._logger.log(LogLevel.Debug, "Server handshake complete.");
1571
- }
1572
- this._handshakeResolver();
1573
- return remainingData;
1574
- }
1575
- _resetKeepAliveInterval() {
1576
- if (this.connection.features.inherentKeepAlive) {
1577
- return;
1578
- }
1579
- // Set the time we want the next keep alive to be sent
1580
- // Timer will be setup on next message receive
1581
- this._nextKeepAlive = new Date().getTime() + this.keepAliveIntervalInMilliseconds;
1582
- this._cleanupPingTimer();
1583
- }
1584
- _resetTimeoutPeriod() {
1585
- if (!this.connection.features || !this.connection.features.inherentKeepAlive) {
1586
- // Set the timeout timer
1587
- this._timeoutHandle = setTimeout(() => this.serverTimeout(), this.serverTimeoutInMilliseconds);
1588
- // Set keepAlive timer if there isn't one
1589
- if (this._pingServerHandle === undefined) {
1590
- let nextPing = this._nextKeepAlive - new Date().getTime();
1591
- if (nextPing < 0) {
1592
- nextPing = 0;
1593
- }
1594
- // The timer needs to be set from a networking callback to avoid Chrome timer throttling from causing timers to run once a minute
1595
- this._pingServerHandle = setTimeout(async () => {
1596
- if (this._connectionState === HubConnectionState.Connected) {
1597
- try {
1598
- await this._sendMessage(this._cachedPingMessage);
1599
- }
1600
- catch {
1601
- // We don't care about the error. It should be seen elsewhere in the client.
1602
- // The connection is probably in a bad or closed state now, cleanup the timer so it stops triggering
1603
- this._cleanupPingTimer();
1604
- }
1605
- }
1606
- }, nextPing);
1607
- }
1608
- }
1609
- }
1610
- // eslint-disable-next-line @typescript-eslint/naming-convention
1611
- serverTimeout() {
1612
- // The server hasn't talked to us in a while. It doesn't like us anymore ... :(
1613
- // Terminate the connection, but we don't need to wait on the promise. This could trigger reconnecting.
1614
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
1615
- this.connection.stop(new Error("Server timeout elapsed without receiving a message from the server."));
1616
- }
1617
- async _invokeClientMethod(invocationMessage) {
1618
- const methodName = invocationMessage.target.toLowerCase();
1619
- const methods = this._methods[methodName];
1620
- if (!methods) {
1621
- this._logger.log(LogLevel.Warning, `No client method with the name '${methodName}' found.`);
1622
- // No handlers provided by client but the server is expecting a response still, so we send an error
1623
- if (invocationMessage.invocationId) {
1624
- this._logger.log(LogLevel.Warning, `No result given for '${methodName}' method and invocation ID '${invocationMessage.invocationId}'.`);
1625
- await this._sendWithProtocol(this._createCompletionMessage(invocationMessage.invocationId, "Client didn't provide a result.", null));
1626
- }
1627
- return;
1628
- }
1629
- // Avoid issues with handlers removing themselves thus modifying the list while iterating through it
1630
- const methodsCopy = methods.slice();
1631
- // Server expects a response
1632
- const expectsResponse = invocationMessage.invocationId ? true : false;
1633
- // We preserve the last result or exception but still call all handlers
1634
- let res;
1635
- let exception;
1636
- let completionMessage;
1637
- for (const m of methodsCopy) {
1638
- try {
1639
- const prevRes = res;
1640
- res = await m.apply(this, invocationMessage.arguments);
1641
- if (expectsResponse && res && prevRes) {
1642
- this._logger.log(LogLevel.Error, `Multiple results provided for '${methodName}'. Sending error to server.`);
1643
- completionMessage = this._createCompletionMessage(invocationMessage.invocationId, `Client provided multiple results.`, null);
1644
- }
1645
- // Ignore exception if we got a result after, the exception will be logged
1646
- exception = undefined;
1647
- }
1648
- catch (e) {
1649
- exception = e;
1650
- this._logger.log(LogLevel.Error, `A callback for the method '${methodName}' threw error '${e}'.`);
1651
- }
1652
- }
1653
- if (completionMessage) {
1654
- await this._sendWithProtocol(completionMessage);
1655
- }
1656
- else if (expectsResponse) {
1657
- // If there is an exception that means either no result was given or a handler after a result threw
1658
- if (exception) {
1659
- completionMessage = this._createCompletionMessage(invocationMessage.invocationId, `${exception}`, null);
1660
- }
1661
- else if (res !== undefined) {
1662
- completionMessage = this._createCompletionMessage(invocationMessage.invocationId, null, res);
1663
- }
1664
- else {
1665
- this._logger.log(LogLevel.Warning, `No result given for '${methodName}' method and invocation ID '${invocationMessage.invocationId}'.`);
1666
- // Client didn't provide a result or throw from a handler, server expects a response so we send an error
1667
- completionMessage = this._createCompletionMessage(invocationMessage.invocationId, "Client didn't provide a result.", null);
1668
- }
1669
- await this._sendWithProtocol(completionMessage);
1670
- }
1671
- else {
1672
- if (res) {
1673
- this._logger.log(LogLevel.Error, `Result given for '${methodName}' method but server is not expecting a result.`);
1674
- }
1675
- }
1676
- }
1677
- _connectionClosed(error) {
1678
- this._logger.log(LogLevel.Debug, `HubConnection.connectionClosed(${error}) called while in state ${this._connectionState}.`);
1679
- // Triggering this.handshakeRejecter is insufficient because it could already be resolved without the continuation having run yet.
1680
- this._stopDuringStartError = this._stopDuringStartError || error || new AbortError("The underlying connection was closed before the hub handshake could complete.");
1681
- // If the handshake is in progress, start will be waiting for the handshake promise, so we complete it.
1682
- // If it has already completed, this should just noop.
1683
- if (this._handshakeResolver) {
1684
- this._handshakeResolver();
1685
- }
1686
- this._cancelCallbacksWithError(error || new Error("Invocation canceled due to the underlying connection being closed."));
1687
- this._cleanupTimeout();
1688
- this._cleanupPingTimer();
1689
- if (this._connectionState === HubConnectionState.Disconnecting) {
1690
- this._completeClose(error);
1691
- }
1692
- else if (this._connectionState === HubConnectionState.Connected && this._reconnectPolicy) {
1693
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
1694
- this._reconnect(error);
1695
- }
1696
- else if (this._connectionState === HubConnectionState.Connected) {
1697
- this._completeClose(error);
1698
- }
1699
- // If none of the above if conditions were true were called the HubConnection must be in either:
1700
- // 1. The Connecting state in which case the handshakeResolver will complete it and stopDuringStartError will fail it.
1701
- // 2. The Reconnecting state in which case the handshakeResolver will complete it and stopDuringStartError will fail the current reconnect attempt
1702
- // and potentially continue the reconnect() loop.
1703
- // 3. The Disconnected state in which case we're already done.
1704
- }
1705
- _completeClose(error) {
1706
- if (this._connectionStarted) {
1707
- this._connectionState = HubConnectionState.Disconnected;
1708
- this._connectionStarted = false;
1709
- if (this._messageBuffer) {
1710
- this._messageBuffer._dispose(error !== null && error !== void 0 ? error : new Error("Connection closed."));
1711
- this._messageBuffer = undefined;
1712
- }
1713
- if (Platform.isBrowser) {
1714
- window.document.removeEventListener("freeze", this._freezeEventListener);
1715
- }
1716
- try {
1717
- this._closedCallbacks.forEach((c) => c.apply(this, [error]));
1718
- }
1719
- catch (e) {
1720
- this._logger.log(LogLevel.Error, `An onclose callback called with error '${error}' threw error '${e}'.`);
1721
- }
1722
- }
1723
- }
1724
- async _reconnect(error) {
1725
- const reconnectStartTime = Date.now();
1726
- let previousReconnectAttempts = 0;
1727
- let retryError = error !== undefined ? error : new Error("Attempting to reconnect due to a unknown error.");
1728
- let nextRetryDelay = this._getNextRetryDelay(previousReconnectAttempts++, 0, retryError);
1729
- if (nextRetryDelay === null) {
1730
- this._logger.log(LogLevel.Debug, "Connection not reconnecting because the IRetryPolicy returned null on the first reconnect attempt.");
1731
- this._completeClose(error);
1732
- return;
1733
- }
1734
- this._connectionState = HubConnectionState.Reconnecting;
1735
- if (error) {
1736
- this._logger.log(LogLevel.Information, `Connection reconnecting because of error '${error}'.`);
1737
- }
1738
- else {
1739
- this._logger.log(LogLevel.Information, "Connection reconnecting.");
1740
- }
1741
- if (this._reconnectingCallbacks.length !== 0) {
1742
- try {
1743
- this._reconnectingCallbacks.forEach((c) => c.apply(this, [error]));
1744
- }
1745
- catch (e) {
1746
- this._logger.log(LogLevel.Error, `An onreconnecting callback called with error '${error}' threw error '${e}'.`);
1747
- }
1748
- // Exit early if an onreconnecting callback called connection.stop().
1749
- if (this._connectionState !== HubConnectionState.Reconnecting) {
1750
- this._logger.log(LogLevel.Debug, "Connection left the reconnecting state in onreconnecting callback. Done reconnecting.");
1751
- return;
1752
- }
1753
- }
1754
- while (nextRetryDelay !== null) {
1755
- this._logger.log(LogLevel.Information, `Reconnect attempt number ${previousReconnectAttempts} will start in ${nextRetryDelay} ms.`);
1756
- await new Promise((resolve) => {
1757
- this._reconnectDelayHandle = setTimeout(resolve, nextRetryDelay);
1758
- });
1759
- this._reconnectDelayHandle = undefined;
1760
- if (this._connectionState !== HubConnectionState.Reconnecting) {
1761
- this._logger.log(LogLevel.Debug, "Connection left the reconnecting state during reconnect delay. Done reconnecting.");
1762
- return;
1763
- }
1764
- try {
1765
- await this._startInternal();
1766
- this._connectionState = HubConnectionState.Connected;
1767
- this._logger.log(LogLevel.Information, "HubConnection reconnected successfully.");
1768
- if (this._reconnectedCallbacks.length !== 0) {
1769
- try {
1770
- this._reconnectedCallbacks.forEach((c) => c.apply(this, [this.connection.connectionId]));
1771
- }
1772
- catch (e) {
1773
- this._logger.log(LogLevel.Error, `An onreconnected callback called with connectionId '${this.connection.connectionId}; threw error '${e}'.`);
1774
- }
1775
- }
1776
- return;
1777
- }
1778
- catch (e) {
1779
- this._logger.log(LogLevel.Information, `Reconnect attempt failed because of error '${e}'.`);
1780
- if (this._connectionState !== HubConnectionState.Reconnecting) {
1781
- this._logger.log(LogLevel.Debug, `Connection moved to the '${this._connectionState}' from the reconnecting state during reconnect attempt. Done reconnecting.`);
1782
- // The TypeScript compiler thinks that connectionState must be Connected here. The TypeScript compiler is wrong.
1783
- if (this._connectionState === HubConnectionState.Disconnecting) {
1784
- this._completeClose();
1785
- }
1786
- return;
1787
- }
1788
- retryError = e instanceof Error ? e : new Error(e.toString());
1789
- nextRetryDelay = this._getNextRetryDelay(previousReconnectAttempts++, Date.now() - reconnectStartTime, retryError);
1790
- }
1791
- }
1792
- this._logger.log(LogLevel.Information, `Reconnect retries have been exhausted after ${Date.now() - reconnectStartTime} ms and ${previousReconnectAttempts} failed attempts. Connection disconnecting.`);
1793
- this._completeClose();
1794
- }
1795
- _getNextRetryDelay(previousRetryCount, elapsedMilliseconds, retryReason) {
1796
- try {
1797
- return this._reconnectPolicy.nextRetryDelayInMilliseconds({
1798
- elapsedMilliseconds,
1799
- previousRetryCount,
1800
- retryReason,
1801
- });
1802
- }
1803
- catch (e) {
1804
- this._logger.log(LogLevel.Error, `IRetryPolicy.nextRetryDelayInMilliseconds(${previousRetryCount}, ${elapsedMilliseconds}) threw error '${e}'.`);
1805
- return null;
1806
- }
1807
- }
1808
- _cancelCallbacksWithError(error) {
1809
- const callbacks = this._callbacks;
1810
- this._callbacks = {};
1811
- Object.keys(callbacks)
1812
- .forEach((key) => {
1813
- const callback = callbacks[key];
1814
- try {
1815
- callback(null, error);
1816
- }
1817
- catch (e) {
1818
- this._logger.log(LogLevel.Error, `Stream 'error' callback called with '${error}' threw error: ${getErrorString(e)}`);
1819
- }
1820
- });
1821
- }
1822
- _cleanupPingTimer() {
1823
- if (this._pingServerHandle) {
1824
- clearTimeout(this._pingServerHandle);
1825
- this._pingServerHandle = undefined;
1826
- }
1827
- }
1828
- _cleanupTimeout() {
1829
- if (this._timeoutHandle) {
1830
- clearTimeout(this._timeoutHandle);
1831
- }
1832
- }
1833
- _createInvocation(methodName, args, nonblocking, streamIds) {
1834
- if (nonblocking) {
1835
- if (streamIds.length !== 0) {
1836
- return {
1837
- arguments: args,
1838
- streamIds,
1839
- target: methodName,
1840
- type: MessageType.Invocation,
1841
- };
1842
- }
1843
- else {
1844
- return {
1845
- arguments: args,
1846
- target: methodName,
1847
- type: MessageType.Invocation,
1848
- };
1849
- }
1850
- }
1851
- else {
1852
- const invocationId = this._invocationId;
1853
- this._invocationId++;
1854
- if (streamIds.length !== 0) {
1855
- return {
1856
- arguments: args,
1857
- invocationId: invocationId.toString(),
1858
- streamIds,
1859
- target: methodName,
1860
- type: MessageType.Invocation,
1861
- };
1862
- }
1863
- else {
1864
- return {
1865
- arguments: args,
1866
- invocationId: invocationId.toString(),
1867
- target: methodName,
1868
- type: MessageType.Invocation,
1869
- };
1870
- }
1871
- }
1872
- }
1873
- _launchStreams(streams, promiseQueue) {
1874
- if (streams.length === 0) {
1875
- return;
1876
- }
1877
- // Synchronize stream data so they arrive in-order on the server
1878
- if (!promiseQueue) {
1879
- promiseQueue = Promise.resolve();
1880
- }
1881
- // We want to iterate over the keys, since the keys are the stream ids
1882
- // eslint-disable-next-line guard-for-in
1883
- for (const streamId in streams) {
1884
- streams[streamId].subscribe({
1885
- complete: () => {
1886
- promiseQueue = promiseQueue.then(() => this._sendWithProtocol(this._createCompletionMessage(streamId)));
1887
- },
1888
- error: (err) => {
1889
- let message;
1890
- if (err instanceof Error) {
1891
- message = err.message;
1892
- }
1893
- else if (err && err.toString) {
1894
- message = err.toString();
1895
- }
1896
- else {
1897
- message = "Unknown error";
1898
- }
1899
- promiseQueue = promiseQueue.then(() => this._sendWithProtocol(this._createCompletionMessage(streamId, message)));
1900
- },
1901
- next: (item) => {
1902
- promiseQueue = promiseQueue.then(() => this._sendWithProtocol(this._createStreamItemMessage(streamId, item)));
1903
- },
1904
- });
1905
- }
1906
- }
1907
- _replaceStreamingParams(args) {
1908
- const streams = [];
1909
- const streamIds = [];
1910
- for (let i = 0; i < args.length; i++) {
1911
- const argument = args[i];
1912
- if (this._isObservable(argument)) {
1913
- const streamId = this._invocationId;
1914
- this._invocationId++;
1915
- // Store the stream for later use
1916
- streams[streamId] = argument;
1917
- streamIds.push(streamId.toString());
1918
- // remove stream from args
1919
- args.splice(i, 1);
1920
- }
1921
- }
1922
- return [streams, streamIds];
1923
- }
1924
- _isObservable(arg) {
1925
- // This allows other stream implementations to just work (like rxjs)
1926
- return arg && arg.subscribe && typeof arg.subscribe === "function";
1927
- }
1928
- _createStreamInvocation(methodName, args, streamIds) {
1929
- const invocationId = this._invocationId;
1930
- this._invocationId++;
1931
- if (streamIds.length !== 0) {
1932
- return {
1933
- arguments: args,
1934
- invocationId: invocationId.toString(),
1935
- streamIds,
1936
- target: methodName,
1937
- type: MessageType.StreamInvocation,
1938
- };
1939
- }
1940
- else {
1941
- return {
1942
- arguments: args,
1943
- invocationId: invocationId.toString(),
1944
- target: methodName,
1945
- type: MessageType.StreamInvocation,
1946
- };
1947
- }
1948
- }
1949
- _createCancelInvocation(id) {
1950
- return {
1951
- invocationId: id,
1952
- type: MessageType.CancelInvocation,
1953
- };
1954
- }
1955
- _createStreamItemMessage(id, item) {
1956
- return {
1957
- invocationId: id,
1958
- item,
1959
- type: MessageType.StreamItem,
1960
- };
1961
- }
1962
- _createCompletionMessage(id, error, result) {
1963
- if (error) {
1964
- return {
1965
- error,
1966
- invocationId: id,
1967
- type: MessageType.Completion,
1968
- };
1969
- }
1970
- return {
1971
- invocationId: id,
1972
- result,
1973
- type: MessageType.Completion,
1974
- };
1975
- }
1976
- _createCloseMessage() {
1977
- return { type: MessageType.Close };
1978
- }
1979
- }
1980
-
1981
- // Licensed to the .NET Foundation under one or more agreements.
1982
- // The .NET Foundation licenses this file to you under the MIT license.
1983
- // 0, 2, 10, 30 second delays before reconnect attempts.
1984
- const DEFAULT_RETRY_DELAYS_IN_MILLISECONDS = [0, 2000, 10000, 30000, null];
1985
- /** @private */
1986
- class DefaultReconnectPolicy {
1987
- constructor(retryDelays) {
1988
- this._retryDelays = retryDelays !== undefined ? [...retryDelays, null] : DEFAULT_RETRY_DELAYS_IN_MILLISECONDS;
1989
- }
1990
- nextRetryDelayInMilliseconds(retryContext) {
1991
- return this._retryDelays[retryContext.previousRetryCount];
1992
- }
1993
- }
1994
-
1995
- // Licensed to the .NET Foundation under one or more agreements.
1996
- // The .NET Foundation licenses this file to you under the MIT license.
1997
- class HeaderNames {
1998
- }
1999
- HeaderNames.Authorization = "Authorization";
2000
- HeaderNames.Cookie = "Cookie";
2001
-
2002
- // Licensed to the .NET Foundation under one or more agreements.
2003
- // The .NET Foundation licenses this file to you under the MIT license.
2004
- /** @private */
2005
- class AccessTokenHttpClient extends HttpClient {
2006
- constructor(innerClient, accessTokenFactory) {
2007
- super();
2008
- this._innerClient = innerClient;
2009
- this._accessTokenFactory = accessTokenFactory;
2010
- }
2011
- async send(request) {
2012
- let allowRetry = true;
2013
- if (this._accessTokenFactory && (!this._accessToken || (request.url && request.url.indexOf("/negotiate?") > 0))) {
2014
- // don't retry if the request is a negotiate or if we just got a potentially new token from the access token factory
2015
- allowRetry = false;
2016
- this._accessToken = await this._accessTokenFactory();
2017
- }
2018
- this._setAuthorizationHeader(request);
2019
- const response = await this._innerClient.send(request);
2020
- if (allowRetry && response.statusCode === 401 && this._accessTokenFactory) {
2021
- this._accessToken = await this._accessTokenFactory();
2022
- this._setAuthorizationHeader(request);
2023
- return await this._innerClient.send(request);
2024
- }
2025
- return response;
2026
- }
2027
- _setAuthorizationHeader(request) {
2028
- if (!request.headers) {
2029
- request.headers = {};
2030
- }
2031
- if (this._accessToken) {
2032
- request.headers[HeaderNames.Authorization] = `Bearer ${this._accessToken}`;
2033
- }
2034
- // don't remove the header if there isn't an access token factory, the user manually added the header in this case
2035
- else if (this._accessTokenFactory) {
2036
- if (request.headers[HeaderNames.Authorization]) {
2037
- delete request.headers[HeaderNames.Authorization];
2038
- }
2039
- }
2040
- }
2041
- getCookieString(url) {
2042
- return this._innerClient.getCookieString(url);
2043
- }
2044
- }
2045
-
2046
- // Licensed to the .NET Foundation under one or more agreements.
2047
- // The .NET Foundation licenses this file to you under the MIT license.
2048
- // This will be treated as a bit flag in the future, so we keep it using power-of-two values.
2049
- /** Specifies a specific HTTP transport type. */
2050
- var HttpTransportType;
2051
- (function (HttpTransportType) {
2052
- /** Specifies no transport preference. */
2053
- HttpTransportType[HttpTransportType["None"] = 0] = "None";
2054
- /** Specifies the WebSockets transport. */
2055
- HttpTransportType[HttpTransportType["WebSockets"] = 1] = "WebSockets";
2056
- /** Specifies the Server-Sent Events transport. */
2057
- HttpTransportType[HttpTransportType["ServerSentEvents"] = 2] = "ServerSentEvents";
2058
- /** Specifies the Long Polling transport. */
2059
- HttpTransportType[HttpTransportType["LongPolling"] = 4] = "LongPolling";
2060
- })(HttpTransportType || (HttpTransportType = {}));
2061
- /** Specifies the transfer format for a connection. */
2062
- var TransferFormat;
2063
- (function (TransferFormat) {
2064
- /** Specifies that only text data will be transmitted over the connection. */
2065
- TransferFormat[TransferFormat["Text"] = 1] = "Text";
2066
- /** Specifies that binary data will be transmitted over the connection. */
2067
- TransferFormat[TransferFormat["Binary"] = 2] = "Binary";
2068
- })(TransferFormat || (TransferFormat = {}));
2069
-
2070
- // Licensed to the .NET Foundation under one or more agreements.
2071
- // The .NET Foundation licenses this file to you under the MIT license.
2072
- // Rough polyfill of https://developer.mozilla.org/en-US/docs/Web/API/AbortController
2073
- // We don't actually ever use the API being polyfilled, we always use the polyfill because
2074
- // it's a very new API right now.
2075
- // Not exported from index.
2076
- /** @private */
2077
- let AbortController$1 = class AbortController {
2078
- constructor() {
2079
- this._isAborted = false;
2080
- this.onabort = null;
2081
- }
2082
- abort() {
2083
- if (!this._isAborted) {
2084
- this._isAborted = true;
2085
- if (this.onabort) {
2086
- this.onabort();
2087
- }
2088
- }
2089
- }
2090
- get signal() {
2091
- return this;
2092
- }
2093
- get aborted() {
2094
- return this._isAborted;
2095
- }
2096
- };
2097
-
2098
- // Licensed to the .NET Foundation under one or more agreements.
2099
- // The .NET Foundation licenses this file to you under the MIT license.
2100
- // Not exported from 'index', this type is internal.
2101
- /** @private */
2102
- class LongPollingTransport {
2103
- // This is an internal type, not exported from 'index' so this is really just internal.
2104
- get pollAborted() {
2105
- return this._pollAbort.aborted;
2106
- }
2107
- constructor(httpClient, logger, options) {
2108
- this._httpClient = httpClient;
2109
- this._logger = logger;
2110
- this._pollAbort = new AbortController$1();
2111
- this._options = options;
2112
- this._running = false;
2113
- this.onreceive = null;
2114
- this.onclose = null;
2115
- }
2116
- async connect(url, transferFormat) {
2117
- Arg.isRequired(url, "url");
2118
- Arg.isRequired(transferFormat, "transferFormat");
2119
- Arg.isIn(transferFormat, TransferFormat, "transferFormat");
2120
- this._url = url;
2121
- this._logger.log(LogLevel.Trace, "(LongPolling transport) Connecting.");
2122
- // Allow binary format on Node and Browsers that support binary content (indicated by the presence of responseType property)
2123
- if (transferFormat === TransferFormat.Binary &&
2124
- (typeof XMLHttpRequest !== "undefined" && typeof new XMLHttpRequest().responseType !== "string")) {
2125
- throw new Error("Binary protocols over XmlHttpRequest not implementing advanced features are not supported.");
2126
- }
2127
- const [name, value] = getUserAgentHeader();
2128
- const headers = { [name]: value, ...this._options.headers };
2129
- const pollOptions = {
2130
- abortSignal: this._pollAbort.signal,
2131
- headers,
2132
- timeout: 100000,
2133
- withCredentials: this._options.withCredentials,
2134
- };
2135
- if (transferFormat === TransferFormat.Binary) {
2136
- pollOptions.responseType = "arraybuffer";
2137
- }
2138
- // Make initial long polling request
2139
- // Server uses first long polling request to finish initializing connection and it returns without data
2140
- const pollUrl = `${url}&_=${Date.now()}`;
2141
- this._logger.log(LogLevel.Trace, `(LongPolling transport) polling: ${pollUrl}.`);
2142
- const response = await this._httpClient.get(pollUrl, pollOptions);
2143
- if (response.statusCode !== 200) {
2144
- this._logger.log(LogLevel.Error, `(LongPolling transport) Unexpected response code: ${response.statusCode}.`);
2145
- // Mark running as false so that the poll immediately ends and runs the close logic
2146
- this._closeError = new HttpError(response.statusText || "", response.statusCode);
2147
- this._running = false;
2148
- }
2149
- else {
2150
- this._running = true;
2151
- }
2152
- this._receiving = this._poll(this._url, pollOptions);
2153
- }
2154
- async _poll(url, pollOptions) {
2155
- try {
2156
- while (this._running) {
2157
- try {
2158
- const pollUrl = `${url}&_=${Date.now()}`;
2159
- this._logger.log(LogLevel.Trace, `(LongPolling transport) polling: ${pollUrl}.`);
2160
- const response = await this._httpClient.get(pollUrl, pollOptions);
2161
- if (response.statusCode === 204) {
2162
- this._logger.log(LogLevel.Information, "(LongPolling transport) Poll terminated by server.");
2163
- this._running = false;
2164
- }
2165
- else if (response.statusCode !== 200) {
2166
- this._logger.log(LogLevel.Error, `(LongPolling transport) Unexpected response code: ${response.statusCode}.`);
2167
- // Unexpected status code
2168
- this._closeError = new HttpError(response.statusText || "", response.statusCode);
2169
- this._running = false;
2170
- }
2171
- else {
2172
- // Process the response
2173
- if (response.content) {
2174
- this._logger.log(LogLevel.Trace, `(LongPolling transport) data received. ${getDataDetail(response.content, this._options.logMessageContent)}.`);
2175
- if (this.onreceive) {
2176
- this.onreceive(response.content);
2177
- }
2178
- }
2179
- else {
2180
- // This is another way timeout manifest.
2181
- this._logger.log(LogLevel.Trace, "(LongPolling transport) Poll timed out, reissuing.");
2182
- }
2183
- }
2184
- }
2185
- catch (e) {
2186
- if (!this._running) {
2187
- // Log but disregard errors that occur after stopping
2188
- this._logger.log(LogLevel.Trace, `(LongPolling transport) Poll errored after shutdown: ${e.message}`);
2189
- }
2190
- else {
2191
- if (e instanceof TimeoutError) {
2192
- // Ignore timeouts and reissue the poll.
2193
- this._logger.log(LogLevel.Trace, "(LongPolling transport) Poll timed out, reissuing.");
2194
- }
2195
- else {
2196
- // Close the connection with the error as the result.
2197
- this._closeError = e;
2198
- this._running = false;
2199
- }
2200
- }
2201
- }
2202
- }
2203
- }
2204
- finally {
2205
- this._logger.log(LogLevel.Trace, "(LongPolling transport) Polling complete.");
2206
- // We will reach here with pollAborted==false when the server returned a response causing the transport to stop.
2207
- // If pollAborted==true then client initiated the stop and the stop method will raise the close event after DELETE is sent.
2208
- if (!this.pollAborted) {
2209
- this._raiseOnClose();
2210
- }
2211
- }
2212
- }
2213
- async send(data) {
2214
- if (!this._running) {
2215
- return Promise.reject(new Error("Cannot send until the transport is connected"));
2216
- }
2217
- return sendMessage(this._logger, "LongPolling", this._httpClient, this._url, data, this._options);
2218
- }
2219
- async stop() {
2220
- this._logger.log(LogLevel.Trace, "(LongPolling transport) Stopping polling.");
2221
- // Tell receiving loop to stop, abort any current request, and then wait for it to finish
2222
- this._running = false;
2223
- this._pollAbort.abort();
2224
- try {
2225
- await this._receiving;
2226
- // Send DELETE to clean up long polling on the server
2227
- this._logger.log(LogLevel.Trace, `(LongPolling transport) sending DELETE request to ${this._url}.`);
2228
- const headers = {};
2229
- const [name, value] = getUserAgentHeader();
2230
- headers[name] = value;
2231
- const deleteOptions = {
2232
- headers: { ...headers, ...this._options.headers },
2233
- timeout: this._options.timeout,
2234
- withCredentials: this._options.withCredentials,
2235
- };
2236
- let error;
2237
- try {
2238
- await this._httpClient.delete(this._url, deleteOptions);
2239
- }
2240
- catch (err) {
2241
- error = err;
2242
- }
2243
- if (error) {
2244
- if (error instanceof HttpError) {
2245
- if (error.statusCode === 404) {
2246
- this._logger.log(LogLevel.Trace, "(LongPolling transport) A 404 response was returned from sending a DELETE request.");
2247
- }
2248
- else {
2249
- this._logger.log(LogLevel.Trace, `(LongPolling transport) Error sending a DELETE request: ${error}`);
2250
- }
2251
- }
2252
- }
2253
- else {
2254
- this._logger.log(LogLevel.Trace, "(LongPolling transport) DELETE request accepted.");
2255
- }
2256
- }
2257
- finally {
2258
- this._logger.log(LogLevel.Trace, "(LongPolling transport) Stop finished.");
2259
- // Raise close event here instead of in polling
2260
- // It needs to happen after the DELETE request is sent
2261
- this._raiseOnClose();
2262
- }
2263
- }
2264
- _raiseOnClose() {
2265
- if (this.onclose) {
2266
- let logMessage = "(LongPolling transport) Firing onclose event.";
2267
- if (this._closeError) {
2268
- logMessage += " Error: " + this._closeError;
2269
- }
2270
- this._logger.log(LogLevel.Trace, logMessage);
2271
- this.onclose(this._closeError);
2272
- }
2273
- }
2274
- }
2275
-
2276
- // Licensed to the .NET Foundation under one or more agreements.
2277
- // The .NET Foundation licenses this file to you under the MIT license.
2278
- /** @private */
2279
- class ServerSentEventsTransport {
2280
- constructor(httpClient, accessToken, logger, options) {
2281
- this._httpClient = httpClient;
2282
- this._accessToken = accessToken;
2283
- this._logger = logger;
2284
- this._options = options;
2285
- this.onreceive = null;
2286
- this.onclose = null;
2287
- }
2288
- async connect(url, transferFormat) {
2289
- Arg.isRequired(url, "url");
2290
- Arg.isRequired(transferFormat, "transferFormat");
2291
- Arg.isIn(transferFormat, TransferFormat, "transferFormat");
2292
- this._logger.log(LogLevel.Trace, "(SSE transport) Connecting.");
2293
- // set url before accessTokenFactory because this._url is only for send and we set the auth header instead of the query string for send
2294
- this._url = url;
2295
- if (this._accessToken) {
2296
- url += (url.indexOf("?") < 0 ? "?" : "&") + `access_token=${encodeURIComponent(this._accessToken)}`;
2297
- }
2298
- return new Promise((resolve, reject) => {
2299
- let opened = false;
2300
- if (transferFormat !== TransferFormat.Text) {
2301
- reject(new Error("The Server-Sent Events transport only supports the 'Text' transfer format"));
2302
- return;
2303
- }
2304
- let eventSource;
2305
- if (Platform.isBrowser || Platform.isWebWorker) {
2306
- eventSource = new this._options.EventSource(url, { withCredentials: this._options.withCredentials });
2307
- }
2308
- else {
2309
- // Non-browser passes cookies via the dictionary
2310
- const cookies = this._httpClient.getCookieString(url);
2311
- const headers = {};
2312
- headers.Cookie = cookies;
2313
- const [name, value] = getUserAgentHeader();
2314
- headers[name] = value;
2315
- eventSource = new this._options.EventSource(url, { withCredentials: this._options.withCredentials, headers: { ...headers, ...this._options.headers } });
2316
- }
2317
- try {
2318
- eventSource.onmessage = (e) => {
2319
- if (this.onreceive) {
2320
- try {
2321
- this._logger.log(LogLevel.Trace, `(SSE transport) data received. ${getDataDetail(e.data, this._options.logMessageContent)}.`);
2322
- this.onreceive(e.data);
2323
- }
2324
- catch (error) {
2325
- this._close(error);
2326
- return;
2327
- }
2328
- }
2329
- };
2330
- // @ts-ignore: not using event on purpose
2331
- eventSource.onerror = (e) => {
2332
- // EventSource doesn't give any useful information about server side closes.
2333
- if (opened) {
2334
- this._close();
2335
- }
2336
- else {
2337
- reject(new Error("EventSource failed to connect. The connection could not be found on the server,"
2338
- + " either the connection ID is not present on the server, or a proxy is refusing/buffering the connection."
2339
- + " If you have multiple servers check that sticky sessions are enabled."));
2340
- }
2341
- };
2342
- eventSource.onopen = () => {
2343
- this._logger.log(LogLevel.Information, `SSE connected to ${this._url}`);
2344
- this._eventSource = eventSource;
2345
- opened = true;
2346
- resolve();
2347
- };
2348
- }
2349
- catch (e) {
2350
- reject(e);
2351
- return;
2352
- }
2353
- });
2354
- }
2355
- async send(data) {
2356
- if (!this._eventSource) {
2357
- return Promise.reject(new Error("Cannot send until the transport is connected"));
2358
- }
2359
- return sendMessage(this._logger, "SSE", this._httpClient, this._url, data, this._options);
2360
- }
2361
- stop() {
2362
- this._close();
2363
- return Promise.resolve();
2364
- }
2365
- _close(e) {
2366
- if (this._eventSource) {
2367
- this._eventSource.close();
2368
- this._eventSource = undefined;
2369
- if (this.onclose) {
2370
- this.onclose(e);
2371
- }
2372
- }
2373
- }
2374
- }
2375
-
2376
- // Licensed to the .NET Foundation under one or more agreements.
2377
- // The .NET Foundation licenses this file to you under the MIT license.
2378
- /** @private */
2379
- class WebSocketTransport {
2380
- constructor(httpClient, accessTokenFactory, logger, logMessageContent, webSocketConstructor, headers) {
2381
- this._logger = logger;
2382
- this._accessTokenFactory = accessTokenFactory;
2383
- this._logMessageContent = logMessageContent;
2384
- this._webSocketConstructor = webSocketConstructor;
2385
- this._httpClient = httpClient;
2386
- this.onreceive = null;
2387
- this.onclose = null;
2388
- this._headers = headers;
2389
- }
2390
- async connect(url, transferFormat) {
2391
- Arg.isRequired(url, "url");
2392
- Arg.isRequired(transferFormat, "transferFormat");
2393
- Arg.isIn(transferFormat, TransferFormat, "transferFormat");
2394
- this._logger.log(LogLevel.Trace, "(WebSockets transport) Connecting.");
2395
- let token;
2396
- if (this._accessTokenFactory) {
2397
- token = await this._accessTokenFactory();
2398
- }
2399
- return new Promise((resolve, reject) => {
2400
- url = url.replace(/^http/, "ws");
2401
- let webSocket;
2402
- const cookies = this._httpClient.getCookieString(url);
2403
- let opened = false;
2404
- if (Platform.isNode || Platform.isReactNative) {
2405
- const headers = {};
2406
- const [name, value] = getUserAgentHeader();
2407
- headers[name] = value;
2408
- if (token) {
2409
- headers[HeaderNames.Authorization] = `Bearer ${token}`;
2410
- }
2411
- if (cookies) {
2412
- headers[HeaderNames.Cookie] = cookies;
2413
- }
2414
- // Only pass headers when in non-browser environments
2415
- webSocket = new this._webSocketConstructor(url, undefined, {
2416
- headers: { ...headers, ...this._headers },
2417
- });
2418
- }
2419
- else {
2420
- if (token) {
2421
- url += (url.indexOf("?") < 0 ? "?" : "&") + `access_token=${encodeURIComponent(token)}`;
2422
- }
2423
- }
2424
- if (!webSocket) {
2425
- // Chrome is not happy with passing 'undefined' as protocol
2426
- webSocket = new this._webSocketConstructor(url);
2427
- }
2428
- if (transferFormat === TransferFormat.Binary) {
2429
- webSocket.binaryType = "arraybuffer";
2430
- }
2431
- webSocket.onopen = (_event) => {
2432
- this._logger.log(LogLevel.Information, `WebSocket connected to ${url}.`);
2433
- this._webSocket = webSocket;
2434
- opened = true;
2435
- resolve();
2436
- };
2437
- webSocket.onerror = (event) => {
2438
- let error = null;
2439
- // ErrorEvent is a browser only type we need to check if the type exists before using it
2440
- if (typeof ErrorEvent !== "undefined" && event instanceof ErrorEvent) {
2441
- error = event.error;
2442
- }
2443
- else {
2444
- error = "There was an error with the transport";
2445
- }
2446
- this._logger.log(LogLevel.Information, `(WebSockets transport) ${error}.`);
2447
- };
2448
- webSocket.onmessage = (message) => {
2449
- this._logger.log(LogLevel.Trace, `(WebSockets transport) data received. ${getDataDetail(message.data, this._logMessageContent)}.`);
2450
- if (this.onreceive) {
2451
- try {
2452
- this.onreceive(message.data);
2453
- }
2454
- catch (error) {
2455
- this._close(error);
2456
- return;
2457
- }
2458
- }
2459
- };
2460
- webSocket.onclose = (event) => {
2461
- // Don't call close handler if connection was never established
2462
- // We'll reject the connect call instead
2463
- if (opened) {
2464
- this._close(event);
2465
- }
2466
- else {
2467
- let error = null;
2468
- // ErrorEvent is a browser only type we need to check if the type exists before using it
2469
- if (typeof ErrorEvent !== "undefined" && event instanceof ErrorEvent) {
2470
- error = event.error;
2471
- }
2472
- else {
2473
- error = "WebSocket failed to connect. The connection could not be found on the server,"
2474
- + " either the endpoint may not be a SignalR endpoint,"
2475
- + " the connection ID is not present on the server, or there is a proxy blocking WebSockets."
2476
- + " If you have multiple servers check that sticky sessions are enabled.";
2477
- }
2478
- reject(new Error(error));
2479
- }
2480
- };
2481
- });
2482
- }
2483
- send(data) {
2484
- if (this._webSocket && this._webSocket.readyState === this._webSocketConstructor.OPEN) {
2485
- this._logger.log(LogLevel.Trace, `(WebSockets transport) sending data. ${getDataDetail(data, this._logMessageContent)}.`);
2486
- this._webSocket.send(data);
2487
- return Promise.resolve();
2488
- }
2489
- return Promise.reject("WebSocket is not in the OPEN state");
2490
- }
2491
- stop() {
2492
- if (this._webSocket) {
2493
- // Manually invoke onclose callback inline so we know the HttpConnection was closed properly before returning
2494
- // This also solves an issue where websocket.onclose could take 18+ seconds to trigger during network disconnects
2495
- this._close(undefined);
2496
- }
2497
- return Promise.resolve();
2498
- }
2499
- _close(event) {
2500
- // webSocket will be null if the transport did not start successfully
2501
- if (this._webSocket) {
2502
- // Clear websocket handlers because we are considering the socket closed now
2503
- this._webSocket.onclose = () => { };
2504
- this._webSocket.onmessage = () => { };
2505
- this._webSocket.onerror = () => { };
2506
- this._webSocket.close();
2507
- this._webSocket = undefined;
2508
- }
2509
- this._logger.log(LogLevel.Trace, "(WebSockets transport) socket closed.");
2510
- if (this.onclose) {
2511
- if (this._isCloseEvent(event) && (event.wasClean === false || event.code !== 1000)) {
2512
- this.onclose(new Error(`WebSocket closed with status code: ${event.code} (${event.reason || "no reason given"}).`));
2513
- }
2514
- else if (event instanceof Error) {
2515
- this.onclose(event);
2516
- }
2517
- else {
2518
- this.onclose();
2519
- }
2520
- }
2521
- }
2522
- _isCloseEvent(event) {
2523
- return event && typeof event.wasClean === "boolean" && typeof event.code === "number";
2524
- }
2525
- }
2526
-
2527
- // Licensed to the .NET Foundation under one or more agreements.
2528
- // The .NET Foundation licenses this file to you under the MIT license.
2529
- const MAX_REDIRECTS = 100;
2530
- /** @private */
2531
- class HttpConnection {
2532
- constructor(url, options = {}) {
2533
- this._stopPromiseResolver = () => { };
2534
- this.features = {};
2535
- this._negotiateVersion = 1;
2536
- Arg.isRequired(url, "url");
2537
- this._logger = createLogger(options.logger);
2538
- this.baseUrl = this._resolveUrl(url);
2539
- options = options || {};
2540
- options.logMessageContent = options.logMessageContent === undefined ? false : options.logMessageContent;
2541
- if (typeof options.withCredentials === "boolean" || options.withCredentials === undefined) {
2542
- options.withCredentials = options.withCredentials === undefined ? true : options.withCredentials;
2543
- }
2544
- else {
2545
- throw new Error("withCredentials option was not a 'boolean' or 'undefined' value");
2546
- }
2547
- options.timeout = options.timeout === undefined ? 100 * 1000 : options.timeout;
2548
- let webSocketModule = null;
2549
- let eventSourceModule = null;
2550
- if (Platform.isNode && typeof require !== "undefined") {
2551
- // In order to ignore the dynamic require in webpack builds we need to do this magic
2552
- // @ts-ignore: TS doesn't know about these names
2553
- const requireFunc = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
2554
- webSocketModule = requireFunc("ws");
2555
- eventSourceModule = requireFunc("eventsource");
2556
- }
2557
- if (!Platform.isNode && typeof WebSocket !== "undefined" && !options.WebSocket) {
2558
- options.WebSocket = WebSocket;
2559
- }
2560
- else if (Platform.isNode && !options.WebSocket) {
2561
- if (webSocketModule) {
2562
- options.WebSocket = webSocketModule;
2563
- }
2564
- }
2565
- if (!Platform.isNode && typeof EventSource !== "undefined" && !options.EventSource) {
2566
- options.EventSource = EventSource;
2567
- }
2568
- else if (Platform.isNode && !options.EventSource) {
2569
- if (typeof eventSourceModule !== "undefined") {
2570
- options.EventSource = eventSourceModule;
2571
- }
2572
- }
2573
- this._httpClient = new AccessTokenHttpClient(options.httpClient || new DefaultHttpClient(this._logger), options.accessTokenFactory);
2574
- this._connectionState = "Disconnected" /* ConnectionState.Disconnected */;
2575
- this._connectionStarted = false;
2576
- this._options = options;
2577
- this.onreceive = null;
2578
- this.onclose = null;
2579
- }
2580
- async start(transferFormat) {
2581
- transferFormat = transferFormat || TransferFormat.Binary;
2582
- Arg.isIn(transferFormat, TransferFormat, "transferFormat");
2583
- this._logger.log(LogLevel.Debug, `Starting connection with transfer format '${TransferFormat[transferFormat]}'.`);
2584
- if (this._connectionState !== "Disconnected" /* ConnectionState.Disconnected */) {
2585
- return Promise.reject(new Error("Cannot start an HttpConnection that is not in the 'Disconnected' state."));
2586
- }
2587
- this._connectionState = "Connecting" /* ConnectionState.Connecting */;
2588
- this._startInternalPromise = this._startInternal(transferFormat);
2589
- await this._startInternalPromise;
2590
- // The TypeScript compiler thinks that connectionState must be Connecting here. The TypeScript compiler is wrong.
2591
- if (this._connectionState === "Disconnecting" /* ConnectionState.Disconnecting */) {
2592
- // stop() was called and transitioned the client into the Disconnecting state.
2593
- const message = "Failed to start the HttpConnection before stop() was called.";
2594
- this._logger.log(LogLevel.Error, message);
2595
- // We cannot await stopPromise inside startInternal since stopInternal awaits the startInternalPromise.
2596
- await this._stopPromise;
2597
- return Promise.reject(new AbortError(message));
2598
- }
2599
- else if (this._connectionState !== "Connected" /* ConnectionState.Connected */) {
2600
- // stop() was called and transitioned the client into the Disconnecting state.
2601
- const message = "HttpConnection.startInternal completed gracefully but didn't enter the connection into the connected state!";
2602
- this._logger.log(LogLevel.Error, message);
2603
- return Promise.reject(new AbortError(message));
2604
- }
2605
- this._connectionStarted = true;
2606
- }
2607
- send(data) {
2608
- if (this._connectionState !== "Connected" /* ConnectionState.Connected */) {
2609
- return Promise.reject(new Error("Cannot send data if the connection is not in the 'Connected' State."));
2610
- }
2611
- if (!this._sendQueue) {
2612
- this._sendQueue = new TransportSendQueue(this.transport);
2613
- }
2614
- // Transport will not be null if state is connected
2615
- return this._sendQueue.send(data);
2616
- }
2617
- async stop(error) {
2618
- if (this._connectionState === "Disconnected" /* ConnectionState.Disconnected */) {
2619
- this._logger.log(LogLevel.Debug, `Call to HttpConnection.stop(${error}) ignored because the connection is already in the disconnected state.`);
2620
- return Promise.resolve();
2621
- }
2622
- if (this._connectionState === "Disconnecting" /* ConnectionState.Disconnecting */) {
2623
- this._logger.log(LogLevel.Debug, `Call to HttpConnection.stop(${error}) ignored because the connection is already in the disconnecting state.`);
2624
- return this._stopPromise;
2625
- }
2626
- this._connectionState = "Disconnecting" /* ConnectionState.Disconnecting */;
2627
- this._stopPromise = new Promise((resolve) => {
2628
- // Don't complete stop() until stopConnection() completes.
2629
- this._stopPromiseResolver = resolve;
2630
- });
2631
- // stopInternal should never throw so just observe it.
2632
- await this._stopInternal(error);
2633
- await this._stopPromise;
2634
- }
2635
- async _stopInternal(error) {
2636
- // Set error as soon as possible otherwise there is a race between
2637
- // the transport closing and providing an error and the error from a close message
2638
- // We would prefer the close message error.
2639
- this._stopError = error;
2640
- try {
2641
- await this._startInternalPromise;
2642
- }
2643
- catch (e) {
2644
- // This exception is returned to the user as a rejected Promise from the start method.
2645
- }
2646
- // The transport's onclose will trigger stopConnection which will run our onclose event.
2647
- // The transport should always be set if currently connected. If it wasn't set, it's likely because
2648
- // stop was called during start() and start() failed.
2649
- if (this.transport) {
2650
- try {
2651
- await this.transport.stop();
2652
- }
2653
- catch (e) {
2654
- this._logger.log(LogLevel.Error, `HttpConnection.transport.stop() threw error '${e}'.`);
2655
- this._stopConnection();
2656
- }
2657
- this.transport = undefined;
2658
- }
2659
- else {
2660
- this._logger.log(LogLevel.Debug, "HttpConnection.transport is undefined in HttpConnection.stop() because start() failed.");
2661
- }
2662
- }
2663
- async _startInternal(transferFormat) {
2664
- // Store the original base url and the access token factory since they may change
2665
- // as part of negotiating
2666
- let url = this.baseUrl;
2667
- this._accessTokenFactory = this._options.accessTokenFactory;
2668
- this._httpClient._accessTokenFactory = this._accessTokenFactory;
2669
- try {
2670
- if (this._options.skipNegotiation) {
2671
- if (this._options.transport === HttpTransportType.WebSockets) {
2672
- // No need to add a connection ID in this case
2673
- this.transport = this._constructTransport(HttpTransportType.WebSockets);
2674
- // We should just call connect directly in this case.
2675
- // No fallback or negotiate in this case.
2676
- await this._startTransport(url, transferFormat);
2677
- }
2678
- else {
2679
- throw new Error("Negotiation can only be skipped when using the WebSocket transport directly.");
2680
- }
2681
- }
2682
- else {
2683
- let negotiateResponse = null;
2684
- let redirects = 0;
2685
- do {
2686
- negotiateResponse = await this._getNegotiationResponse(url);
2687
- // the user tries to stop the connection when it is being started
2688
- if (this._connectionState === "Disconnecting" /* ConnectionState.Disconnecting */ || this._connectionState === "Disconnected" /* ConnectionState.Disconnected */) {
2689
- throw new AbortError("The connection was stopped during negotiation.");
2690
- }
2691
- if (negotiateResponse.error) {
2692
- throw new Error(negotiateResponse.error);
2693
- }
2694
- if (negotiateResponse.ProtocolVersion) {
2695
- throw new Error("Detected a connection attempt to an ASP.NET SignalR Server. This client only supports connecting to an ASP.NET Core SignalR Server. See https://aka.ms/signalr-core-differences for details.");
2696
- }
2697
- if (negotiateResponse.url) {
2698
- url = negotiateResponse.url;
2699
- }
2700
- if (negotiateResponse.accessToken) {
2701
- // Replace the current access token factory with one that uses
2702
- // the returned access token
2703
- const accessToken = negotiateResponse.accessToken;
2704
- this._accessTokenFactory = () => accessToken;
2705
- // set the factory to undefined so the AccessTokenHttpClient won't retry with the same token, since we know it won't change until a connection restart
2706
- this._httpClient._accessToken = accessToken;
2707
- this._httpClient._accessTokenFactory = undefined;
2708
- }
2709
- redirects++;
2710
- } while (negotiateResponse.url && redirects < MAX_REDIRECTS);
2711
- if (redirects === MAX_REDIRECTS && negotiateResponse.url) {
2712
- throw new Error("Negotiate redirection limit exceeded.");
2713
- }
2714
- await this._createTransport(url, this._options.transport, negotiateResponse, transferFormat);
2715
- }
2716
- if (this.transport instanceof LongPollingTransport) {
2717
- this.features.inherentKeepAlive = true;
2718
- }
2719
- if (this._connectionState === "Connecting" /* ConnectionState.Connecting */) {
2720
- // Ensure the connection transitions to the connected state prior to completing this.startInternalPromise.
2721
- // start() will handle the case when stop was called and startInternal exits still in the disconnecting state.
2722
- this._logger.log(LogLevel.Debug, "The HttpConnection connected successfully.");
2723
- this._connectionState = "Connected" /* ConnectionState.Connected */;
2724
- }
2725
- // stop() is waiting on us via this.startInternalPromise so keep this.transport around so it can clean up.
2726
- // This is the only case startInternal can exit in neither the connected nor disconnected state because stopConnection()
2727
- // will transition to the disconnected state. start() will wait for the transition using the stopPromise.
2728
- }
2729
- catch (e) {
2730
- this._logger.log(LogLevel.Error, "Failed to start the connection: " + e);
2731
- this._connectionState = "Disconnected" /* ConnectionState.Disconnected */;
2732
- this.transport = undefined;
2733
- // if start fails, any active calls to stop assume that start will complete the stop promise
2734
- this._stopPromiseResolver();
2735
- return Promise.reject(e);
2736
- }
2737
- }
2738
- async _getNegotiationResponse(url) {
2739
- const headers = {};
2740
- const [name, value] = getUserAgentHeader();
2741
- headers[name] = value;
2742
- const negotiateUrl = this._resolveNegotiateUrl(url);
2743
- this._logger.log(LogLevel.Debug, `Sending negotiation request: ${negotiateUrl}.`);
2744
- try {
2745
- const response = await this._httpClient.post(negotiateUrl, {
2746
- content: "",
2747
- headers: { ...headers, ...this._options.headers },
2748
- timeout: this._options.timeout,
2749
- withCredentials: this._options.withCredentials,
2750
- });
2751
- if (response.statusCode !== 200) {
2752
- return Promise.reject(new Error(`Unexpected status code returned from negotiate '${response.statusCode}'`));
2753
- }
2754
- const negotiateResponse = JSON.parse(response.content);
2755
- if (!negotiateResponse.negotiateVersion || negotiateResponse.negotiateVersion < 1) {
2756
- // Negotiate version 0 doesn't use connectionToken
2757
- // So we set it equal to connectionId so all our logic can use connectionToken without being aware of the negotiate version
2758
- negotiateResponse.connectionToken = negotiateResponse.connectionId;
2759
- }
2760
- if (negotiateResponse.useStatefulReconnect && this._options._useStatefulReconnect !== true) {
2761
- return Promise.reject(new FailedToNegotiateWithServerError("Client didn't negotiate Stateful Reconnect but the server did."));
2762
- }
2763
- return negotiateResponse;
2764
- }
2765
- catch (e) {
2766
- let errorMessage = "Failed to complete negotiation with the server: " + e;
2767
- if (e instanceof HttpError) {
2768
- if (e.statusCode === 404) {
2769
- errorMessage = errorMessage + " Either this is not a SignalR endpoint or there is a proxy blocking the connection.";
2770
- }
2771
- }
2772
- this._logger.log(LogLevel.Error, errorMessage);
2773
- return Promise.reject(new FailedToNegotiateWithServerError(errorMessage));
2774
- }
2775
- }
2776
- _createConnectUrl(url, connectionToken) {
2777
- if (!connectionToken) {
2778
- return url;
2779
- }
2780
- return url + (url.indexOf("?") === -1 ? "?" : "&") + `id=${connectionToken}`;
2781
- }
2782
- async _createTransport(url, requestedTransport, negotiateResponse, requestedTransferFormat) {
2783
- let connectUrl = this._createConnectUrl(url, negotiateResponse.connectionToken);
2784
- if (this._isITransport(requestedTransport)) {
2785
- this._logger.log(LogLevel.Debug, "Connection was provided an instance of ITransport, using that directly.");
2786
- this.transport = requestedTransport;
2787
- await this._startTransport(connectUrl, requestedTransferFormat);
2788
- this.connectionId = negotiateResponse.connectionId;
2789
- return;
2790
- }
2791
- const transportExceptions = [];
2792
- const transports = negotiateResponse.availableTransports || [];
2793
- let negotiate = negotiateResponse;
2794
- for (const endpoint of transports) {
2795
- const transportOrError = this._resolveTransportOrError(endpoint, requestedTransport, requestedTransferFormat, (negotiate === null || negotiate === void 0 ? void 0 : negotiate.useStatefulReconnect) === true);
2796
- if (transportOrError instanceof Error) {
2797
- // Store the error and continue, we don't want to cause a re-negotiate in these cases
2798
- transportExceptions.push(`${endpoint.transport} failed:`);
2799
- transportExceptions.push(transportOrError);
2800
- }
2801
- else if (this._isITransport(transportOrError)) {
2802
- this.transport = transportOrError;
2803
- if (!negotiate) {
2804
- try {
2805
- negotiate = await this._getNegotiationResponse(url);
2806
- }
2807
- catch (ex) {
2808
- return Promise.reject(ex);
2809
- }
2810
- connectUrl = this._createConnectUrl(url, negotiate.connectionToken);
2811
- }
2812
- try {
2813
- await this._startTransport(connectUrl, requestedTransferFormat);
2814
- this.connectionId = negotiate.connectionId;
2815
- return;
2816
- }
2817
- catch (ex) {
2818
- this._logger.log(LogLevel.Error, `Failed to start the transport '${endpoint.transport}': ${ex}`);
2819
- negotiate = undefined;
2820
- transportExceptions.push(new FailedToStartTransportError(`${endpoint.transport} failed: ${ex}`, HttpTransportType[endpoint.transport]));
2821
- if (this._connectionState !== "Connecting" /* ConnectionState.Connecting */) {
2822
- const message = "Failed to select transport before stop() was called.";
2823
- this._logger.log(LogLevel.Debug, message);
2824
- return Promise.reject(new AbortError(message));
2825
- }
2826
- }
2827
- }
2828
- }
2829
- if (transportExceptions.length > 0) {
2830
- return Promise.reject(new AggregateErrors(`Unable to connect to the server with any of the available transports. ${transportExceptions.join(" ")}`, transportExceptions));
2831
- }
2832
- return Promise.reject(new Error("None of the transports supported by the client are supported by the server."));
2833
- }
2834
- _constructTransport(transport) {
2835
- switch (transport) {
2836
- case HttpTransportType.WebSockets:
2837
- if (!this._options.WebSocket) {
2838
- throw new Error("'WebSocket' is not supported in your environment.");
2839
- }
2840
- return new WebSocketTransport(this._httpClient, this._accessTokenFactory, this._logger, this._options.logMessageContent, this._options.WebSocket, this._options.headers || {});
2841
- case HttpTransportType.ServerSentEvents:
2842
- if (!this._options.EventSource) {
2843
- throw new Error("'EventSource' is not supported in your environment.");
2844
- }
2845
- return new ServerSentEventsTransport(this._httpClient, this._httpClient._accessToken, this._logger, this._options);
2846
- case HttpTransportType.LongPolling:
2847
- return new LongPollingTransport(this._httpClient, this._logger, this._options);
2848
- default:
2849
- throw new Error(`Unknown transport: ${transport}.`);
2850
- }
2851
- }
2852
- _startTransport(url, transferFormat) {
2853
- this.transport.onreceive = this.onreceive;
2854
- if (this.features.reconnect) {
2855
- this.transport.onclose = async (e) => {
2856
- let callStop = false;
2857
- if (this.features.reconnect) {
2858
- try {
2859
- this.features.disconnected();
2860
- await this.transport.connect(url, transferFormat);
2861
- await this.features.resend();
2862
- }
2863
- catch {
2864
- callStop = true;
2865
- }
2866
- }
2867
- else {
2868
- this._stopConnection(e);
2869
- return;
2870
- }
2871
- if (callStop) {
2872
- this._stopConnection(e);
2873
- }
2874
- };
2875
- }
2876
- else {
2877
- this.transport.onclose = (e) => this._stopConnection(e);
2878
- }
2879
- return this.transport.connect(url, transferFormat);
2880
- }
2881
- _resolveTransportOrError(endpoint, requestedTransport, requestedTransferFormat, useStatefulReconnect) {
2882
- const transport = HttpTransportType[endpoint.transport];
2883
- if (transport === null || transport === undefined) {
2884
- this._logger.log(LogLevel.Debug, `Skipping transport '${endpoint.transport}' because it is not supported by this client.`);
2885
- return new Error(`Skipping transport '${endpoint.transport}' because it is not supported by this client.`);
2886
- }
2887
- else {
2888
- if (transportMatches(requestedTransport, transport)) {
2889
- const transferFormats = endpoint.transferFormats.map((s) => TransferFormat[s]);
2890
- if (transferFormats.indexOf(requestedTransferFormat) >= 0) {
2891
- if ((transport === HttpTransportType.WebSockets && !this._options.WebSocket) ||
2892
- (transport === HttpTransportType.ServerSentEvents && !this._options.EventSource)) {
2893
- this._logger.log(LogLevel.Debug, `Skipping transport '${HttpTransportType[transport]}' because it is not supported in your environment.'`);
2894
- return new UnsupportedTransportError(`'${HttpTransportType[transport]}' is not supported in your environment.`, transport);
2895
- }
2896
- else {
2897
- this._logger.log(LogLevel.Debug, `Selecting transport '${HttpTransportType[transport]}'.`);
2898
- try {
2899
- this.features.reconnect = transport === HttpTransportType.WebSockets ? useStatefulReconnect : undefined;
2900
- return this._constructTransport(transport);
2901
- }
2902
- catch (ex) {
2903
- return ex;
2904
- }
2905
- }
2906
- }
2907
- else {
2908
- this._logger.log(LogLevel.Debug, `Skipping transport '${HttpTransportType[transport]}' because it does not support the requested transfer format '${TransferFormat[requestedTransferFormat]}'.`);
2909
- return new Error(`'${HttpTransportType[transport]}' does not support ${TransferFormat[requestedTransferFormat]}.`);
2910
- }
2911
- }
2912
- else {
2913
- this._logger.log(LogLevel.Debug, `Skipping transport '${HttpTransportType[transport]}' because it was disabled by the client.`);
2914
- return new DisabledTransportError(`'${HttpTransportType[transport]}' is disabled by the client.`, transport);
2915
- }
2916
- }
2917
- }
2918
- _isITransport(transport) {
2919
- return transport && typeof (transport) === "object" && "connect" in transport;
2920
- }
2921
- _stopConnection(error) {
2922
- this._logger.log(LogLevel.Debug, `HttpConnection.stopConnection(${error}) called while in state ${this._connectionState}.`);
2923
- this.transport = undefined;
2924
- // If we have a stopError, it takes precedence over the error from the transport
2925
- error = this._stopError || error;
2926
- this._stopError = undefined;
2927
- if (this._connectionState === "Disconnected" /* ConnectionState.Disconnected */) {
2928
- this._logger.log(LogLevel.Debug, `Call to HttpConnection.stopConnection(${error}) was ignored because the connection is already in the disconnected state.`);
2929
- return;
2930
- }
2931
- if (this._connectionState === "Connecting" /* ConnectionState.Connecting */) {
2932
- this._logger.log(LogLevel.Warning, `Call to HttpConnection.stopConnection(${error}) was ignored because the connection is still in the connecting state.`);
2933
- throw new Error(`HttpConnection.stopConnection(${error}) was called while the connection is still in the connecting state.`);
2934
- }
2935
- if (this._connectionState === "Disconnecting" /* ConnectionState.Disconnecting */) {
2936
- // A call to stop() induced this call to stopConnection and needs to be completed.
2937
- // Any stop() awaiters will be scheduled to continue after the onclose callback fires.
2938
- this._stopPromiseResolver();
2939
- }
2940
- if (error) {
2941
- this._logger.log(LogLevel.Error, `Connection disconnected with error '${error}'.`);
2942
- }
2943
- else {
2944
- this._logger.log(LogLevel.Information, "Connection disconnected.");
2945
- }
2946
- if (this._sendQueue) {
2947
- this._sendQueue.stop().catch((e) => {
2948
- this._logger.log(LogLevel.Error, `TransportSendQueue.stop() threw error '${e}'.`);
2949
- });
2950
- this._sendQueue = undefined;
2951
- }
2952
- this.connectionId = undefined;
2953
- this._connectionState = "Disconnected" /* ConnectionState.Disconnected */;
2954
- if (this._connectionStarted) {
2955
- this._connectionStarted = false;
2956
- try {
2957
- if (this.onclose) {
2958
- this.onclose(error);
2959
- }
2960
- }
2961
- catch (e) {
2962
- this._logger.log(LogLevel.Error, `HttpConnection.onclose(${error}) threw error '${e}'.`);
2963
- }
2964
- }
2965
- }
2966
- _resolveUrl(url) {
2967
- // startsWith is not supported in IE
2968
- if (url.lastIndexOf("https://", 0) === 0 || url.lastIndexOf("http://", 0) === 0) {
2969
- return url;
2970
- }
2971
- if (!Platform.isBrowser) {
2972
- throw new Error(`Cannot resolve '${url}'.`);
2973
- }
2974
- // Setting the url to the href propery of an anchor tag handles normalization
2975
- // for us. There are 3 main cases.
2976
- // 1. Relative path normalization e.g "b" -> "http://localhost:5000/a/b"
2977
- // 2. Absolute path normalization e.g "/a/b" -> "http://localhost:5000/a/b"
2978
- // 3. Networkpath reference normalization e.g "//localhost:5000/a/b" -> "http://localhost:5000/a/b"
2979
- const aTag = window.document.createElement("a");
2980
- aTag.href = url;
2981
- this._logger.log(LogLevel.Information, `Normalizing '${url}' to '${aTag.href}'.`);
2982
- return aTag.href;
2983
- }
2984
- _resolveNegotiateUrl(url) {
2985
- const negotiateUrl = new URL(url);
2986
- if (negotiateUrl.pathname.endsWith('/')) {
2987
- negotiateUrl.pathname += "negotiate";
2988
- }
2989
- else {
2990
- negotiateUrl.pathname += "/negotiate";
2991
- }
2992
- const searchParams = new URLSearchParams(negotiateUrl.searchParams);
2993
- if (!searchParams.has("negotiateVersion")) {
2994
- searchParams.append("negotiateVersion", this._negotiateVersion.toString());
2995
- }
2996
- if (searchParams.has("useStatefulReconnect")) {
2997
- if (searchParams.get("useStatefulReconnect") === "true") {
2998
- this._options._useStatefulReconnect = true;
2999
- }
3000
- }
3001
- else if (this._options._useStatefulReconnect === true) {
3002
- searchParams.append("useStatefulReconnect", "true");
3003
- }
3004
- negotiateUrl.search = searchParams.toString();
3005
- return negotiateUrl.toString();
3006
- }
3007
- }
3008
- function transportMatches(requestedTransport, actualTransport) {
3009
- return !requestedTransport || ((actualTransport & requestedTransport) !== 0);
3010
- }
3011
- /** @private */
3012
- class TransportSendQueue {
3013
- constructor(_transport) {
3014
- this._transport = _transport;
3015
- this._buffer = [];
3016
- this._executing = true;
3017
- this._sendBufferedData = new PromiseSource();
3018
- this._transportResult = new PromiseSource();
3019
- this._sendLoopPromise = this._sendLoop();
3020
- }
3021
- send(data) {
3022
- this._bufferData(data);
3023
- if (!this._transportResult) {
3024
- this._transportResult = new PromiseSource();
3025
- }
3026
- return this._transportResult.promise;
3027
- }
3028
- stop() {
3029
- this._executing = false;
3030
- this._sendBufferedData.resolve();
3031
- return this._sendLoopPromise;
3032
- }
3033
- _bufferData(data) {
3034
- if (this._buffer.length && typeof (this._buffer[0]) !== typeof (data)) {
3035
- throw new Error(`Expected data to be of type ${typeof (this._buffer)} but was of type ${typeof (data)}`);
3036
- }
3037
- this._buffer.push(data);
3038
- this._sendBufferedData.resolve();
3039
- }
3040
- async _sendLoop() {
3041
- while (true) {
3042
- await this._sendBufferedData.promise;
3043
- if (!this._executing) {
3044
- if (this._transportResult) {
3045
- this._transportResult.reject("Connection stopped.");
3046
- }
3047
- break;
3048
- }
3049
- this._sendBufferedData = new PromiseSource();
3050
- const transportResult = this._transportResult;
3051
- this._transportResult = undefined;
3052
- const data = typeof (this._buffer[0]) === "string" ?
3053
- this._buffer.join("") :
3054
- TransportSendQueue._concatBuffers(this._buffer);
3055
- this._buffer.length = 0;
3056
- try {
3057
- await this._transport.send(data);
3058
- transportResult.resolve();
3059
- }
3060
- catch (error) {
3061
- transportResult.reject(error);
3062
- }
3063
- }
3064
- }
3065
- static _concatBuffers(arrayBuffers) {
3066
- const totalLength = arrayBuffers.map((b) => b.byteLength).reduce((a, b) => a + b);
3067
- const result = new Uint8Array(totalLength);
3068
- let offset = 0;
3069
- for (const item of arrayBuffers) {
3070
- result.set(new Uint8Array(item), offset);
3071
- offset += item.byteLength;
3072
- }
3073
- return result.buffer;
3074
- }
3075
- }
3076
- class PromiseSource {
3077
- constructor() {
3078
- this.promise = new Promise((resolve, reject) => [this._resolver, this._rejecter] = [resolve, reject]);
3079
- }
3080
- resolve() {
3081
- this._resolver();
3082
- }
3083
- reject(reason) {
3084
- this._rejecter(reason);
3085
- }
3086
- }
3087
-
3088
- // Licensed to the .NET Foundation under one or more agreements.
3089
- // The .NET Foundation licenses this file to you under the MIT license.
3090
- const JSON_HUB_PROTOCOL_NAME = "json";
3091
- /** Implements the JSON Hub Protocol. */
3092
- class JsonHubProtocol {
3093
- constructor() {
3094
- /** @inheritDoc */
3095
- this.name = JSON_HUB_PROTOCOL_NAME;
3096
- /** @inheritDoc */
3097
- this.version = 2;
3098
- /** @inheritDoc */
3099
- this.transferFormat = TransferFormat.Text;
3100
- }
3101
- /** Creates an array of {@link @microsoft/signalr.HubMessage} objects from the specified serialized representation.
3102
- *
3103
- * @param {string} input A string containing the serialized representation.
3104
- * @param {ILogger} logger A logger that will be used to log messages that occur during parsing.
3105
- */
3106
- parseMessages(input, logger) {
3107
- // The interface does allow "ArrayBuffer" to be passed in, but this implementation does not. So let's throw a useful error.
3108
- if (typeof input !== "string") {
3109
- throw new Error("Invalid input for JSON hub protocol. Expected a string.");
3110
- }
3111
- if (!input) {
3112
- return [];
3113
- }
3114
- if (logger === null) {
3115
- logger = NullLogger.instance;
3116
- }
3117
- // Parse the messages
3118
- const messages = TextMessageFormat.parse(input);
3119
- const hubMessages = [];
3120
- for (const message of messages) {
3121
- const parsedMessage = JSON.parse(message);
3122
- if (typeof parsedMessage.type !== "number") {
3123
- throw new Error("Invalid payload.");
3124
- }
3125
- switch (parsedMessage.type) {
3126
- case MessageType.Invocation:
3127
- this._isInvocationMessage(parsedMessage);
3128
- break;
3129
- case MessageType.StreamItem:
3130
- this._isStreamItemMessage(parsedMessage);
3131
- break;
3132
- case MessageType.Completion:
3133
- this._isCompletionMessage(parsedMessage);
3134
- break;
3135
- case MessageType.Ping:
3136
- // Single value, no need to validate
3137
- break;
3138
- case MessageType.Close:
3139
- // All optional values, no need to validate
3140
- break;
3141
- case MessageType.Ack:
3142
- this._isAckMessage(parsedMessage);
3143
- break;
3144
- case MessageType.Sequence:
3145
- this._isSequenceMessage(parsedMessage);
3146
- break;
3147
- default:
3148
- // Future protocol changes can add message types, old clients can ignore them
3149
- logger.log(LogLevel.Information, "Unknown message type '" + parsedMessage.type + "' ignored.");
3150
- continue;
3151
- }
3152
- hubMessages.push(parsedMessage);
3153
- }
3154
- return hubMessages;
3155
- }
3156
- /** Writes the specified {@link @microsoft/signalr.HubMessage} to a string and returns it.
3157
- *
3158
- * @param {HubMessage} message The message to write.
3159
- * @returns {string} A string containing the serialized representation of the message.
3160
- */
3161
- writeMessage(message) {
3162
- return TextMessageFormat.write(JSON.stringify(message));
3163
- }
3164
- _isInvocationMessage(message) {
3165
- this._assertNotEmptyString(message.target, "Invalid payload for Invocation message.");
3166
- if (message.invocationId !== undefined) {
3167
- this._assertNotEmptyString(message.invocationId, "Invalid payload for Invocation message.");
3168
- }
3169
- }
3170
- _isStreamItemMessage(message) {
3171
- this._assertNotEmptyString(message.invocationId, "Invalid payload for StreamItem message.");
3172
- if (message.item === undefined) {
3173
- throw new Error("Invalid payload for StreamItem message.");
3174
- }
3175
- }
3176
- _isCompletionMessage(message) {
3177
- if (message.result && message.error) {
3178
- throw new Error("Invalid payload for Completion message.");
3179
- }
3180
- if (!message.result && message.error) {
3181
- this._assertNotEmptyString(message.error, "Invalid payload for Completion message.");
3182
- }
3183
- this._assertNotEmptyString(message.invocationId, "Invalid payload for Completion message.");
3184
- }
3185
- _isAckMessage(message) {
3186
- if (typeof message.sequenceId !== 'number') {
3187
- throw new Error("Invalid SequenceId for Ack message.");
3188
- }
3189
- }
3190
- _isSequenceMessage(message) {
3191
- if (typeof message.sequenceId !== 'number') {
3192
- throw new Error("Invalid SequenceId for Sequence message.");
3193
- }
3194
- }
3195
- _assertNotEmptyString(value, errorMessage) {
3196
- if (typeof value !== "string" || value === "") {
3197
- throw new Error(errorMessage);
3198
- }
3199
- }
3200
- }
3201
-
3202
- // Licensed to the .NET Foundation under one or more agreements.
3203
- // The .NET Foundation licenses this file to you under the MIT license.
3204
- const LogLevelNameMapping = {
3205
- trace: LogLevel.Trace,
3206
- debug: LogLevel.Debug,
3207
- info: LogLevel.Information,
3208
- information: LogLevel.Information,
3209
- warn: LogLevel.Warning,
3210
- warning: LogLevel.Warning,
3211
- error: LogLevel.Error,
3212
- critical: LogLevel.Critical,
3213
- none: LogLevel.None,
3214
- };
3215
- function parseLogLevel(name) {
3216
- // Case-insensitive matching via lower-casing
3217
- // Yes, I know case-folding is a complicated problem in Unicode, but we only support
3218
- // the ASCII strings defined in LogLevelNameMapping anyway, so it's fine -anurse.
3219
- const mapping = LogLevelNameMapping[name.toLowerCase()];
3220
- if (typeof mapping !== "undefined") {
3221
- return mapping;
3222
- }
3223
- else {
3224
- throw new Error(`Unknown log level: ${name}`);
3225
- }
3226
- }
3227
- /** A builder for configuring {@link @microsoft/signalr.HubConnection} instances. */
3228
- class HubConnectionBuilder {
3229
- configureLogging(logging) {
3230
- Arg.isRequired(logging, "logging");
3231
- if (isLogger(logging)) {
3232
- this.logger = logging;
3233
- }
3234
- else if (typeof logging === "string") {
3235
- const logLevel = parseLogLevel(logging);
3236
- this.logger = new ConsoleLogger(logLevel);
3237
- }
3238
- else {
3239
- this.logger = new ConsoleLogger(logging);
3240
- }
3241
- return this;
3242
- }
3243
- withUrl(url, transportTypeOrOptions) {
3244
- Arg.isRequired(url, "url");
3245
- Arg.isNotEmpty(url, "url");
3246
- this.url = url;
3247
- // Flow-typing knows where it's at. Since HttpTransportType is a number and IHttpConnectionOptions is guaranteed
3248
- // to be an object, we know (as does TypeScript) this comparison is all we need to figure out which overload was called.
3249
- if (typeof transportTypeOrOptions === "object") {
3250
- this.httpConnectionOptions = { ...this.httpConnectionOptions, ...transportTypeOrOptions };
3251
- }
3252
- else {
3253
- this.httpConnectionOptions = {
3254
- ...this.httpConnectionOptions,
3255
- transport: transportTypeOrOptions,
3256
- };
3257
- }
3258
- return this;
3259
- }
3260
- /** Configures the {@link @microsoft/signalr.HubConnection} to use the specified Hub Protocol.
3261
- *
3262
- * @param {IHubProtocol} protocol The {@link @microsoft/signalr.IHubProtocol} implementation to use.
3263
- */
3264
- withHubProtocol(protocol) {
3265
- Arg.isRequired(protocol, "protocol");
3266
- this.protocol = protocol;
3267
- return this;
3268
- }
3269
- withAutomaticReconnect(retryDelaysOrReconnectPolicy) {
3270
- if (this.reconnectPolicy) {
3271
- throw new Error("A reconnectPolicy has already been set.");
3272
- }
3273
- if (!retryDelaysOrReconnectPolicy) {
3274
- this.reconnectPolicy = new DefaultReconnectPolicy();
3275
- }
3276
- else if (Array.isArray(retryDelaysOrReconnectPolicy)) {
3277
- this.reconnectPolicy = new DefaultReconnectPolicy(retryDelaysOrReconnectPolicy);
3278
- }
3279
- else {
3280
- this.reconnectPolicy = retryDelaysOrReconnectPolicy;
3281
- }
3282
- return this;
3283
- }
3284
- /** Configures {@link @microsoft/signalr.HubConnection.serverTimeoutInMilliseconds} for the {@link @microsoft/signalr.HubConnection}.
3285
- *
3286
- * @returns The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining.
3287
- */
3288
- withServerTimeout(milliseconds) {
3289
- Arg.isRequired(milliseconds, "milliseconds");
3290
- this._serverTimeoutInMilliseconds = milliseconds;
3291
- return this;
3292
- }
3293
- /** Configures {@link @microsoft/signalr.HubConnection.keepAliveIntervalInMilliseconds} for the {@link @microsoft/signalr.HubConnection}.
3294
- *
3295
- * @returns The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining.
3296
- */
3297
- withKeepAliveInterval(milliseconds) {
3298
- Arg.isRequired(milliseconds, "milliseconds");
3299
- this._keepAliveIntervalInMilliseconds = milliseconds;
3300
- return this;
3301
- }
3302
- /** Enables and configures options for the Stateful Reconnect feature.
3303
- *
3304
- * @returns The {@link @microsoft/signalr.HubConnectionBuilder} instance, for chaining.
3305
- */
3306
- withStatefulReconnect(options) {
3307
- if (this.httpConnectionOptions === undefined) {
3308
- this.httpConnectionOptions = {};
3309
- }
3310
- this.httpConnectionOptions._useStatefulReconnect = true;
3311
- this._statefulReconnectBufferSize = options === null || options === void 0 ? void 0 : options.bufferSize;
3312
- return this;
3313
- }
3314
- /** Creates a {@link @microsoft/signalr.HubConnection} from the configuration options specified in this builder.
3315
- *
3316
- * @returns {HubConnection} The configured {@link @microsoft/signalr.HubConnection}.
3317
- */
3318
- build() {
3319
- // If httpConnectionOptions has a logger, use it. Otherwise, override it with the one
3320
- // provided to configureLogger
3321
- const httpConnectionOptions = this.httpConnectionOptions || {};
3322
- // If it's 'null', the user **explicitly** asked for null, don't mess with it.
3323
- if (httpConnectionOptions.logger === undefined) {
3324
- // If our logger is undefined or null, that's OK, the HttpConnection constructor will handle it.
3325
- httpConnectionOptions.logger = this.logger;
3326
- }
3327
- // Now create the connection
3328
- if (!this.url) {
3329
- throw new Error("The 'HubConnectionBuilder.withUrl' method must be called before building the connection.");
3330
- }
3331
- const connection = new HttpConnection(this.url, httpConnectionOptions);
3332
- return HubConnection.create(connection, this.logger || NullLogger.instance, this.protocol || new JsonHubProtocol(), this.reconnectPolicy, this._serverTimeoutInMilliseconds, this._keepAliveIntervalInMilliseconds, this._statefulReconnectBufferSize);
3333
- }
3334
- }
3335
- function isLogger(logger) {
3336
- return logger.log !== undefined;
3337
- }
3338
-
3339
- export { HubConnectionBuilder as H, LogLevel as L };