@rindo/core 1.8.12 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (608) hide show
  1. package/LICENSE.md +27 -27
  2. package/bin/cli.ts +20 -0
  3. package/bin/rindo +51 -22
  4. package/cli/index.cjs +1263 -0
  5. package/cli/index.d.ts +15 -0
  6. package/cli/index.js +1237 -0
  7. package/cli/package.json +14 -0
  8. package/compiler/lib.d.ts +24 -0
  9. package/compiler/lib.dom.d.ts +20230 -0
  10. package/compiler/lib.dom.iterable.d.ts +351 -0
  11. package/compiler/lib.es2015.collection.d.ts +89 -0
  12. package/compiler/lib.es2015.core.d.ts +517 -0
  13. package/compiler/lib.es2015.d.ts +30 -0
  14. package/compiler/lib.es2015.generator.d.ts +79 -0
  15. package/compiler/lib.es2015.iterable.d.ts +505 -0
  16. package/compiler/lib.es2015.promise.d.ts +150 -0
  17. package/compiler/lib.es2015.proxy.d.ts +41 -0
  18. package/compiler/lib.es2015.reflect.d.ts +123 -0
  19. package/compiler/lib.es2015.symbol.d.ts +48 -0
  20. package/compiler/lib.es2015.symbol.wellknown.d.ts +324 -0
  21. package/compiler/lib.es2016.array.include.d.ts +118 -0
  22. package/compiler/lib.es2016.d.ts +22 -0
  23. package/compiler/lib.es2016.full.d.ts +25 -0
  24. package/compiler/lib.es2017.d.ts +26 -0
  25. package/compiler/lib.es2017.full.d.ts +25 -0
  26. package/compiler/lib.es2017.intl.d.ts +32 -0
  27. package/compiler/lib.es2017.object.d.ts +51 -0
  28. package/compiler/lib.es2017.sharedmemory.d.ts +137 -0
  29. package/compiler/lib.es2017.string.d.ts +47 -0
  30. package/compiler/lib.es2017.typedarrays.d.ts +55 -0
  31. package/compiler/lib.es2018.asyncgenerator.d.ts +79 -0
  32. package/compiler/lib.es2018.asynciterable.d.ts +45 -0
  33. package/compiler/lib.es2018.d.ts +26 -0
  34. package/compiler/lib.es2018.full.d.ts +25 -0
  35. package/compiler/lib.es2018.intl.d.ts +61 -0
  36. package/compiler/lib.es2018.promise.d.ts +32 -0
  37. package/compiler/lib.es2018.regexp.d.ts +39 -0
  38. package/compiler/lib.es2019.array.d.ts +85 -0
  39. package/compiler/lib.es2019.d.ts +25 -0
  40. package/compiler/lib.es2019.full.d.ts +25 -0
  41. package/compiler/lib.es2019.object.d.ts +35 -0
  42. package/compiler/lib.es2019.string.d.ts +33 -0
  43. package/compiler/lib.es2019.symbol.d.ts +26 -0
  44. package/compiler/lib.es2020.bigint.d.ts +728 -0
  45. package/compiler/lib.es2020.d.ts +27 -0
  46. package/compiler/lib.es2020.full.d.ts +25 -0
  47. package/compiler/lib.es2020.intl.d.ts +310 -0
  48. package/compiler/lib.es2020.promise.d.ts +50 -0
  49. package/compiler/lib.es2020.sharedmemory.d.ts +99 -0
  50. package/compiler/lib.es2020.string.d.ts +30 -0
  51. package/compiler/lib.es2020.symbol.wellknown.d.ts +39 -0
  52. package/compiler/lib.es5.d.ts +4435 -0
  53. package/compiler/lib.es6.d.ts +25 -0
  54. package/compiler/lib.esnext.d.ts +25 -0
  55. package/compiler/lib.esnext.full.d.ts +25 -0
  56. package/compiler/lib.esnext.intl.d.ts +32 -0
  57. package/compiler/lib.esnext.promise.d.ts +43 -0
  58. package/compiler/lib.esnext.string.d.ts +35 -0
  59. package/compiler/lib.esnext.weakref.d.ts +75 -0
  60. package/compiler/lib.scripthost.d.ts +327 -0
  61. package/compiler/lib.webworker.d.ts +6042 -0
  62. package/compiler/lib.webworker.importscripts.d.ts +26 -0
  63. package/compiler/lib.webworker.iterable.d.ts +166 -0
  64. package/compiler/package.json +8 -6
  65. package/compiler/rindo.d.ts +95 -0
  66. package/compiler/rindo.js +65051 -6657
  67. package/compiler/rindo.min.js +4 -0
  68. package/dependencies.json +103 -0
  69. package/dev-server/client/app-error.d.ts +18 -0
  70. package/dev-server/client/events.d.ts +6 -0
  71. package/dev-server/client/hmr-components.d.ts +1 -0
  72. package/dev-server/client/hmr-external-styles.d.ts +1 -0
  73. package/dev-server/client/hmr-images.d.ts +1 -0
  74. package/dev-server/client/hmr-inline-styles.d.ts +1 -0
  75. package/dev-server/client/hmr-util.d.ts +9 -0
  76. package/dev-server/client/hmr-window.d.ts +10 -0
  77. package/dev-server/client/index.d.ts +6 -0
  78. package/dev-server/client/index.js +808 -0
  79. package/dev-server/client/logger.d.ts +5 -0
  80. package/dev-server/client/package.json +8 -0
  81. package/dev-server/client/progress.d.ts +3 -0
  82. package/dev-server/client/status.d.ts +4 -0
  83. package/dev-server/connector.html +6 -0
  84. package/dev-server/index.d.ts +3 -0
  85. package/dev-server/index.js +264 -0
  86. package/dev-server/open-in-editor-api.js +1 -0
  87. package/dev-server/package.json +8 -0
  88. package/dev-server/server-process.js +1738 -0
  89. package/dev-server/server-worker-thread.js +39 -0
  90. package/{dist/dev-server → dev-server}/templates/directory-index.html +132 -132
  91. package/{dist/dev-server → dev-server}/templates/initial-load.html +160 -160
  92. package/dev-server/ws.js +1 -0
  93. package/internal/app-data/index.cjs +90 -0
  94. package/internal/app-data/index.d.ts +4 -0
  95. package/internal/{client/build-conditionals.mjs → app-data/index.js} +25 -21
  96. package/internal/app-data/package.json +15 -0
  97. package/internal/client/css-shim.js +4 -0
  98. package/internal/client/{dom.rindo-client.mjs → dom.js} +73 -137
  99. package/{dist/client/index.mjs → internal/client/index.js} +863 -789
  100. package/internal/client/package.json +8 -0
  101. package/internal/client/patch-browser.js +120 -0
  102. package/internal/client/patch-esm.js +23 -0
  103. package/internal/client/polyfills/core-js.js +11 -10
  104. package/internal/client/polyfills/css-shim.js +1 -656
  105. package/internal/client/polyfills/dom.js +79 -146
  106. package/internal/client/polyfills/es5-html-element.js +1 -18
  107. package/internal/client/polyfills/index.js +34 -35
  108. package/internal/client/{shadow-css.rindo-client.mjs → shadow-css.js} +20 -17
  109. package/internal/hydrate/index.js +1097 -0
  110. package/internal/hydrate/package.json +7 -0
  111. package/internal/hydrate/runner.d.ts +217 -0
  112. package/internal/hydrate/runner.js +777 -0
  113. package/internal/hydrate/shadow-css.js +146 -0
  114. package/internal/index.d.ts +4 -18
  115. package/internal/index.js +1 -1
  116. package/internal/package.json +9 -6
  117. package/internal/rindo-core/index.cjs +1 -0
  118. package/internal/rindo-core/index.d.ts +51 -0
  119. package/internal/rindo-core/index.js +15 -0
  120. package/internal/rindo-ext-modules.d.ts +41 -0
  121. package/internal/rindo-private.d.ts +2128 -0
  122. package/internal/rindo-public-compiler.d.ts +2170 -0
  123. package/{dist/declarations/docs.d.ts → internal/rindo-public-docs.d.ts} +13 -1
  124. package/internal/rindo-public-runtime.d.ts +1555 -0
  125. package/internal/testing/index.js +1055 -0
  126. package/internal/testing/package.json +7 -0
  127. package/internal/testing/shadow-css.js +146 -0
  128. package/mock-doc/index.cjs +4610 -0
  129. package/mock-doc/index.d.ts +916 -0
  130. package/mock-doc/index.js +4574 -2
  131. package/mock-doc/package.json +15 -10
  132. package/package.json +132 -186
  133. package/readme.md +21 -174
  134. package/screenshot/compare/build/app.css +1 -1
  135. package/screenshot/compare/build/app.esm.js +1 -1
  136. package/screenshot/compare/build/app.js +33 -818
  137. package/screenshot/compare/build/{p-113f7459.js → p-081b0641.js} +1 -1
  138. package/screenshot/compare/build/p-227a1e18.entry.js +1 -0
  139. package/screenshot/compare/build/p-2c298727.entry.js +1 -0
  140. package/screenshot/compare/build/p-5479268c.entry.js +1 -0
  141. package/screenshot/compare/build/p-573ec8a4.entry.js +1 -0
  142. package/screenshot/compare/build/p-6ba08604.entry.js +1 -0
  143. package/screenshot/compare/build/p-6bc63295.entry.js +1 -0
  144. package/screenshot/compare/build/p-7a3759fd.entry.js +1 -0
  145. package/screenshot/compare/build/{p-ejpsp3kx.js → p-7b4e3ba7.js} +1 -1
  146. package/screenshot/compare/build/p-988eb362.css +1 -0
  147. package/screenshot/compare/build/p-9b6a9315.js +1 -0
  148. package/screenshot/compare/build/p-b4cc611c.entry.js +1 -0
  149. package/screenshot/compare/build/p-d1bf53f5.entry.js +1 -0
  150. package/screenshot/compare/build/{p-efb0eac6.js → p-e2efe0df.js} +1 -1
  151. package/screenshot/compare/build/p-e8ca6d97.entry.js +1 -0
  152. package/screenshot/compare/build/p-ec2f13e0.entry.js +1 -0
  153. package/screenshot/compare/build/p-f0b99977.entry.js +1 -0
  154. package/screenshot/compare/build/p-f4745c2f.entry.js +1 -0
  155. package/screenshot/compare/build/p-fbbae598.js +1 -0
  156. package/screenshot/compare/host.config.json +14 -14
  157. package/screenshot/compare/index.html +1 -1
  158. package/{dist/screenshot → screenshot}/connector-base.d.ts +1 -1
  159. package/{dist/screenshot → screenshot}/connector-local.d.ts +1 -1
  160. package/screenshot/connector.js +2 -3
  161. package/{dist/screenshot → screenshot}/index.d.ts +1 -1
  162. package/screenshot/index.js +659 -2
  163. package/screenshot/local-connector.js +2 -3
  164. package/screenshot/package.json +15 -13
  165. package/screenshot/pixel-match.js +62 -49
  166. package/screenshot/screenshot-compare.d.ts +3 -0
  167. package/{dist/screenshot → screenshot}/screenshot-fs.d.ts +1 -1
  168. package/sys/deno/index.js +1785 -0
  169. package/sys/deno/node-compat.js +2654 -0
  170. package/sys/deno/worker.js +44 -0
  171. package/sys/node/autoprefixer.js +8 -0
  172. package/sys/node/glob.js +1 -0
  173. package/sys/node/graceful-fs.js +1 -0
  174. package/sys/node/index.d.ts +18 -0
  175. package/sys/node/index.js +1386 -2
  176. package/sys/node/node-fetch.js +1 -0
  177. package/sys/node/package.json +8 -5
  178. package/sys/node/prompts.js +1 -0
  179. package/sys/node/worker.js +52 -0
  180. package/{dist/testing → testing}/index.d.ts +5 -6
  181. package/testing/index.js +4017 -2
  182. package/testing/jest/jest-config.d.ts +5 -0
  183. package/{dist/testing → testing}/jest/jest-environment.d.ts +4 -2
  184. package/{dist/testing → testing}/jest/jest-preprocessor.d.ts +1 -0
  185. package/{dist/testing → testing}/jest/jest-runner.d.ts +1 -1
  186. package/{dist/testing → testing}/jest/jest-screenshot.d.ts +1 -1
  187. package/{dist/testing → testing}/jest/jest-serializer.d.ts +1 -1
  188. package/testing/jest-environment.js +3 -3
  189. package/testing/jest-preprocessor.js +3 -3
  190. package/testing/jest-preset.js +32 -40
  191. package/testing/jest-runner.js +3 -3
  192. package/testing/jest-setuptestframework.js +3 -3
  193. package/{dist/testing → testing}/matchers/events.d.ts +9 -1
  194. package/{dist/testing → testing}/matchers/index.d.ts +3 -1
  195. package/{dist/testing → testing}/matchers/screenshot.d.ts +1 -1
  196. package/testing/mock-fetch.d.ts +11 -0
  197. package/testing/mocks.d.ts +14 -0
  198. package/testing/package.json +8 -6
  199. package/testing/puppeteer/index.d.ts +2 -0
  200. package/{dist/testing → testing}/puppeteer/puppeteer-browser.d.ts +3 -3
  201. package/{dist/testing → testing}/puppeteer/puppeteer-declarations.d.ts +18 -18
  202. package/{dist/testing → testing}/puppeteer/puppeteer-element.d.ts +7 -5
  203. package/testing/puppeteer/puppeteer-emulate.d.ts +2 -0
  204. package/{dist/testing → testing}/puppeteer/puppeteer-events.d.ts +9 -9
  205. package/testing/puppeteer/puppeteer-page.d.ts +2 -0
  206. package/testing/puppeteer/puppeteer-screenshot.d.ts +4 -0
  207. package/testing/reset-build-conditionals.d.ts +2 -0
  208. package/testing/spec-page.d.ts +2 -0
  209. package/testing/test-transpile.d.ts +2 -0
  210. package/{dist/testing → testing}/testing-logger.d.ts +10 -8
  211. package/testing/testing-sys.d.ts +1 -0
  212. package/{dist/testing → testing}/testing-utils.d.ts +3 -2
  213. package/testing/testing.d.ts +2 -0
  214. package/build-conditionals/index.d.ts +0 -2
  215. package/build-conditionals/index.mjs +0 -66
  216. package/build-conditionals/package.json +0 -6
  217. package/compiler/index.js +0 -2
  218. package/dist/cli/index.js +0 -6068
  219. package/dist/client/css-shim-14a9812e.js +0 -656
  220. package/dist/client/css-shim-69821662.js +0 -658
  221. package/dist/client/declarations/rindo.core.d.ts +0 -1347
  222. package/dist/client/dom-68c8fe31.js +0 -139
  223. package/dist/client/dom-af01458a.js +0 -137
  224. package/dist/client/index.js +0 -2937
  225. package/dist/client/polyfills/core-js.js +0 -10
  226. package/dist/client/polyfills/css-shim.js +0 -656
  227. package/dist/client/polyfills/dom.js +0 -146
  228. package/dist/client/polyfills/es5-html-element.js +0 -18
  229. package/dist/client/polyfills/index.js +0 -35
  230. package/dist/client/polyfills/promise.js +0 -9
  231. package/dist/client/polyfills/system.js +0 -6
  232. package/dist/client/shadow-css-6ef31c68.js +0 -386
  233. package/dist/client/shadow-css-8fd1a9e4.js +0 -388
  234. package/dist/compiler/app-core/app-es5-disabled.d.ts +0 -2
  235. package/dist/compiler/app-core/app-polyfills.d.ts +0 -3
  236. package/dist/compiler/app-core/build-conditionals.d.ts +0 -6
  237. package/dist/compiler/app-core/bundle-app-core.d.ts +0 -6
  238. package/dist/compiler/app-core/component-styles.d.ts +0 -4
  239. package/dist/compiler/app-core/format-component-runtime-meta.d.ts +0 -4
  240. package/dist/compiler/app-core/optimize-module.d.ts +0 -7
  241. package/dist/compiler/browser/build-conditionals-client.d.ts +0 -3
  242. package/dist/compiler/browser/compile-options.d.ts +0 -12
  243. package/dist/compiler/browser/compile.d.ts +0 -2
  244. package/dist/compiler/browser/create-compiler.d.ts +0 -14
  245. package/dist/compiler/browser/index.d.ts +0 -11
  246. package/dist/compiler/build/build-ctx.d.ts +0 -74
  247. package/dist/compiler/build/build-finish.d.ts +0 -3
  248. package/dist/compiler/build/build-hmr.d.ts +0 -2
  249. package/dist/compiler/build/build-results.d.ts +0 -2
  250. package/dist/compiler/build/build-stats.d.ts +0 -3
  251. package/dist/compiler/build/build.d.ts +0 -2
  252. package/dist/compiler/build/cache-stats.d.ts +0 -4
  253. package/dist/compiler/build/compiler-build-id.d.ts +0 -6
  254. package/dist/compiler/build/compiler-ctx.d.ts +0 -44
  255. package/dist/compiler/build/init-index-html.d.ts +0 -2
  256. package/dist/compiler/build/validate-files.d.ts +0 -2
  257. package/dist/compiler/build/write-build.d.ts +0 -2
  258. package/dist/compiler/cache.d.ts +0 -22
  259. package/dist/compiler/compiler.d.ts +0 -27
  260. package/dist/compiler/component-hydrate/bundle-hydrate-factory.d.ts +0 -3
  261. package/dist/compiler/component-hydrate/generate-hydrate-app.d.ts +0 -2
  262. package/dist/compiler/component-hydrate/hydrate-factory-closure.d.ts +0 -2
  263. package/dist/compiler/component-hydrate/update-to-hydrate-components.d.ts +0 -2
  264. package/dist/compiler/component-hydrate/write-hydrate-outputs.d.ts +0 -3
  265. package/dist/compiler/component-lazy/generate-cjs.d.ts +0 -3
  266. package/dist/compiler/component-lazy/generate-esm-browser.d.ts +0 -3
  267. package/dist/compiler/component-lazy/generate-esm.d.ts +0 -3
  268. package/dist/compiler/component-lazy/generate-lazy-app.d.ts +0 -3
  269. package/dist/compiler/component-lazy/generate-lazy-module.d.ts +0 -4
  270. package/dist/compiler/component-lazy/generate-system.d.ts +0 -3
  271. package/dist/compiler/component-lazy/update-to-lazy-component.d.ts +0 -2
  272. package/dist/compiler/component-lazy/write-lazy-entry-module.d.ts +0 -2
  273. package/dist/compiler/component-native/update-to-native-component.d.ts +0 -2
  274. package/dist/compiler/config/config-reload.d.ts +0 -3
  275. package/dist/compiler/config/config-utils.d.ts +0 -4
  276. package/dist/compiler/config/validate-config.d.ts +0 -4
  277. package/dist/compiler/config/validate-copy.d.ts +0 -2
  278. package/dist/compiler/config/validate-dev-server.d.ts +0 -2
  279. package/dist/compiler/config/validate-docs.d.ts +0 -2
  280. package/dist/compiler/config/validate-namespace.d.ts +0 -3
  281. package/dist/compiler/config/validate-output-stats.d.ts +0 -2
  282. package/dist/compiler/config/validate-outputs-angular.d.ts +0 -2
  283. package/dist/compiler/config/validate-outputs-custom.d.ts +0 -2
  284. package/dist/compiler/config/validate-outputs-dist-module.d.ts +0 -2
  285. package/dist/compiler/config/validate-outputs-dist.d.ts +0 -2
  286. package/dist/compiler/config/validate-outputs-hydrate-script.d.ts +0 -2
  287. package/dist/compiler/config/validate-outputs-www.d.ts +0 -2
  288. package/dist/compiler/config/validate-outputs.d.ts +0 -2
  289. package/dist/compiler/config/validate-paths.d.ts +0 -2
  290. package/dist/compiler/config/validate-plugins.d.ts +0 -2
  291. package/dist/compiler/config/validate-prerender.d.ts +0 -2
  292. package/dist/compiler/config/validate-rollup-config.d.ts +0 -2
  293. package/dist/compiler/config/validate-service-worker.d.ts +0 -2
  294. package/dist/compiler/config/validate-testing.d.ts +0 -2
  295. package/dist/compiler/config/validate-workers.d.ts +0 -2
  296. package/dist/compiler/copy/assets-copy-tasks.d.ts +0 -3
  297. package/dist/compiler/copy/hashed-copy.d.ts +0 -2
  298. package/dist/compiler/copy/local-copy-tasks.d.ts +0 -3
  299. package/dist/compiler/docs/constants.d.ts +0 -2
  300. package/dist/compiler/docs/custom/index.d.ts +0 -2
  301. package/dist/compiler/docs/docs.d.ts +0 -2
  302. package/dist/compiler/docs/generate-doc-data.d.ts +0 -3
  303. package/dist/compiler/docs/json/index.d.ts +0 -3
  304. package/dist/compiler/docs/readme/docs-util.d.ts +0 -13
  305. package/dist/compiler/docs/readme/index.d.ts +0 -3
  306. package/dist/compiler/docs/readme/markdown-css-props.d.ts +0 -2
  307. package/dist/compiler/docs/readme/markdown-dependencies.d.ts +0 -2
  308. package/dist/compiler/docs/readme/markdown-events.d.ts +0 -2
  309. package/dist/compiler/docs/readme/markdown-methods.d.ts +0 -2
  310. package/dist/compiler/docs/readme/markdown-props.d.ts +0 -2
  311. package/dist/compiler/docs/readme/markdown-slots.d.ts +0 -2
  312. package/dist/compiler/docs/readme/markdown-usage.d.ts +0 -6
  313. package/dist/compiler/docs/readme/output-docs.d.ts +0 -3
  314. package/dist/compiler/docs/style-docs.d.ts +0 -2
  315. package/dist/compiler/docs/vscode/index.d.ts +0 -2
  316. package/dist/compiler/entries/component-bundles.d.ts +0 -3
  317. package/dist/compiler/entries/component-graph.d.ts +0 -2
  318. package/dist/compiler/entries/default-bundles.d.ts +0 -3
  319. package/dist/compiler/entries/entry-modules.d.ts +0 -6
  320. package/dist/compiler/entries/resolve-component-dependencies.d.ts +0 -2
  321. package/dist/compiler/events.d.ts +0 -15
  322. package/dist/compiler/fs-watch/fs-watch-init.d.ts +0 -2
  323. package/dist/compiler/fs-watch/fs-watch-log.d.ts +0 -2
  324. package/dist/compiler/fs-watch/fs-watch-rebuild.d.ts +0 -7
  325. package/dist/compiler/html/inject-module-preloads.d.ts +0 -3
  326. package/dist/compiler/html/inject-sw-script.d.ts +0 -4
  327. package/dist/compiler/html/inline-esm-import.d.ts +0 -2
  328. package/dist/compiler/html/inline-style-sheets.d.ts +0 -2
  329. package/dist/compiler/html/update-global-styles-link.d.ts +0 -2
  330. package/dist/compiler/html/used-components.d.ts +0 -2
  331. package/dist/compiler/html/utils.d.ts +0 -2
  332. package/dist/compiler/html/validate-manifest-json.d.ts +0 -2
  333. package/dist/compiler/index.d.ts +0 -10
  334. package/dist/compiler/index.js +0 -18008
  335. package/dist/compiler/output-targets/empty-dir.d.ts +0 -6
  336. package/dist/compiler/output-targets/index.d.ts +0 -2
  337. package/dist/compiler/output-targets/output-angular.d.ts +0 -4
  338. package/dist/compiler/output-targets/output-app.d.ts +0 -4
  339. package/dist/compiler/output-targets/output-collection.d.ts +0 -3
  340. package/dist/compiler/output-targets/output-copy.d.ts +0 -2
  341. package/dist/compiler/output-targets/output-custom.d.ts +0 -2
  342. package/dist/compiler/output-targets/output-docs.d.ts +0 -2
  343. package/dist/compiler/output-targets/output-hydrate.d.ts +0 -2
  344. package/dist/compiler/output-targets/output-lazy-loader.d.ts +0 -2
  345. package/dist/compiler/output-targets/output-module.d.ts +0 -4
  346. package/dist/compiler/output-targets/output-prerender.d.ts +0 -2
  347. package/dist/compiler/output-targets/output-service-workers.d.ts +0 -2
  348. package/dist/compiler/output-targets/output-types.d.ts +0 -2
  349. package/dist/compiler/output-targets/output-utils.d.ts +0 -54
  350. package/dist/compiler/output-targets/output-www.d.ts +0 -2
  351. package/dist/compiler/plugin/plugin.d.ts +0 -6
  352. package/dist/compiler/prerender/crawl-urls.d.ts +0 -3
  353. package/dist/compiler/prerender/host-config.d.ts +0 -12
  354. package/dist/compiler/prerender/prerender-config.d.ts +0 -2
  355. package/dist/compiler/prerender/prerender-main.d.ts +0 -2
  356. package/dist/compiler/prerender/prerender-queue.d.ts +0 -3
  357. package/dist/compiler/prerender/prerender-template-html.d.ts +0 -2
  358. package/dist/compiler/prerender/prerendered-write-path.d.ts +0 -2
  359. package/dist/compiler/prerender/robots-txt.d.ts +0 -2
  360. package/dist/compiler/prerender/sitemap-xml.d.ts +0 -3
  361. package/dist/compiler/rollup-plugins/component-entry.d.ts +0 -3
  362. package/dist/compiler/rollup-plugins/css-transformer.d.ts +0 -3
  363. package/dist/compiler/rollup-plugins/global-scripts.d.ts +0 -4
  364. package/dist/compiler/rollup-plugins/image-plugin.d.ts +0 -3
  365. package/dist/compiler/rollup-plugins/in-memory-fs-read.d.ts +0 -3
  366. package/dist/compiler/rollup-plugins/loader.d.ts +0 -4
  367. package/dist/compiler/rollup-plugins/plugin-helper.d.ts +0 -5
  368. package/dist/compiler/rollup-plugins/rindo-build-conditionals.d.ts +0 -7
  369. package/dist/compiler/rollup-plugins/rindo-client.d.ts +0 -3
  370. package/dist/compiler/rollup-plugins/rindo-external-runtime.d.ts +0 -2
  371. package/dist/compiler/rollup-plugins/rindo-hydrate.d.ts +0 -3
  372. package/dist/compiler/rollup-plugins/rindo-public-plugin.d.ts +0 -2
  373. package/dist/compiler/service-worker/generate-sw.d.ts +0 -7
  374. package/dist/compiler/service-worker/service-worker-util.d.ts +0 -2
  375. package/dist/compiler/style/cached-styles.d.ts +0 -5
  376. package/dist/compiler/style/component-styles.d.ts +0 -2
  377. package/dist/compiler/style/css-imports.d.ts +0 -9
  378. package/dist/compiler/style/css-to-esm.d.ts +0 -5
  379. package/dist/compiler/style/generate-styles.d.ts +0 -2
  380. package/dist/compiler/style/global-styles.d.ts +0 -3
  381. package/dist/compiler/style/normalize-styles.d.ts +0 -2
  382. package/dist/compiler/style/optimize-css.d.ts +0 -2
  383. package/dist/compiler/style/scope-css.d.ts +0 -3
  384. package/dist/compiler/style/style-utils.d.ts +0 -10
  385. package/dist/compiler/transformers/add-component-meta-proxy.d.ts +0 -3
  386. package/dist/compiler/transformers/add-component-meta-static.d.ts +0 -4
  387. package/dist/compiler/transformers/add-imports.d.ts +0 -3
  388. package/dist/compiler/transformers/collections/add-external-import.d.ts +0 -2
  389. package/dist/compiler/transformers/collections/parse-collection-components.d.ts +0 -2
  390. package/dist/compiler/transformers/collections/parse-collection-deprecated.d.ts +0 -2
  391. package/dist/compiler/transformers/collections/parse-collection-manifest.d.ts +0 -7
  392. package/dist/compiler/transformers/collections/parse-collection-module.d.ts +0 -2
  393. package/dist/compiler/transformers/component-build-conditionals.d.ts +0 -2
  394. package/dist/compiler/transformers/component-hydrate/hydrate-component.d.ts +0 -3
  395. package/dist/compiler/transformers/component-hydrate/hydrate-runtime-cmp-meta.d.ts +0 -3
  396. package/dist/compiler/transformers/component-hydrate/tranform-to-hydrate-component.d.ts +0 -2
  397. package/dist/compiler/transformers/component-lazy/lazy-component.d.ts +0 -3
  398. package/dist/compiler/transformers/component-lazy/lazy-constructor.d.ts +0 -3
  399. package/dist/compiler/transformers/component-lazy/lazy-element-getter.d.ts +0 -3
  400. package/dist/compiler/transformers/component-lazy/transform-lazy-component.d.ts +0 -4
  401. package/dist/compiler/transformers/component-native/native-component.d.ts +0 -3
  402. package/dist/compiler/transformers/component-native/native-connected-callback.d.ts +0 -3
  403. package/dist/compiler/transformers/component-native/native-constructor.d.ts +0 -3
  404. package/dist/compiler/transformers/component-native/native-element-getter.d.ts +0 -3
  405. package/dist/compiler/transformers/component-native/native-static-style.d.ts +0 -3
  406. package/dist/compiler/transformers/component-native/tranform-to-native-component.d.ts +0 -4
  407. package/dist/compiler/transformers/core-runtime-apis.d.ts +0 -30
  408. package/dist/compiler/transformers/create-event.d.ts +0 -3
  409. package/dist/compiler/transformers/decorators-to-static/component-decorator.d.ts +0 -3
  410. package/dist/compiler/transformers/decorators-to-static/convert-decorators.d.ts +0 -3
  411. package/dist/compiler/transformers/decorators-to-static/decorator-utils.d.ts +0 -10
  412. package/dist/compiler/transformers/decorators-to-static/element-decorator.d.ts +0 -3
  413. package/dist/compiler/transformers/decorators-to-static/event-decorator.d.ts +0 -4
  414. package/dist/compiler/transformers/decorators-to-static/listen-decorator.d.ts +0 -6
  415. package/dist/compiler/transformers/decorators-to-static/method-decorator.d.ts +0 -3
  416. package/dist/compiler/transformers/decorators-to-static/prop-decorator.d.ts +0 -4
  417. package/dist/compiler/transformers/decorators-to-static/state-decorator.d.ts +0 -3
  418. package/dist/compiler/transformers/decorators-to-static/style-to-static.d.ts +0 -3
  419. package/dist/compiler/transformers/decorators-to-static/watch-decorator.d.ts +0 -3
  420. package/dist/compiler/transformers/define-custom-element.d.ts +0 -3
  421. package/dist/compiler/transformers/host-data-transform.d.ts +0 -3
  422. package/dist/compiler/transformers/legacy-props.d.ts +0 -3
  423. package/dist/compiler/transformers/remove-static-meta-properties.d.ts +0 -2
  424. package/dist/compiler/transformers/reserved-public-members.d.ts +0 -3
  425. package/dist/compiler/transformers/rindo-import-path.d.ts +0 -3
  426. package/dist/compiler/transformers/static-to-meta/call-expression.d.ts +0 -3
  427. package/dist/compiler/transformers/static-to-meta/class-methods.d.ts +0 -3
  428. package/dist/compiler/transformers/static-to-meta/component.d.ts +0 -3
  429. package/dist/compiler/transformers/static-to-meta/element-ref.d.ts +0 -2
  430. package/dist/compiler/transformers/static-to-meta/encapsulation.d.ts +0 -3
  431. package/dist/compiler/transformers/static-to-meta/events.d.ts +0 -3
  432. package/dist/compiler/transformers/static-to-meta/import.d.ts +0 -3
  433. package/dist/compiler/transformers/static-to-meta/listeners.d.ts +0 -3
  434. package/dist/compiler/transformers/static-to-meta/methods.d.ts +0 -3
  435. package/dist/compiler/transformers/static-to-meta/props.d.ts +0 -3
  436. package/dist/compiler/transformers/static-to-meta/states.d.ts +0 -3
  437. package/dist/compiler/transformers/static-to-meta/string-literal.d.ts +0 -3
  438. package/dist/compiler/transformers/static-to-meta/styles.d.ts +0 -3
  439. package/dist/compiler/transformers/static-to-meta/vdom.d.ts +0 -3
  440. package/dist/compiler/transformers/static-to-meta/visitor.d.ts +0 -3
  441. package/dist/compiler/transformers/static-to-meta/watchers.d.ts +0 -3
  442. package/dist/compiler/transformers/style-imports.d.ts +0 -3
  443. package/dist/compiler/transformers/transform-utils.d.ts +0 -31
  444. package/dist/compiler/transformers/update-component-class.d.ts +0 -3
  445. package/dist/compiler/transformers/update-rindo-core-import.d.ts +0 -3
  446. package/dist/compiler/transformers/watcher-meta-transform.d.ts +0 -3
  447. package/dist/compiler/transpile/compiler-options.d.ts +0 -4
  448. package/dist/compiler/transpile/transpile-app.d.ts +0 -2
  449. package/dist/compiler/transpile/transpile-module.d.ts +0 -5
  450. package/dist/compiler/transpile/transpile-service.d.ts +0 -3
  451. package/dist/compiler/transpile/transpile-to-es5-main.d.ts +0 -2
  452. package/dist/compiler/transpile/validate-types-main.d.ts +0 -2
  453. package/dist/compiler/types/generate-app-types.d.ts +0 -2
  454. package/dist/compiler/types/generate-component-types.d.ts +0 -8
  455. package/dist/compiler/types/generate-event-types.d.ts +0 -2
  456. package/dist/compiler/types/generate-method-types.d.ts +0 -2
  457. package/dist/compiler/types/generate-prop-types.d.ts +0 -2
  458. package/dist/compiler/types/generate-types.d.ts +0 -2
  459. package/dist/compiler/types/rindo-types.d.ts +0 -3
  460. package/dist/compiler/types/types-utils.d.ts +0 -4
  461. package/dist/compiler/types/update-import-refs.d.ts +0 -11
  462. package/dist/compiler/types/validate-package-json.d.ts +0 -9
  463. package/dist/declarations/assets.d.ts +0 -17
  464. package/dist/declarations/browser-compile.d.ts +0 -47
  465. package/dist/declarations/build-conditionals.d.ts +0 -91
  466. package/dist/declarations/build-events.d.ts +0 -19
  467. package/dist/declarations/build.d.ts +0 -247
  468. package/dist/declarations/cache.d.ts +0 -11
  469. package/dist/declarations/collection-manifest.d.ts +0 -106
  470. package/dist/declarations/collection.d.ts +0 -139
  471. package/dist/declarations/compiler.d.ts +0 -53
  472. package/dist/declarations/component-compiler-meta.d.ts +0 -198
  473. package/dist/declarations/component-constructor.d.ts +0 -61
  474. package/dist/declarations/component-interfaces.d.ts +0 -123
  475. package/dist/declarations/config.d.ts +0 -409
  476. package/dist/declarations/css-var-shim.d.ts +0 -9
  477. package/dist/declarations/decorators.d.ts +0 -150
  478. package/dist/declarations/dev-server.d.ts +0 -135
  479. package/dist/declarations/diagnostics.d.ts +0 -21
  480. package/dist/declarations/entry.d.ts +0 -28
  481. package/dist/declarations/events.d.ts +0 -13
  482. package/dist/declarations/file-system.d.ts +0 -91
  483. package/dist/declarations/fs-watch.d.ts +0 -15
  484. package/dist/declarations/host-element.d.ts +0 -53
  485. package/dist/declarations/hydrate.d.ts +0 -99
  486. package/dist/declarations/in-memory-fs.d.ts +0 -59
  487. package/dist/declarations/index.d.ts +0 -45
  488. package/dist/declarations/jsdoc.d.ts +0 -16
  489. package/dist/declarations/jsx.d.ts +0 -1050
  490. package/dist/declarations/logger.d.ts +0 -25
  491. package/dist/declarations/minify-js.d.ts +0 -11
  492. package/dist/declarations/module.d.ts +0 -35
  493. package/dist/declarations/optimize-css.d.ts +0 -12
  494. package/dist/declarations/output-targets.d.ts +0 -189
  495. package/dist/declarations/plugin.d.ts +0 -23
  496. package/dist/declarations/prerender.d.ts +0 -79
  497. package/dist/declarations/render.d.ts +0 -62
  498. package/dist/declarations/runtime.d.ts +0 -92
  499. package/dist/declarations/screenshots.d.ts +0 -192
  500. package/dist/declarations/server.d.ts +0 -19
  501. package/dist/declarations/style.d.ts +0 -35
  502. package/dist/declarations/system.d.ts +0 -174
  503. package/dist/declarations/testing.d.ts +0 -523
  504. package/dist/declarations/transpile.d.ts +0 -24
  505. package/dist/declarations/types.d.ts +0 -24
  506. package/dist/declarations/vdom.d.ts +0 -55
  507. package/dist/declarations/worker.d.ts +0 -33
  508. package/dist/dev-server/content-type-db.json +0 -1
  509. package/dist/dev-server/index.js +0 -887
  510. package/dist/dev-server/static/app-error.css +0 -257
  511. package/dist/dev-server/static/dev-server-client.html +0 -13
  512. package/dist/hydrate/index.d.ts +0 -101
  513. package/dist/hydrate/index.mjs +0 -1281
  514. package/dist/hydrate/platform.mjs +0 -347
  515. package/dist/index.d.ts +0 -99
  516. package/dist/index.js +0 -1
  517. package/dist/mock-doc/index.d.ts +0 -851
  518. package/dist/mock-doc/index.js +0 -3982
  519. package/dist/mock-doc/index.mjs +0 -3954
  520. package/dist/runtime/index.js +0 -2576
  521. package/dist/runtime/index.mjs +0 -2521
  522. package/dist/runtime/shadow-css-6ef31c68.js +0 -386
  523. package/dist/runtime/shadow-css-8fd1a9e4.js +0 -388
  524. package/dist/screenshot/index.js +0 -520
  525. package/dist/sys/node/graceful-fs.js +0 -975
  526. package/dist/sys/node/index.js +0 -33545
  527. package/dist/sys/node/node-fetch.js +0 -1779
  528. package/dist/sys/node/open-in-editor.js +0 -734
  529. package/dist/sys/node/sys-worker.js +0 -67035
  530. package/dist/sys/node/websocket.js +0 -3728
  531. package/dist/testing/build-conditionals.d.ts +0 -4
  532. package/dist/testing/build-conditionals.js +0 -43
  533. package/dist/testing/core.d.ts +0 -35
  534. package/dist/testing/core.js +0 -52
  535. package/dist/testing/index.js +0 -40511
  536. package/dist/testing/jest/jest-config.d.ts +0 -4
  537. package/dist/testing/mock-fetch.d.ts +0 -46
  538. package/dist/testing/mocks.d.ts +0 -12
  539. package/dist/testing/platform.d.ts +0 -23
  540. package/dist/testing/platform.js +0 -321
  541. package/dist/testing/puppeteer/puppeteer-emulate.d.ts +0 -2
  542. package/dist/testing/puppeteer/puppeteer-find.d.ts +0 -5
  543. package/dist/testing/puppeteer/puppeteer-page.d.ts +0 -2
  544. package/dist/testing/puppeteer/puppeteer-screenshot.d.ts +0 -4
  545. package/dist/testing/spec-page.d.ts +0 -5
  546. package/dist/testing/task-queue.d.ts +0 -15
  547. package/dist/testing/test-transpile.d.ts +0 -5
  548. package/dist/testing/testing-fs.d.ts +0 -31
  549. package/dist/testing/testing-sys.d.ts +0 -19
  550. package/dist/testing/testing.d.ts +0 -12
  551. package/dist/utils/index.js +0 -1575
  552. package/dist/utils/index.mjs +0 -1511
  553. package/internal/client/css-shim.rindo-client.mjs +0 -656
  554. package/internal/client/index.mjs +0 -2859
  555. package/internal/client/polyfills/promise.js +0 -9
  556. package/internal/images.d.ts +0 -5
  557. package/runtime/package.json +0 -5
  558. package/screenshot/compare/build/p-020f8d73.js +0 -1
  559. package/screenshot/compare/build/p-09qdknbg.system.entry.js +0 -1
  560. package/screenshot/compare/build/p-0a13mpsc.system.entry.js +0 -1
  561. package/screenshot/compare/build/p-168ec2c4.system.js +0 -1
  562. package/screenshot/compare/build/p-2ab1fdf1.system.js +0 -1
  563. package/screenshot/compare/build/p-2pxcsgrj.entry.js +0 -1
  564. package/screenshot/compare/build/p-42fb7034.system.js +0 -1
  565. package/screenshot/compare/build/p-54d9d7c2.system.js +0 -1
  566. package/screenshot/compare/build/p-67c1f911.js +0 -1
  567. package/screenshot/compare/build/p-68613371.system.js +0 -1
  568. package/screenshot/compare/build/p-7dvsjpu0.entry.js +0 -1
  569. package/screenshot/compare/build/p-aa67fb06.js +0 -1
  570. package/screenshot/compare/build/p-aeb3cec1.system.js +0 -1
  571. package/screenshot/compare/build/p-b6e44a24.js +0 -1
  572. package/screenshot/compare/build/p-c1c25b8a.js +0 -1
  573. package/screenshot/compare/build/p-c9bopbjy.system.entry.js +0 -1
  574. package/screenshot/compare/build/p-c9iqz1pp.system.entry.js +0 -1
  575. package/screenshot/compare/build/p-dizjz8rg.entry.js +0 -1
  576. package/screenshot/compare/build/p-dnta0rwp.system.entry.js +0 -1
  577. package/screenshot/compare/build/p-e9670d22.system.js +0 -1
  578. package/screenshot/compare/build/p-ei9jkpd0.system.entry.js +0 -1
  579. package/screenshot/compare/build/p-ejwcppol.entry.js +0 -1
  580. package/screenshot/compare/build/p-f6612d5d.system.js +0 -1
  581. package/screenshot/compare/build/p-foiivsfc.css +0 -1
  582. package/screenshot/compare/build/p-gpjjyogx.entry.js +0 -1
  583. package/screenshot/compare/build/p-howklem2.system.entry.js +0 -1
  584. package/screenshot/compare/build/p-knv9wvoc.entry.js +0 -1
  585. package/screenshot/compare/build/p-nsqsfhhy.entry.js +0 -1
  586. package/screenshot/compare/build/p-ojt278pp.entry.js +0 -1
  587. package/screenshot/compare/build/p-oywass99.entry.js +0 -1
  588. package/screenshot/compare/build/p-q3ujhub6.entry.js +0 -1
  589. package/screenshot/compare/build/p-qw4xnmxv.entry.js +0 -1
  590. package/screenshot/compare/build/p-t1wvevhc.system.entry.js +0 -1
  591. package/screenshot/compare/build/p-tnjarrex.system.entry.js +0 -1
  592. package/screenshot/compare/build/p-vhfpd6kk.system.entry.js +0 -1
  593. package/screenshot/compare/build/p-vk6rhemd.system.entry.js +0 -1
  594. package/screenshot/compare/build/p-w6bnm16k.entry.js +0 -1
  595. package/screenshot/compare/build/p-xje6d7zl.system.entry.js +0 -1
  596. package/screenshot/compare/build/p-y5jlrcha.system.entry.js +0 -1
  597. package/screenshot/compare/build/p-yh170wkt.entry.js +0 -1
  598. package/testing/jest.preprocessor.js +0 -7
  599. /package/{dist/dev-server → dev-server}/static/favicon.ico +0 -0
  600. /package/{dist/sys/node → dev-server}/visualstudio.vbs +0 -0
  601. /package/{dist/sys/node → dev-server}/xdg-open +0 -0
  602. /package/{dist/compiler/polyfills.d.ts → screenshot/compare/build/index.esm.js} +0 -0
  603. /package/{dist/screenshot → screenshot}/pixel-match.d.ts +0 -0
  604. /package/{dist/testing → testing}/jest/jest-setup-test-framework.d.ts +0 -0
  605. /package/{dist/testing → testing}/matchers/attributes.d.ts +0 -0
  606. /package/{dist/testing → testing}/matchers/class-list.d.ts +0 -0
  607. /package/{dist/testing → testing}/matchers/html.d.ts +0 -0
  608. /package/{dist/testing → testing}/matchers/text.d.ts +0 -0
@@ -1,3728 +0,0 @@
1
- (function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
2
- /******/ // The module cache
3
- /******/ var installedModules = {};
4
- /******/
5
- /******/ // The require function
6
- /******/ function __webpack_require__(moduleId) {
7
- /******/
8
- /******/ // Check if module is in cache
9
- /******/ if(installedModules[moduleId]) {
10
- /******/ return installedModules[moduleId].exports;
11
- /******/ }
12
- /******/ // Create a new module (and put it into the cache)
13
- /******/ var module = installedModules[moduleId] = {
14
- /******/ i: moduleId,
15
- /******/ l: false,
16
- /******/ exports: {}
17
- /******/ };
18
- /******/
19
- /******/ // Execute the module function
20
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21
- /******/
22
- /******/ // Flag the module as loaded
23
- /******/ module.l = true;
24
- /******/
25
- /******/ // Return the exports of the module
26
- /******/ return module.exports;
27
- /******/ }
28
- /******/
29
- /******/
30
- /******/ // expose the modules object (__webpack_modules__)
31
- /******/ __webpack_require__.m = modules;
32
- /******/
33
- /******/ // expose the module cache
34
- /******/ __webpack_require__.c = installedModules;
35
- /******/
36
- /******/ // define getter function for harmony exports
37
- /******/ __webpack_require__.d = function(exports, name, getter) {
38
- /******/ if(!__webpack_require__.o(exports, name)) {
39
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
40
- /******/ }
41
- /******/ };
42
- /******/
43
- /******/ // define __esModule on exports
44
- /******/ __webpack_require__.r = function(exports) {
45
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
46
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
47
- /******/ }
48
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
49
- /******/ };
50
- /******/
51
- /******/ // create a fake namespace object
52
- /******/ // mode & 1: value is a module id, require it
53
- /******/ // mode & 2: merge all properties of value into the ns
54
- /******/ // mode & 4: return value when already ns object
55
- /******/ // mode & 8|1: behave like require
56
- /******/ __webpack_require__.t = function(value, mode) {
57
- /******/ if(mode & 1) value = __webpack_require__(value);
58
- /******/ if(mode & 8) return value;
59
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
60
- /******/ var ns = Object.create(null);
61
- /******/ __webpack_require__.r(ns);
62
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
63
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
64
- /******/ return ns;
65
- /******/ };
66
- /******/
67
- /******/ // getDefaultExport function for compatibility with non-harmony modules
68
- /******/ __webpack_require__.n = function(module) {
69
- /******/ var getter = module && module.__esModule ?
70
- /******/ function getDefault() { return module['default']; } :
71
- /******/ function getModuleExports() { return module; };
72
- /******/ __webpack_require__.d(getter, 'a', getter);
73
- /******/ return getter;
74
- /******/ };
75
- /******/
76
- /******/ // Object.prototype.hasOwnProperty.call
77
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
78
- /******/
79
- /******/ // __webpack_public_path__
80
- /******/ __webpack_require__.p = "";
81
- /******/
82
- /******/
83
- /******/ // Load entry module and return exports
84
- /******/ return __webpack_require__(__webpack_require__.s = 12);
85
- /******/ })
86
- /************************************************************************/
87
- /******/ ([
88
- /* 0 */
89
- /***/ (function(module, exports, __webpack_require__) {
90
-
91
- "use strict";
92
-
93
-
94
- module.exports = {
95
- BINARY_TYPES: ['nodebuffer', 'arraybuffer', 'fragments'],
96
- GUID: '258EAFA5-E914-47DA-95CA-C5AB0DC85B11',
97
- kStatusCode: Symbol('status-code'),
98
- kWebSocket: Symbol('websocket'),
99
- EMPTY_BUFFER: Buffer.alloc(0),
100
- NOOP: () => {}
101
- };
102
-
103
-
104
- /***/ }),
105
- /* 1 */
106
- /***/ (function(module, exports, __webpack_require__) {
107
-
108
- "use strict";
109
-
110
-
111
- const Limiter = __webpack_require__(18);
112
- const zlib = __webpack_require__(19);
113
-
114
- const bufferUtil = __webpack_require__(2);
115
- const { kStatusCode, NOOP } = __webpack_require__(0);
116
-
117
- const TRAILER = Buffer.from([0x00, 0x00, 0xff, 0xff]);
118
- const EMPTY_BLOCK = Buffer.from([0x00]);
119
-
120
- const kPerMessageDeflate = Symbol('permessage-deflate');
121
- const kTotalLength = Symbol('total-length');
122
- const kCallback = Symbol('callback');
123
- const kBuffers = Symbol('buffers');
124
- const kError = Symbol('error');
125
-
126
- //
127
- // We limit zlib concurrency, which prevents severe memory fragmentation
128
- // as documented in https://github.com/nodejs/node/issues/8871#issuecomment-250915913
129
- // and https://github.com/websockets/ws/issues/1202
130
- //
131
- // Intentionally global; it's the global thread pool that's an issue.
132
- //
133
- let zlibLimiter;
134
-
135
- /**
136
- * permessage-deflate implementation.
137
- */
138
- class PerMessageDeflate {
139
- /**
140
- * Creates a PerMessageDeflate instance.
141
- *
142
- * @param {Object} options Configuration options
143
- * @param {Boolean} options.serverNoContextTakeover Request/accept disabling
144
- * of server context takeover
145
- * @param {Boolean} options.clientNoContextTakeover Advertise/acknowledge
146
- * disabling of client context takeover
147
- * @param {(Boolean|Number)} options.serverMaxWindowBits Request/confirm the
148
- * use of a custom server window size
149
- * @param {(Boolean|Number)} options.clientMaxWindowBits Advertise support
150
- * for, or request, a custom client window size
151
- * @param {Object} options.zlibDeflateOptions Options to pass to zlib on deflate
152
- * @param {Object} options.zlibInflateOptions Options to pass to zlib on inflate
153
- * @param {Number} options.threshold Size (in bytes) below which messages
154
- * should not be compressed
155
- * @param {Number} options.concurrencyLimit The number of concurrent calls to
156
- * zlib
157
- * @param {Boolean} isServer Create the instance in either server or client
158
- * mode
159
- * @param {Number} maxPayload The maximum allowed message length
160
- */
161
- constructor(options, isServer, maxPayload) {
162
- this._maxPayload = maxPayload | 0;
163
- this._options = options || {};
164
- this._threshold =
165
- this._options.threshold !== undefined ? this._options.threshold : 1024;
166
- this._isServer = !!isServer;
167
- this._deflate = null;
168
- this._inflate = null;
169
-
170
- this.params = null;
171
-
172
- if (!zlibLimiter) {
173
- const concurrency =
174
- this._options.concurrencyLimit !== undefined
175
- ? this._options.concurrencyLimit
176
- : 10;
177
- zlibLimiter = new Limiter({ concurrency });
178
- }
179
- }
180
-
181
- /**
182
- * @type {String}
183
- */
184
- static get extensionName() {
185
- return 'permessage-deflate';
186
- }
187
-
188
- /**
189
- * Create an extension negotiation offer.
190
- *
191
- * @return {Object} Extension parameters
192
- * @public
193
- */
194
- offer() {
195
- const params = {};
196
-
197
- if (this._options.serverNoContextTakeover) {
198
- params.server_no_context_takeover = true;
199
- }
200
- if (this._options.clientNoContextTakeover) {
201
- params.client_no_context_takeover = true;
202
- }
203
- if (this._options.serverMaxWindowBits) {
204
- params.server_max_window_bits = this._options.serverMaxWindowBits;
205
- }
206
- if (this._options.clientMaxWindowBits) {
207
- params.client_max_window_bits = this._options.clientMaxWindowBits;
208
- } else if (this._options.clientMaxWindowBits == null) {
209
- params.client_max_window_bits = true;
210
- }
211
-
212
- return params;
213
- }
214
-
215
- /**
216
- * Accept an extension negotiation offer/response.
217
- *
218
- * @param {Array} configurations The extension negotiation offers/reponse
219
- * @return {Object} Accepted configuration
220
- * @public
221
- */
222
- accept(configurations) {
223
- configurations = this.normalizeParams(configurations);
224
-
225
- this.params = this._isServer
226
- ? this.acceptAsServer(configurations)
227
- : this.acceptAsClient(configurations);
228
-
229
- return this.params;
230
- }
231
-
232
- /**
233
- * Releases all resources used by the extension.
234
- *
235
- * @public
236
- */
237
- cleanup() {
238
- if (this._inflate) {
239
- this._inflate.close();
240
- this._inflate = null;
241
- }
242
-
243
- if (this._deflate) {
244
- if (this._deflate[kCallback]) {
245
- this._deflate[kCallback]();
246
- }
247
-
248
- this._deflate.close();
249
- this._deflate = null;
250
- }
251
- }
252
-
253
- /**
254
- * Accept an extension negotiation offer.
255
- *
256
- * @param {Array} offers The extension negotiation offers
257
- * @return {Object} Accepted configuration
258
- * @private
259
- */
260
- acceptAsServer(offers) {
261
- const opts = this._options;
262
- const accepted = offers.find((params) => {
263
- if (
264
- (opts.serverNoContextTakeover === false &&
265
- params.server_no_context_takeover) ||
266
- (params.server_max_window_bits &&
267
- (opts.serverMaxWindowBits === false ||
268
- (typeof opts.serverMaxWindowBits === 'number' &&
269
- opts.serverMaxWindowBits > params.server_max_window_bits))) ||
270
- (typeof opts.clientMaxWindowBits === 'number' &&
271
- !params.client_max_window_bits)
272
- ) {
273
- return false;
274
- }
275
-
276
- return true;
277
- });
278
-
279
- if (!accepted) {
280
- throw new Error('None of the extension offers can be accepted');
281
- }
282
-
283
- if (opts.serverNoContextTakeover) {
284
- accepted.server_no_context_takeover = true;
285
- }
286
- if (opts.clientNoContextTakeover) {
287
- accepted.client_no_context_takeover = true;
288
- }
289
- if (typeof opts.serverMaxWindowBits === 'number') {
290
- accepted.server_max_window_bits = opts.serverMaxWindowBits;
291
- }
292
- if (typeof opts.clientMaxWindowBits === 'number') {
293
- accepted.client_max_window_bits = opts.clientMaxWindowBits;
294
- } else if (
295
- accepted.client_max_window_bits === true ||
296
- opts.clientMaxWindowBits === false
297
- ) {
298
- delete accepted.client_max_window_bits;
299
- }
300
-
301
- return accepted;
302
- }
303
-
304
- /**
305
- * Accept the extension negotiation response.
306
- *
307
- * @param {Array} response The extension negotiation response
308
- * @return {Object} Accepted configuration
309
- * @private
310
- */
311
- acceptAsClient(response) {
312
- const params = response[0];
313
-
314
- if (
315
- this._options.clientNoContextTakeover === false &&
316
- params.client_no_context_takeover
317
- ) {
318
- throw new Error('Unexpected parameter "client_no_context_takeover"');
319
- }
320
-
321
- if (!params.client_max_window_bits) {
322
- if (typeof this._options.clientMaxWindowBits === 'number') {
323
- params.client_max_window_bits = this._options.clientMaxWindowBits;
324
- }
325
- } else if (
326
- this._options.clientMaxWindowBits === false ||
327
- (typeof this._options.clientMaxWindowBits === 'number' &&
328
- params.client_max_window_bits > this._options.clientMaxWindowBits)
329
- ) {
330
- throw new Error(
331
- 'Unexpected or invalid parameter "client_max_window_bits"'
332
- );
333
- }
334
-
335
- return params;
336
- }
337
-
338
- /**
339
- * Normalize parameters.
340
- *
341
- * @param {Array} configurations The extension negotiation offers/reponse
342
- * @return {Array} The offers/response with normalized parameters
343
- * @private
344
- */
345
- normalizeParams(configurations) {
346
- configurations.forEach((params) => {
347
- Object.keys(params).forEach((key) => {
348
- let value = params[key];
349
-
350
- if (value.length > 1) {
351
- throw new Error(`Parameter "${key}" must have only a single value`);
352
- }
353
-
354
- value = value[0];
355
-
356
- if (key === 'client_max_window_bits') {
357
- if (value !== true) {
358
- const num = +value;
359
- if (!Number.isInteger(num) || num < 8 || num > 15) {
360
- throw new TypeError(
361
- `Invalid value for parameter "${key}": ${value}`
362
- );
363
- }
364
- value = num;
365
- } else if (!this._isServer) {
366
- throw new TypeError(
367
- `Invalid value for parameter "${key}": ${value}`
368
- );
369
- }
370
- } else if (key === 'server_max_window_bits') {
371
- const num = +value;
372
- if (!Number.isInteger(num) || num < 8 || num > 15) {
373
- throw new TypeError(
374
- `Invalid value for parameter "${key}": ${value}`
375
- );
376
- }
377
- value = num;
378
- } else if (
379
- key === 'client_no_context_takeover' ||
380
- key === 'server_no_context_takeover'
381
- ) {
382
- if (value !== true) {
383
- throw new TypeError(
384
- `Invalid value for parameter "${key}": ${value}`
385
- );
386
- }
387
- } else {
388
- throw new Error(`Unknown parameter "${key}"`);
389
- }
390
-
391
- params[key] = value;
392
- });
393
- });
394
-
395
- return configurations;
396
- }
397
-
398
- /**
399
- * Decompress data. Concurrency limited by async-limiter.
400
- *
401
- * @param {Buffer} data Compressed data
402
- * @param {Boolean} fin Specifies whether or not this is the last fragment
403
- * @param {Function} callback Callback
404
- * @public
405
- */
406
- decompress(data, fin, callback) {
407
- zlibLimiter.push((done) => {
408
- this._decompress(data, fin, (err, result) => {
409
- done();
410
- callback(err, result);
411
- });
412
- });
413
- }
414
-
415
- /**
416
- * Compress data. Concurrency limited by async-limiter.
417
- *
418
- * @param {Buffer} data Data to compress
419
- * @param {Boolean} fin Specifies whether or not this is the last fragment
420
- * @param {Function} callback Callback
421
- * @public
422
- */
423
- compress(data, fin, callback) {
424
- zlibLimiter.push((done) => {
425
- this._compress(data, fin, (err, result) => {
426
- done();
427
- if (err || result) {
428
- callback(err, result);
429
- }
430
- });
431
- });
432
- }
433
-
434
- /**
435
- * Decompress data.
436
- *
437
- * @param {Buffer} data Compressed data
438
- * @param {Boolean} fin Specifies whether or not this is the last fragment
439
- * @param {Function} callback Callback
440
- * @private
441
- */
442
- _decompress(data, fin, callback) {
443
- const endpoint = this._isServer ? 'client' : 'server';
444
-
445
- if (!this._inflate) {
446
- const key = `${endpoint}_max_window_bits`;
447
- const windowBits =
448
- typeof this.params[key] !== 'number'
449
- ? zlib.Z_DEFAULT_WINDOWBITS
450
- : this.params[key];
451
-
452
- this._inflate = zlib.createInflateRaw({
453
- ...this._options.zlibInflateOptions,
454
- windowBits
455
- });
456
- this._inflate[kPerMessageDeflate] = this;
457
- this._inflate[kTotalLength] = 0;
458
- this._inflate[kBuffers] = [];
459
- this._inflate.on('error', inflateOnError);
460
- this._inflate.on('data', inflateOnData);
461
- }
462
-
463
- this._inflate[kCallback] = callback;
464
-
465
- this._inflate.write(data);
466
- if (fin) this._inflate.write(TRAILER);
467
-
468
- this._inflate.flush(() => {
469
- const err = this._inflate[kError];
470
-
471
- if (err) {
472
- this._inflate.close();
473
- this._inflate = null;
474
- callback(err);
475
- return;
476
- }
477
-
478
- const data = bufferUtil.concat(
479
- this._inflate[kBuffers],
480
- this._inflate[kTotalLength]
481
- );
482
-
483
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
484
- this._inflate.close();
485
- this._inflate = null;
486
- } else {
487
- this._inflate[kTotalLength] = 0;
488
- this._inflate[kBuffers] = [];
489
- }
490
-
491
- callback(null, data);
492
- });
493
- }
494
-
495
- /**
496
- * Compress data.
497
- *
498
- * @param {Buffer} data Data to compress
499
- * @param {Boolean} fin Specifies whether or not this is the last fragment
500
- * @param {Function} callback Callback
501
- * @private
502
- */
503
- _compress(data, fin, callback) {
504
- if (!data || data.length === 0) {
505
- process.nextTick(callback, null, EMPTY_BLOCK);
506
- return;
507
- }
508
-
509
- const endpoint = this._isServer ? 'server' : 'client';
510
-
511
- if (!this._deflate) {
512
- const key = `${endpoint}_max_window_bits`;
513
- const windowBits =
514
- typeof this.params[key] !== 'number'
515
- ? zlib.Z_DEFAULT_WINDOWBITS
516
- : this.params[key];
517
-
518
- this._deflate = zlib.createDeflateRaw({
519
- ...this._options.zlibDeflateOptions,
520
- windowBits
521
- });
522
-
523
- this._deflate[kTotalLength] = 0;
524
- this._deflate[kBuffers] = [];
525
-
526
- //
527
- // An `'error'` event is emitted, only on Node.js < 10.0.0, if the
528
- // `zlib.DeflateRaw` instance is closed while data is being processed.
529
- // This can happen if `PerMessageDeflate#cleanup()` is called at the wrong
530
- // time due to an abnormal WebSocket closure.
531
- //
532
- this._deflate.on('error', NOOP);
533
- this._deflate.on('data', deflateOnData);
534
- }
535
-
536
- this._deflate[kCallback] = callback;
537
-
538
- this._deflate.write(data);
539
- this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
540
- if (!this._deflate) {
541
- //
542
- // This `if` statement is only needed for Node.js < 10.0.0 because as of
543
- // commit https://github.com/nodejs/node/commit/5e3f5164, the flush
544
- // callback is no longer called if the deflate stream is closed while
545
- // data is being processed.
546
- //
547
- return;
548
- }
549
-
550
- let data = bufferUtil.concat(
551
- this._deflate[kBuffers],
552
- this._deflate[kTotalLength]
553
- );
554
-
555
- if (fin) data = data.slice(0, data.length - 4);
556
-
557
- //
558
- // Ensure that the callback will not be called again in
559
- // `PerMessageDeflate#cleanup()`.
560
- //
561
- this._deflate[kCallback] = null;
562
-
563
- if (fin && this.params[`${endpoint}_no_context_takeover`]) {
564
- this._deflate.close();
565
- this._deflate = null;
566
- } else {
567
- this._deflate[kTotalLength] = 0;
568
- this._deflate[kBuffers] = [];
569
- }
570
-
571
- callback(null, data);
572
- });
573
- }
574
- }
575
-
576
- module.exports = PerMessageDeflate;
577
-
578
- /**
579
- * The listener of the `zlib.DeflateRaw` stream `'data'` event.
580
- *
581
- * @param {Buffer} chunk A chunk of data
582
- * @private
583
- */
584
- function deflateOnData(chunk) {
585
- this[kBuffers].push(chunk);
586
- this[kTotalLength] += chunk.length;
587
- }
588
-
589
- /**
590
- * The listener of the `zlib.InflateRaw` stream `'data'` event.
591
- *
592
- * @param {Buffer} chunk A chunk of data
593
- * @private
594
- */
595
- function inflateOnData(chunk) {
596
- this[kTotalLength] += chunk.length;
597
-
598
- if (
599
- this[kPerMessageDeflate]._maxPayload < 1 ||
600
- this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload
601
- ) {
602
- this[kBuffers].push(chunk);
603
- return;
604
- }
605
-
606
- this[kError] = new RangeError('Max payload size exceeded');
607
- this[kError][kStatusCode] = 1009;
608
- this.removeListener('data', inflateOnData);
609
- this.reset();
610
- }
611
-
612
- /**
613
- * The listener of the `zlib.InflateRaw` stream `'error'` event.
614
- *
615
- * @param {Error} err The emitted error
616
- * @private
617
- */
618
- function inflateOnError(err) {
619
- //
620
- // There is no need to call `Zlib#close()` as the handle is automatically
621
- // closed when an error is emitted.
622
- //
623
- this[kPerMessageDeflate]._inflate = null;
624
- err[kStatusCode] = 1007;
625
- this[kCallback](err);
626
- }
627
-
628
-
629
- /***/ }),
630
- /* 2 */
631
- /***/ (function(module, exports, __webpack_require__) {
632
-
633
- "use strict";
634
-
635
-
636
- const { EMPTY_BUFFER } = __webpack_require__(0);
637
-
638
- /**
639
- * Merges an array of buffers into a new buffer.
640
- *
641
- * @param {Buffer[]} list The array of buffers to concat
642
- * @param {Number} totalLength The total length of buffers in the list
643
- * @return {Buffer} The resulting buffer
644
- * @public
645
- */
646
- function concat(list, totalLength) {
647
- if (list.length === 0) return EMPTY_BUFFER;
648
- if (list.length === 1) return list[0];
649
-
650
- const target = Buffer.allocUnsafe(totalLength);
651
- let offset = 0;
652
-
653
- for (let i = 0; i < list.length; i++) {
654
- const buf = list[i];
655
- buf.copy(target, offset);
656
- offset += buf.length;
657
- }
658
-
659
- return target;
660
- }
661
-
662
- /**
663
- * Masks a buffer using the given mask.
664
- *
665
- * @param {Buffer} source The buffer to mask
666
- * @param {Buffer} mask The mask to use
667
- * @param {Buffer} output The buffer where to store the result
668
- * @param {Number} offset The offset at which to start writing
669
- * @param {Number} length The number of bytes to mask.
670
- * @public
671
- */
672
- function _mask(source, mask, output, offset, length) {
673
- for (let i = 0; i < length; i++) {
674
- output[offset + i] = source[i] ^ mask[i & 3];
675
- }
676
- }
677
-
678
- /**
679
- * Unmasks a buffer using the given mask.
680
- *
681
- * @param {Buffer} buffer The buffer to unmask
682
- * @param {Buffer} mask The mask to use
683
- * @public
684
- */
685
- function _unmask(buffer, mask) {
686
- // Required until https://github.com/nodejs/node/issues/9006 is resolved.
687
- const length = buffer.length;
688
- for (let i = 0; i < length; i++) {
689
- buffer[i] ^= mask[i & 3];
690
- }
691
- }
692
-
693
- /**
694
- * Converts a buffer to an `ArrayBuffer`.
695
- *
696
- * @param {Buffer} buf The buffer to convert
697
- * @return {ArrayBuffer} Converted buffer
698
- * @public
699
- */
700
- function toArrayBuffer(buf) {
701
- if (buf.byteLength === buf.buffer.byteLength) {
702
- return buf.buffer;
703
- }
704
-
705
- return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
706
- }
707
-
708
- /**
709
- * Converts `data` to a `Buffer`.
710
- *
711
- * @param {*} data The data to convert
712
- * @return {Buffer} The buffer
713
- * @throws {TypeError}
714
- * @public
715
- */
716
- function toBuffer(data) {
717
- toBuffer.readOnly = true;
718
-
719
- if (Buffer.isBuffer(data)) return data;
720
-
721
- let buf;
722
-
723
- if (data instanceof ArrayBuffer) {
724
- buf = Buffer.from(data);
725
- } else if (ArrayBuffer.isView(data)) {
726
- buf = viewToBuffer(data);
727
- } else {
728
- buf = Buffer.from(data);
729
- toBuffer.readOnly = false;
730
- }
731
-
732
- return buf;
733
- }
734
-
735
- /**
736
- * Converts an `ArrayBuffer` view into a buffer.
737
- *
738
- * @param {(DataView|TypedArray)} view The view to convert
739
- * @return {Buffer} Converted view
740
- * @private
741
- */
742
- function viewToBuffer(view) {
743
- const buf = Buffer.from(view.buffer);
744
-
745
- if (view.byteLength !== view.buffer.byteLength) {
746
- return buf.slice(view.byteOffset, view.byteOffset + view.byteLength);
747
- }
748
-
749
- return buf;
750
- }
751
-
752
- try {
753
- const bufferUtil = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module 'bufferutil'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()));
754
- const bu = bufferUtil.BufferUtil || bufferUtil;
755
-
756
- module.exports = {
757
- concat,
758
- mask(source, mask, output, offset, length) {
759
- if (length < 48) _mask(source, mask, output, offset, length);
760
- else bu.mask(source, mask, output, offset, length);
761
- },
762
- toArrayBuffer,
763
- toBuffer,
764
- unmask(buffer, mask) {
765
- if (buffer.length < 32) _unmask(buffer, mask);
766
- else bu.unmask(buffer, mask);
767
- }
768
- };
769
- } catch (e) /* istanbul ignore next */ {
770
- module.exports = {
771
- concat,
772
- mask: _mask,
773
- toArrayBuffer,
774
- toBuffer,
775
- unmask: _unmask
776
- };
777
- }
778
-
779
-
780
- /***/ }),
781
- /* 3 */
782
- /***/ (function(module, exports) {
783
-
784
- module.exports = require("crypto");
785
-
786
- /***/ }),
787
- /* 4 */
788
- /***/ (function(module, exports, __webpack_require__) {
789
-
790
- "use strict";
791
-
792
-
793
- const EventEmitter = __webpack_require__(5);
794
- const https = __webpack_require__(14);
795
- const http = __webpack_require__(6);
796
- const net = __webpack_require__(15);
797
- const tls = __webpack_require__(16);
798
- const { randomBytes, createHash } = __webpack_require__(3);
799
- const { URL } = __webpack_require__(17);
800
-
801
- const PerMessageDeflate = __webpack_require__(1);
802
- const Receiver = __webpack_require__(7);
803
- const Sender = __webpack_require__(10);
804
- const {
805
- BINARY_TYPES,
806
- EMPTY_BUFFER,
807
- GUID,
808
- kStatusCode,
809
- kWebSocket,
810
- NOOP
811
- } = __webpack_require__(0);
812
- const { addEventListener, removeEventListener } = __webpack_require__(20);
813
- const { format, parse } = __webpack_require__(11);
814
- const { toBuffer } = __webpack_require__(2);
815
-
816
- const readyStates = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'];
817
- const protocolVersions = [8, 13];
818
- const closeTimeout = 30 * 1000;
819
-
820
- /**
821
- * Class representing a WebSocket.
822
- *
823
- * @extends EventEmitter
824
- */
825
- class WebSocket extends EventEmitter {
826
- /**
827
- * Create a new `WebSocket`.
828
- *
829
- * @param {(String|url.URL)} address The URL to which to connect
830
- * @param {(String|String[])} protocols The subprotocols
831
- * @param {Object} options Connection options
832
- */
833
- constructor(address, protocols, options) {
834
- super();
835
-
836
- this.readyState = WebSocket.CONNECTING;
837
- this.protocol = '';
838
-
839
- this._binaryType = BINARY_TYPES[0];
840
- this._closeFrameReceived = false;
841
- this._closeFrameSent = false;
842
- this._closeMessage = '';
843
- this._closeTimer = null;
844
- this._closeCode = 1006;
845
- this._extensions = {};
846
- this._receiver = null;
847
- this._sender = null;
848
- this._socket = null;
849
-
850
- if (address !== null) {
851
- this._bufferedAmount = 0;
852
- this._isServer = false;
853
- this._redirects = 0;
854
-
855
- if (Array.isArray(protocols)) {
856
- protocols = protocols.join(', ');
857
- } else if (typeof protocols === 'object' && protocols !== null) {
858
- options = protocols;
859
- protocols = undefined;
860
- }
861
-
862
- initAsClient(this, address, protocols, options);
863
- } else {
864
- this._isServer = true;
865
- }
866
- }
867
-
868
- get CONNECTING() {
869
- return WebSocket.CONNECTING;
870
- }
871
- get CLOSING() {
872
- return WebSocket.CLOSING;
873
- }
874
- get CLOSED() {
875
- return WebSocket.CLOSED;
876
- }
877
- get OPEN() {
878
- return WebSocket.OPEN;
879
- }
880
-
881
- /**
882
- * This deviates from the WHATWG interface since ws doesn't support the
883
- * required default "blob" type (instead we define a custom "nodebuffer"
884
- * type).
885
- *
886
- * @type {String}
887
- */
888
- get binaryType() {
889
- return this._binaryType;
890
- }
891
-
892
- set binaryType(type) {
893
- if (!BINARY_TYPES.includes(type)) return;
894
-
895
- this._binaryType = type;
896
-
897
- //
898
- // Allow to change `binaryType` on the fly.
899
- //
900
- if (this._receiver) this._receiver._binaryType = type;
901
- }
902
-
903
- /**
904
- * @type {Number}
905
- */
906
- get bufferedAmount() {
907
- if (!this._socket) return this._bufferedAmount;
908
-
909
- //
910
- // `socket.bufferSize` is `undefined` if the socket is closed.
911
- //
912
- return (this._socket.bufferSize || 0) + this._sender._bufferedBytes;
913
- }
914
-
915
- /**
916
- * @type {String}
917
- */
918
- get extensions() {
919
- return Object.keys(this._extensions).join();
920
- }
921
-
922
- /**
923
- * Set up the socket and the internal resources.
924
- *
925
- * @param {net.Socket} socket The network socket between the server and client
926
- * @param {Buffer} head The first packet of the upgraded stream
927
- * @param {Number} maxPayload The maximum allowed message size
928
- * @private
929
- */
930
- setSocket(socket, head, maxPayload) {
931
- const receiver = new Receiver(
932
- this._binaryType,
933
- this._extensions,
934
- maxPayload
935
- );
936
-
937
- this._sender = new Sender(socket, this._extensions);
938
- this._receiver = receiver;
939
- this._socket = socket;
940
-
941
- receiver[kWebSocket] = this;
942
- socket[kWebSocket] = this;
943
-
944
- receiver.on('conclude', receiverOnConclude);
945
- receiver.on('drain', receiverOnDrain);
946
- receiver.on('error', receiverOnError);
947
- receiver.on('message', receiverOnMessage);
948
- receiver.on('ping', receiverOnPing);
949
- receiver.on('pong', receiverOnPong);
950
-
951
- socket.setTimeout(0);
952
- socket.setNoDelay();
953
-
954
- if (head.length > 0) socket.unshift(head);
955
-
956
- socket.on('close', socketOnClose);
957
- socket.on('data', socketOnData);
958
- socket.on('end', socketOnEnd);
959
- socket.on('error', socketOnError);
960
-
961
- this.readyState = WebSocket.OPEN;
962
- this.emit('open');
963
- }
964
-
965
- /**
966
- * Emit the `'close'` event.
967
- *
968
- * @private
969
- */
970
- emitClose() {
971
- this.readyState = WebSocket.CLOSED;
972
-
973
- if (!this._socket) {
974
- this.emit('close', this._closeCode, this._closeMessage);
975
- return;
976
- }
977
-
978
- if (this._extensions[PerMessageDeflate.extensionName]) {
979
- this._extensions[PerMessageDeflate.extensionName].cleanup();
980
- }
981
-
982
- this._receiver.removeAllListeners();
983
- this.emit('close', this._closeCode, this._closeMessage);
984
- }
985
-
986
- /**
987
- * Start a closing handshake.
988
- *
989
- * +----------+ +-----------+ +----------+
990
- * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
991
- * | +----------+ +-----------+ +----------+ |
992
- * +----------+ +-----------+ |
993
- * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
994
- * +----------+ +-----------+ |
995
- * | | | +---+ |
996
- * +------------------------+-->|fin| - - - -
997
- * | +---+ | +---+
998
- * - - - - -|fin|<---------------------+
999
- * +---+
1000
- *
1001
- * @param {Number} code Status code explaining why the connection is closing
1002
- * @param {String} data A string explaining why the connection is closing
1003
- * @public
1004
- */
1005
- close(code, data) {
1006
- if (this.readyState === WebSocket.CLOSED) return;
1007
- if (this.readyState === WebSocket.CONNECTING) {
1008
- const msg = 'WebSocket was closed before the connection was established';
1009
- return abortHandshake(this, this._req, msg);
1010
- }
1011
-
1012
- if (this.readyState === WebSocket.CLOSING) {
1013
- if (this._closeFrameSent && this._closeFrameReceived) this._socket.end();
1014
- return;
1015
- }
1016
-
1017
- this.readyState = WebSocket.CLOSING;
1018
- this._sender.close(code, data, !this._isServer, (err) => {
1019
- //
1020
- // This error is handled by the `'error'` listener on the socket. We only
1021
- // want to know if the close frame has been sent here.
1022
- //
1023
- if (err) return;
1024
-
1025
- this._closeFrameSent = true;
1026
- if (this._closeFrameReceived) this._socket.end();
1027
- });
1028
-
1029
- //
1030
- // Specify a timeout for the closing handshake to complete.
1031
- //
1032
- this._closeTimer = setTimeout(
1033
- this._socket.destroy.bind(this._socket),
1034
- closeTimeout
1035
- );
1036
- }
1037
-
1038
- /**
1039
- * Send a ping.
1040
- *
1041
- * @param {*} data The data to send
1042
- * @param {Boolean} mask Indicates whether or not to mask `data`
1043
- * @param {Function} cb Callback which is executed when the ping is sent
1044
- * @public
1045
- */
1046
- ping(data, mask, cb) {
1047
- if (this.readyState === WebSocket.CONNECTING) {
1048
- throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
1049
- }
1050
-
1051
- if (typeof data === 'function') {
1052
- cb = data;
1053
- data = mask = undefined;
1054
- } else if (typeof mask === 'function') {
1055
- cb = mask;
1056
- mask = undefined;
1057
- }
1058
-
1059
- if (typeof data === 'number') data = data.toString();
1060
-
1061
- if (this.readyState !== WebSocket.OPEN) {
1062
- sendAfterClose(this, data, cb);
1063
- return;
1064
- }
1065
-
1066
- if (mask === undefined) mask = !this._isServer;
1067
- this._sender.ping(data || EMPTY_BUFFER, mask, cb);
1068
- }
1069
-
1070
- /**
1071
- * Send a pong.
1072
- *
1073
- * @param {*} data The data to send
1074
- * @param {Boolean} mask Indicates whether or not to mask `data`
1075
- * @param {Function} cb Callback which is executed when the pong is sent
1076
- * @public
1077
- */
1078
- pong(data, mask, cb) {
1079
- if (this.readyState === WebSocket.CONNECTING) {
1080
- throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
1081
- }
1082
-
1083
- if (typeof data === 'function') {
1084
- cb = data;
1085
- data = mask = undefined;
1086
- } else if (typeof mask === 'function') {
1087
- cb = mask;
1088
- mask = undefined;
1089
- }
1090
-
1091
- if (typeof data === 'number') data = data.toString();
1092
-
1093
- if (this.readyState !== WebSocket.OPEN) {
1094
- sendAfterClose(this, data, cb);
1095
- return;
1096
- }
1097
-
1098
- if (mask === undefined) mask = !this._isServer;
1099
- this._sender.pong(data || EMPTY_BUFFER, mask, cb);
1100
- }
1101
-
1102
- /**
1103
- * Send a data message.
1104
- *
1105
- * @param {*} data The message to send
1106
- * @param {Object} options Options object
1107
- * @param {Boolean} options.compress Specifies whether or not to compress
1108
- * `data`
1109
- * @param {Boolean} options.binary Specifies whether `data` is binary or text
1110
- * @param {Boolean} options.fin Specifies whether the fragment is the last one
1111
- * @param {Boolean} options.mask Specifies whether or not to mask `data`
1112
- * @param {Function} cb Callback which is executed when data is written out
1113
- * @public
1114
- */
1115
- send(data, options, cb) {
1116
- if (this.readyState === WebSocket.CONNECTING) {
1117
- throw new Error('WebSocket is not open: readyState 0 (CONNECTING)');
1118
- }
1119
-
1120
- if (typeof options === 'function') {
1121
- cb = options;
1122
- options = {};
1123
- }
1124
-
1125
- if (typeof data === 'number') data = data.toString();
1126
-
1127
- if (this.readyState !== WebSocket.OPEN) {
1128
- sendAfterClose(this, data, cb);
1129
- return;
1130
- }
1131
-
1132
- const opts = {
1133
- binary: typeof data !== 'string',
1134
- mask: !this._isServer,
1135
- compress: true,
1136
- fin: true,
1137
- ...options
1138
- };
1139
-
1140
- if (!this._extensions[PerMessageDeflate.extensionName]) {
1141
- opts.compress = false;
1142
- }
1143
-
1144
- this._sender.send(data || EMPTY_BUFFER, opts, cb);
1145
- }
1146
-
1147
- /**
1148
- * Forcibly close the connection.
1149
- *
1150
- * @public
1151
- */
1152
- terminate() {
1153
- if (this.readyState === WebSocket.CLOSED) return;
1154
- if (this.readyState === WebSocket.CONNECTING) {
1155
- const msg = 'WebSocket was closed before the connection was established';
1156
- return abortHandshake(this, this._req, msg);
1157
- }
1158
-
1159
- if (this._socket) {
1160
- this.readyState = WebSocket.CLOSING;
1161
- this._socket.destroy();
1162
- }
1163
- }
1164
- }
1165
-
1166
- readyStates.forEach((readyState, i) => {
1167
- WebSocket[readyState] = i;
1168
- });
1169
-
1170
- //
1171
- // Add the `onopen`, `onerror`, `onclose`, and `onmessage` attributes.
1172
- // See https://html.spec.whatwg.org/multipage/comms.html#the-websocket-interface
1173
- //
1174
- ['open', 'error', 'close', 'message'].forEach((method) => {
1175
- Object.defineProperty(WebSocket.prototype, `on${method}`, {
1176
- /**
1177
- * Return the listener of the event.
1178
- *
1179
- * @return {(Function|undefined)} The event listener or `undefined`
1180
- * @public
1181
- */
1182
- get() {
1183
- const listeners = this.listeners(method);
1184
- for (let i = 0; i < listeners.length; i++) {
1185
- if (listeners[i]._listener) return listeners[i]._listener;
1186
- }
1187
-
1188
- return undefined;
1189
- },
1190
- /**
1191
- * Add a listener for the event.
1192
- *
1193
- * @param {Function} listener The listener to add
1194
- * @public
1195
- */
1196
- set(listener) {
1197
- const listeners = this.listeners(method);
1198
- for (let i = 0; i < listeners.length; i++) {
1199
- //
1200
- // Remove only the listeners added via `addEventListener`.
1201
- //
1202
- if (listeners[i]._listener) this.removeListener(method, listeners[i]);
1203
- }
1204
- this.addEventListener(method, listener);
1205
- }
1206
- });
1207
- });
1208
-
1209
- WebSocket.prototype.addEventListener = addEventListener;
1210
- WebSocket.prototype.removeEventListener = removeEventListener;
1211
-
1212
- module.exports = WebSocket;
1213
-
1214
- /**
1215
- * Initialize a WebSocket client.
1216
- *
1217
- * @param {WebSocket} websocket The client to initialize
1218
- * @param {(String|url.URL)} address The URL to which to connect
1219
- * @param {String} protocols The subprotocols
1220
- * @param {Object} options Connection options
1221
- * @param {(Boolean|Object)} options.perMessageDeflate Enable/disable
1222
- * permessage-deflate
1223
- * @param {Number} options.handshakeTimeout Timeout in milliseconds for the
1224
- * handshake request
1225
- * @param {Number} options.protocolVersion Value of the `Sec-WebSocket-Version`
1226
- * header
1227
- * @param {String} options.origin Value of the `Origin` or
1228
- * `Sec-WebSocket-Origin` header
1229
- * @param {Number} options.maxPayload The maximum allowed message size
1230
- * @param {Boolean} options.followRedirects Whether or not to follow redirects
1231
- * @param {Number} options.maxRedirects The maximum number of redirects allowed
1232
- * @private
1233
- */
1234
- function initAsClient(websocket, address, protocols, options) {
1235
- const opts = {
1236
- protocolVersion: protocolVersions[1],
1237
- maxPayload: 100 * 1024 * 1024,
1238
- perMessageDeflate: true,
1239
- followRedirects: false,
1240
- maxRedirects: 10,
1241
- ...options,
1242
- createConnection: undefined,
1243
- socketPath: undefined,
1244
- hostname: undefined,
1245
- protocol: undefined,
1246
- timeout: undefined,
1247
- method: undefined,
1248
- auth: undefined,
1249
- host: undefined,
1250
- path: undefined,
1251
- port: undefined
1252
- };
1253
-
1254
- if (!protocolVersions.includes(opts.protocolVersion)) {
1255
- throw new RangeError(
1256
- `Unsupported protocol version: ${opts.protocolVersion} ` +
1257
- `(supported versions: ${protocolVersions.join(', ')})`
1258
- );
1259
- }
1260
-
1261
- let parsedUrl;
1262
-
1263
- if (address instanceof URL) {
1264
- parsedUrl = address;
1265
- websocket.url = address.href;
1266
- } else {
1267
- parsedUrl = new URL(address);
1268
- websocket.url = address;
1269
- }
1270
-
1271
- const isUnixSocket = parsedUrl.protocol === 'ws+unix:';
1272
-
1273
- if (!parsedUrl.host && (!isUnixSocket || !parsedUrl.pathname)) {
1274
- throw new Error(`Invalid URL: ${websocket.url}`);
1275
- }
1276
-
1277
- const isSecure =
1278
- parsedUrl.protocol === 'wss:' || parsedUrl.protocol === 'https:';
1279
- const defaultPort = isSecure ? 443 : 80;
1280
- const key = randomBytes(16).toString('base64');
1281
- const get = isSecure ? https.get : http.get;
1282
- let perMessageDeflate;
1283
-
1284
- opts.createConnection = isSecure ? tlsConnect : netConnect;
1285
- opts.defaultPort = opts.defaultPort || defaultPort;
1286
- opts.port = parsedUrl.port || defaultPort;
1287
- opts.host = parsedUrl.hostname.startsWith('[')
1288
- ? parsedUrl.hostname.slice(1, -1)
1289
- : parsedUrl.hostname;
1290
- opts.headers = {
1291
- 'Sec-WebSocket-Version': opts.protocolVersion,
1292
- 'Sec-WebSocket-Key': key,
1293
- Connection: 'Upgrade',
1294
- Upgrade: 'websocket',
1295
- ...opts.headers
1296
- };
1297
- opts.path = parsedUrl.pathname + parsedUrl.search;
1298
- opts.timeout = opts.handshakeTimeout;
1299
-
1300
- if (opts.perMessageDeflate) {
1301
- perMessageDeflate = new PerMessageDeflate(
1302
- opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
1303
- false,
1304
- opts.maxPayload
1305
- );
1306
- opts.headers['Sec-WebSocket-Extensions'] = format({
1307
- [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
1308
- });
1309
- }
1310
- if (protocols) {
1311
- opts.headers['Sec-WebSocket-Protocol'] = protocols;
1312
- }
1313
- if (opts.origin) {
1314
- if (opts.protocolVersion < 13) {
1315
- opts.headers['Sec-WebSocket-Origin'] = opts.origin;
1316
- } else {
1317
- opts.headers.Origin = opts.origin;
1318
- }
1319
- }
1320
- if (parsedUrl.username || parsedUrl.password) {
1321
- opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
1322
- }
1323
-
1324
- if (isUnixSocket) {
1325
- const parts = opts.path.split(':');
1326
-
1327
- opts.socketPath = parts[0];
1328
- opts.path = parts[1];
1329
- }
1330
-
1331
- let req = (websocket._req = get(opts));
1332
-
1333
- if (opts.timeout) {
1334
- req.on('timeout', () => {
1335
- abortHandshake(websocket, req, 'Opening handshake has timed out');
1336
- });
1337
- }
1338
-
1339
- req.on('error', (err) => {
1340
- if (websocket._req.aborted) return;
1341
-
1342
- req = websocket._req = null;
1343
- websocket.readyState = WebSocket.CLOSING;
1344
- websocket.emit('error', err);
1345
- websocket.emitClose();
1346
- });
1347
-
1348
- req.on('response', (res) => {
1349
- const location = res.headers.location;
1350
- const statusCode = res.statusCode;
1351
-
1352
- if (
1353
- location &&
1354
- opts.followRedirects &&
1355
- statusCode >= 300 &&
1356
- statusCode < 400
1357
- ) {
1358
- if (++websocket._redirects > opts.maxRedirects) {
1359
- abortHandshake(websocket, req, 'Maximum redirects exceeded');
1360
- return;
1361
- }
1362
-
1363
- req.abort();
1364
-
1365
- const addr = new URL(location, address);
1366
-
1367
- initAsClient(websocket, addr, protocols, options);
1368
- } else if (!websocket.emit('unexpected-response', req, res)) {
1369
- abortHandshake(
1370
- websocket,
1371
- req,
1372
- `Unexpected server response: ${res.statusCode}`
1373
- );
1374
- }
1375
- });
1376
-
1377
- req.on('upgrade', (res, socket, head) => {
1378
- websocket.emit('upgrade', res);
1379
-
1380
- //
1381
- // The user may have closed the connection from a listener of the `upgrade`
1382
- // event.
1383
- //
1384
- if (websocket.readyState !== WebSocket.CONNECTING) return;
1385
-
1386
- req = websocket._req = null;
1387
-
1388
- const digest = createHash('sha1')
1389
- .update(key + GUID)
1390
- .digest('base64');
1391
-
1392
- if (res.headers['sec-websocket-accept'] !== digest) {
1393
- abortHandshake(websocket, socket, 'Invalid Sec-WebSocket-Accept header');
1394
- return;
1395
- }
1396
-
1397
- const serverProt = res.headers['sec-websocket-protocol'];
1398
- const protList = (protocols || '').split(/, */);
1399
- let protError;
1400
-
1401
- if (!protocols && serverProt) {
1402
- protError = 'Server sent a subprotocol but none was requested';
1403
- } else if (protocols && !serverProt) {
1404
- protError = 'Server sent no subprotocol';
1405
- } else if (serverProt && !protList.includes(serverProt)) {
1406
- protError = 'Server sent an invalid subprotocol';
1407
- }
1408
-
1409
- if (protError) {
1410
- abortHandshake(websocket, socket, protError);
1411
- return;
1412
- }
1413
-
1414
- if (serverProt) websocket.protocol = serverProt;
1415
-
1416
- if (perMessageDeflate) {
1417
- try {
1418
- const extensions = parse(res.headers['sec-websocket-extensions']);
1419
-
1420
- if (extensions[PerMessageDeflate.extensionName]) {
1421
- perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
1422
- websocket._extensions[
1423
- PerMessageDeflate.extensionName
1424
- ] = perMessageDeflate;
1425
- }
1426
- } catch (err) {
1427
- abortHandshake(
1428
- websocket,
1429
- socket,
1430
- 'Invalid Sec-WebSocket-Extensions header'
1431
- );
1432
- return;
1433
- }
1434
- }
1435
-
1436
- websocket.setSocket(socket, head, opts.maxPayload);
1437
- });
1438
- }
1439
-
1440
- /**
1441
- * Create a `net.Socket` and initiate a connection.
1442
- *
1443
- * @param {Object} options Connection options
1444
- * @return {net.Socket} The newly created socket used to start the connection
1445
- * @private
1446
- */
1447
- function netConnect(options) {
1448
- options.path = options.socketPath;
1449
- return net.connect(options);
1450
- }
1451
-
1452
- /**
1453
- * Create a `tls.TLSSocket` and initiate a connection.
1454
- *
1455
- * @param {Object} options Connection options
1456
- * @return {tls.TLSSocket} The newly created socket used to start the connection
1457
- * @private
1458
- */
1459
- function tlsConnect(options) {
1460
- options.path = undefined;
1461
-
1462
- if (!options.servername && options.servername !== '') {
1463
- options.servername = options.host;
1464
- }
1465
-
1466
- return tls.connect(options);
1467
- }
1468
-
1469
- /**
1470
- * Abort the handshake and emit an error.
1471
- *
1472
- * @param {WebSocket} websocket The WebSocket instance
1473
- * @param {(http.ClientRequest|net.Socket)} stream The request to abort or the
1474
- * socket to destroy
1475
- * @param {String} message The error message
1476
- * @private
1477
- */
1478
- function abortHandshake(websocket, stream, message) {
1479
- websocket.readyState = WebSocket.CLOSING;
1480
-
1481
- const err = new Error(message);
1482
- Error.captureStackTrace(err, abortHandshake);
1483
-
1484
- if (stream.setHeader) {
1485
- stream.abort();
1486
- stream.once('abort', websocket.emitClose.bind(websocket));
1487
- websocket.emit('error', err);
1488
- } else {
1489
- stream.destroy(err);
1490
- stream.once('error', websocket.emit.bind(websocket, 'error'));
1491
- stream.once('close', websocket.emitClose.bind(websocket));
1492
- }
1493
- }
1494
-
1495
- /**
1496
- * Handle cases where the `ping()`, `pong()`, or `send()` methods are called
1497
- * when the `readyState` attribute is `CLOSING` or `CLOSED`.
1498
- *
1499
- * @param {WebSocket} websocket The WebSocket instance
1500
- * @param {*} data The data to send
1501
- * @param {Function} cb Callback
1502
- * @private
1503
- */
1504
- function sendAfterClose(websocket, data, cb) {
1505
- if (data) {
1506
- const length = toBuffer(data).length;
1507
-
1508
- //
1509
- // The `_bufferedAmount` property is used only when the peer is a client and
1510
- // the opening handshake fails. Under these circumstances, in fact, the
1511
- // `setSocket()` method is not called, so the `_socket` and `_sender`
1512
- // properties are set to `null`.
1513
- //
1514
- if (websocket._socket) websocket._sender._bufferedBytes += length;
1515
- else websocket._bufferedAmount += length;
1516
- }
1517
-
1518
- if (cb) {
1519
- const err = new Error(
1520
- `WebSocket is not open: readyState ${websocket.readyState} ` +
1521
- `(${readyStates[websocket.readyState]})`
1522
- );
1523
- cb(err);
1524
- }
1525
- }
1526
-
1527
- /**
1528
- * The listener of the `Receiver` `'conclude'` event.
1529
- *
1530
- * @param {Number} code The status code
1531
- * @param {String} reason The reason for closing
1532
- * @private
1533
- */
1534
- function receiverOnConclude(code, reason) {
1535
- const websocket = this[kWebSocket];
1536
-
1537
- websocket._socket.removeListener('data', socketOnData);
1538
- websocket._socket.resume();
1539
-
1540
- websocket._closeFrameReceived = true;
1541
- websocket._closeMessage = reason;
1542
- websocket._closeCode = code;
1543
-
1544
- if (code === 1005) websocket.close();
1545
- else websocket.close(code, reason);
1546
- }
1547
-
1548
- /**
1549
- * The listener of the `Receiver` `'drain'` event.
1550
- *
1551
- * @private
1552
- */
1553
- function receiverOnDrain() {
1554
- this[kWebSocket]._socket.resume();
1555
- }
1556
-
1557
- /**
1558
- * The listener of the `Receiver` `'error'` event.
1559
- *
1560
- * @param {(RangeError|Error)} err The emitted error
1561
- * @private
1562
- */
1563
- function receiverOnError(err) {
1564
- const websocket = this[kWebSocket];
1565
-
1566
- websocket._socket.removeListener('data', socketOnData);
1567
-
1568
- websocket.readyState = WebSocket.CLOSING;
1569
- websocket._closeCode = err[kStatusCode];
1570
- websocket.emit('error', err);
1571
- websocket._socket.destroy();
1572
- }
1573
-
1574
- /**
1575
- * The listener of the `Receiver` `'finish'` event.
1576
- *
1577
- * @private
1578
- */
1579
- function receiverOnFinish() {
1580
- this[kWebSocket].emitClose();
1581
- }
1582
-
1583
- /**
1584
- * The listener of the `Receiver` `'message'` event.
1585
- *
1586
- * @param {(String|Buffer|ArrayBuffer|Buffer[])} data The message
1587
- * @private
1588
- */
1589
- function receiverOnMessage(data) {
1590
- this[kWebSocket].emit('message', data);
1591
- }
1592
-
1593
- /**
1594
- * The listener of the `Receiver` `'ping'` event.
1595
- *
1596
- * @param {Buffer} data The data included in the ping frame
1597
- * @private
1598
- */
1599
- function receiverOnPing(data) {
1600
- const websocket = this[kWebSocket];
1601
-
1602
- websocket.pong(data, !websocket._isServer, NOOP);
1603
- websocket.emit('ping', data);
1604
- }
1605
-
1606
- /**
1607
- * The listener of the `Receiver` `'pong'` event.
1608
- *
1609
- * @param {Buffer} data The data included in the pong frame
1610
- * @private
1611
- */
1612
- function receiverOnPong(data) {
1613
- this[kWebSocket].emit('pong', data);
1614
- }
1615
-
1616
- /**
1617
- * The listener of the `net.Socket` `'close'` event.
1618
- *
1619
- * @private
1620
- */
1621
- function socketOnClose() {
1622
- const websocket = this[kWebSocket];
1623
-
1624
- this.removeListener('close', socketOnClose);
1625
- this.removeListener('end', socketOnEnd);
1626
-
1627
- websocket.readyState = WebSocket.CLOSING;
1628
-
1629
- //
1630
- // The close frame might not have been received or the `'end'` event emitted,
1631
- // for example, if the socket was destroyed due to an error. Ensure that the
1632
- // `receiver` stream is closed after writing any remaining buffered data to
1633
- // it. If the readable side of the socket is in flowing mode then there is no
1634
- // buffered data as everything has been already written and `readable.read()`
1635
- // will return `null`. If instead, the socket is paused, any possible buffered
1636
- // data will be read as a single chunk and emitted synchronously in a single
1637
- // `'data'` event.
1638
- //
1639
- websocket._socket.read();
1640
- websocket._receiver.end();
1641
-
1642
- this.removeListener('data', socketOnData);
1643
- this[kWebSocket] = undefined;
1644
-
1645
- clearTimeout(websocket._closeTimer);
1646
-
1647
- if (
1648
- websocket._receiver._writableState.finished ||
1649
- websocket._receiver._writableState.errorEmitted
1650
- ) {
1651
- websocket.emitClose();
1652
- } else {
1653
- websocket._receiver.on('error', receiverOnFinish);
1654
- websocket._receiver.on('finish', receiverOnFinish);
1655
- }
1656
- }
1657
-
1658
- /**
1659
- * The listener of the `net.Socket` `'data'` event.
1660
- *
1661
- * @param {Buffer} chunk A chunk of data
1662
- * @private
1663
- */
1664
- function socketOnData(chunk) {
1665
- if (!this[kWebSocket]._receiver.write(chunk)) {
1666
- this.pause();
1667
- }
1668
- }
1669
-
1670
- /**
1671
- * The listener of the `net.Socket` `'end'` event.
1672
- *
1673
- * @private
1674
- */
1675
- function socketOnEnd() {
1676
- const websocket = this[kWebSocket];
1677
-
1678
- websocket.readyState = WebSocket.CLOSING;
1679
- websocket._receiver.end();
1680
- this.end();
1681
- }
1682
-
1683
- /**
1684
- * The listener of the `net.Socket` `'error'` event.
1685
- *
1686
- * @private
1687
- */
1688
- function socketOnError() {
1689
- const websocket = this[kWebSocket];
1690
-
1691
- this.removeListener('error', socketOnError);
1692
- this.on('error', NOOP);
1693
-
1694
- if (websocket) {
1695
- websocket.readyState = WebSocket.CLOSING;
1696
- this.destroy();
1697
- }
1698
- }
1699
-
1700
-
1701
- /***/ }),
1702
- /* 5 */
1703
- /***/ (function(module, exports) {
1704
-
1705
- module.exports = require("events");
1706
-
1707
- /***/ }),
1708
- /* 6 */
1709
- /***/ (function(module, exports) {
1710
-
1711
- module.exports = require("http");
1712
-
1713
- /***/ }),
1714
- /* 7 */
1715
- /***/ (function(module, exports, __webpack_require__) {
1716
-
1717
- "use strict";
1718
-
1719
-
1720
- const { Writable } = __webpack_require__(8);
1721
-
1722
- const PerMessageDeflate = __webpack_require__(1);
1723
- const {
1724
- BINARY_TYPES,
1725
- EMPTY_BUFFER,
1726
- kStatusCode,
1727
- kWebSocket
1728
- } = __webpack_require__(0);
1729
- const { concat, toArrayBuffer, unmask } = __webpack_require__(2);
1730
- const { isValidStatusCode, isValidUTF8 } = __webpack_require__(9);
1731
-
1732
- const GET_INFO = 0;
1733
- const GET_PAYLOAD_LENGTH_16 = 1;
1734
- const GET_PAYLOAD_LENGTH_64 = 2;
1735
- const GET_MASK = 3;
1736
- const GET_DATA = 4;
1737
- const INFLATING = 5;
1738
-
1739
- /**
1740
- * HyBi Receiver implementation.
1741
- *
1742
- * @extends stream.Writable
1743
- */
1744
- class Receiver extends Writable {
1745
- /**
1746
- * Creates a Receiver instance.
1747
- *
1748
- * @param {String} binaryType The type for binary data
1749
- * @param {Object} extensions An object containing the negotiated extensions
1750
- * @param {Number} maxPayload The maximum allowed message length
1751
- */
1752
- constructor(binaryType, extensions, maxPayload) {
1753
- super();
1754
-
1755
- this._binaryType = binaryType || BINARY_TYPES[0];
1756
- this[kWebSocket] = undefined;
1757
- this._extensions = extensions || {};
1758
- this._maxPayload = maxPayload | 0;
1759
-
1760
- this._bufferedBytes = 0;
1761
- this._buffers = [];
1762
-
1763
- this._compressed = false;
1764
- this._payloadLength = 0;
1765
- this._mask = undefined;
1766
- this._fragmented = 0;
1767
- this._masked = false;
1768
- this._fin = false;
1769
- this._opcode = 0;
1770
-
1771
- this._totalPayloadLength = 0;
1772
- this._messageLength = 0;
1773
- this._fragments = [];
1774
-
1775
- this._state = GET_INFO;
1776
- this._loop = false;
1777
- }
1778
-
1779
- /**
1780
- * Implements `Writable.prototype._write()`.
1781
- *
1782
- * @param {Buffer} chunk The chunk of data to write
1783
- * @param {String} encoding The character encoding of `chunk`
1784
- * @param {Function} cb Callback
1785
- */
1786
- _write(chunk, encoding, cb) {
1787
- if (this._opcode === 0x08 && this._state == GET_INFO) return cb();
1788
-
1789
- this._bufferedBytes += chunk.length;
1790
- this._buffers.push(chunk);
1791
- this.startLoop(cb);
1792
- }
1793
-
1794
- /**
1795
- * Consumes `n` bytes from the buffered data.
1796
- *
1797
- * @param {Number} n The number of bytes to consume
1798
- * @return {Buffer} The consumed bytes
1799
- * @private
1800
- */
1801
- consume(n) {
1802
- this._bufferedBytes -= n;
1803
-
1804
- if (n === this._buffers[0].length) return this._buffers.shift();
1805
-
1806
- if (n < this._buffers[0].length) {
1807
- const buf = this._buffers[0];
1808
- this._buffers[0] = buf.slice(n);
1809
- return buf.slice(0, n);
1810
- }
1811
-
1812
- const dst = Buffer.allocUnsafe(n);
1813
-
1814
- do {
1815
- const buf = this._buffers[0];
1816
-
1817
- if (n >= buf.length) {
1818
- this._buffers.shift().copy(dst, dst.length - n);
1819
- } else {
1820
- buf.copy(dst, dst.length - n, 0, n);
1821
- this._buffers[0] = buf.slice(n);
1822
- }
1823
-
1824
- n -= buf.length;
1825
- } while (n > 0);
1826
-
1827
- return dst;
1828
- }
1829
-
1830
- /**
1831
- * Starts the parsing loop.
1832
- *
1833
- * @param {Function} cb Callback
1834
- * @private
1835
- */
1836
- startLoop(cb) {
1837
- let err;
1838
- this._loop = true;
1839
-
1840
- do {
1841
- switch (this._state) {
1842
- case GET_INFO:
1843
- err = this.getInfo();
1844
- break;
1845
- case GET_PAYLOAD_LENGTH_16:
1846
- err = this.getPayloadLength16();
1847
- break;
1848
- case GET_PAYLOAD_LENGTH_64:
1849
- err = this.getPayloadLength64();
1850
- break;
1851
- case GET_MASK:
1852
- this.getMask();
1853
- break;
1854
- case GET_DATA:
1855
- err = this.getData(cb);
1856
- break;
1857
- default:
1858
- // `INFLATING`
1859
- this._loop = false;
1860
- return;
1861
- }
1862
- } while (this._loop);
1863
-
1864
- cb(err);
1865
- }
1866
-
1867
- /**
1868
- * Reads the first two bytes of a frame.
1869
- *
1870
- * @return {(RangeError|undefined)} A possible error
1871
- * @private
1872
- */
1873
- getInfo() {
1874
- if (this._bufferedBytes < 2) {
1875
- this._loop = false;
1876
- return;
1877
- }
1878
-
1879
- const buf = this.consume(2);
1880
-
1881
- if ((buf[0] & 0x30) !== 0x00) {
1882
- this._loop = false;
1883
- return error(RangeError, 'RSV2 and RSV3 must be clear', true, 1002);
1884
- }
1885
-
1886
- const compressed = (buf[0] & 0x40) === 0x40;
1887
-
1888
- if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
1889
- this._loop = false;
1890
- return error(RangeError, 'RSV1 must be clear', true, 1002);
1891
- }
1892
-
1893
- this._fin = (buf[0] & 0x80) === 0x80;
1894
- this._opcode = buf[0] & 0x0f;
1895
- this._payloadLength = buf[1] & 0x7f;
1896
-
1897
- if (this._opcode === 0x00) {
1898
- if (compressed) {
1899
- this._loop = false;
1900
- return error(RangeError, 'RSV1 must be clear', true, 1002);
1901
- }
1902
-
1903
- if (!this._fragmented) {
1904
- this._loop = false;
1905
- return error(RangeError, 'invalid opcode 0', true, 1002);
1906
- }
1907
-
1908
- this._opcode = this._fragmented;
1909
- } else if (this._opcode === 0x01 || this._opcode === 0x02) {
1910
- if (this._fragmented) {
1911
- this._loop = false;
1912
- return error(RangeError, `invalid opcode ${this._opcode}`, true, 1002);
1913
- }
1914
-
1915
- this._compressed = compressed;
1916
- } else if (this._opcode > 0x07 && this._opcode < 0x0b) {
1917
- if (!this._fin) {
1918
- this._loop = false;
1919
- return error(RangeError, 'FIN must be set', true, 1002);
1920
- }
1921
-
1922
- if (compressed) {
1923
- this._loop = false;
1924
- return error(RangeError, 'RSV1 must be clear', true, 1002);
1925
- }
1926
-
1927
- if (this._payloadLength > 0x7d) {
1928
- this._loop = false;
1929
- return error(
1930
- RangeError,
1931
- `invalid payload length ${this._payloadLength}`,
1932
- true,
1933
- 1002
1934
- );
1935
- }
1936
- } else {
1937
- this._loop = false;
1938
- return error(RangeError, `invalid opcode ${this._opcode}`, true, 1002);
1939
- }
1940
-
1941
- if (!this._fin && !this._fragmented) this._fragmented = this._opcode;
1942
- this._masked = (buf[1] & 0x80) === 0x80;
1943
-
1944
- if (this._payloadLength === 126) this._state = GET_PAYLOAD_LENGTH_16;
1945
- else if (this._payloadLength === 127) this._state = GET_PAYLOAD_LENGTH_64;
1946
- else return this.haveLength();
1947
- }
1948
-
1949
- /**
1950
- * Gets extended payload length (7+16).
1951
- *
1952
- * @return {(RangeError|undefined)} A possible error
1953
- * @private
1954
- */
1955
- getPayloadLength16() {
1956
- if (this._bufferedBytes < 2) {
1957
- this._loop = false;
1958
- return;
1959
- }
1960
-
1961
- this._payloadLength = this.consume(2).readUInt16BE(0);
1962
- return this.haveLength();
1963
- }
1964
-
1965
- /**
1966
- * Gets extended payload length (7+64).
1967
- *
1968
- * @return {(RangeError|undefined)} A possible error
1969
- * @private
1970
- */
1971
- getPayloadLength64() {
1972
- if (this._bufferedBytes < 8) {
1973
- this._loop = false;
1974
- return;
1975
- }
1976
-
1977
- const buf = this.consume(8);
1978
- const num = buf.readUInt32BE(0);
1979
-
1980
- //
1981
- // The maximum safe integer in JavaScript is 2^53 - 1. An error is returned
1982
- // if payload length is greater than this number.
1983
- //
1984
- if (num > Math.pow(2, 53 - 32) - 1) {
1985
- this._loop = false;
1986
- return error(
1987
- RangeError,
1988
- 'Unsupported WebSocket frame: payload length > 2^53 - 1',
1989
- false,
1990
- 1009
1991
- );
1992
- }
1993
-
1994
- this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
1995
- return this.haveLength();
1996
- }
1997
-
1998
- /**
1999
- * Payload length has been read.
2000
- *
2001
- * @return {(RangeError|undefined)} A possible error
2002
- * @private
2003
- */
2004
- haveLength() {
2005
- if (this._payloadLength && this._opcode < 0x08) {
2006
- this._totalPayloadLength += this._payloadLength;
2007
- if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
2008
- this._loop = false;
2009
- return error(RangeError, 'Max payload size exceeded', false, 1009);
2010
- }
2011
- }
2012
-
2013
- if (this._masked) this._state = GET_MASK;
2014
- else this._state = GET_DATA;
2015
- }
2016
-
2017
- /**
2018
- * Reads mask bytes.
2019
- *
2020
- * @private
2021
- */
2022
- getMask() {
2023
- if (this._bufferedBytes < 4) {
2024
- this._loop = false;
2025
- return;
2026
- }
2027
-
2028
- this._mask = this.consume(4);
2029
- this._state = GET_DATA;
2030
- }
2031
-
2032
- /**
2033
- * Reads data bytes.
2034
- *
2035
- * @param {Function} cb Callback
2036
- * @return {(Error|RangeError|undefined)} A possible error
2037
- * @private
2038
- */
2039
- getData(cb) {
2040
- let data = EMPTY_BUFFER;
2041
-
2042
- if (this._payloadLength) {
2043
- if (this._bufferedBytes < this._payloadLength) {
2044
- this._loop = false;
2045
- return;
2046
- }
2047
-
2048
- data = this.consume(this._payloadLength);
2049
- if (this._masked) unmask(data, this._mask);
2050
- }
2051
-
2052
- if (this._opcode > 0x07) return this.controlMessage(data);
2053
-
2054
- if (this._compressed) {
2055
- this._state = INFLATING;
2056
- this.decompress(data, cb);
2057
- return;
2058
- }
2059
-
2060
- if (data.length) {
2061
- //
2062
- // This message is not compressed so its lenght is the sum of the payload
2063
- // length of all fragments.
2064
- //
2065
- this._messageLength = this._totalPayloadLength;
2066
- this._fragments.push(data);
2067
- }
2068
-
2069
- return this.dataMessage();
2070
- }
2071
-
2072
- /**
2073
- * Decompresses data.
2074
- *
2075
- * @param {Buffer} data Compressed data
2076
- * @param {Function} cb Callback
2077
- * @private
2078
- */
2079
- decompress(data, cb) {
2080
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
2081
-
2082
- perMessageDeflate.decompress(data, this._fin, (err, buf) => {
2083
- if (err) return cb(err);
2084
-
2085
- if (buf.length) {
2086
- this._messageLength += buf.length;
2087
- if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
2088
- return cb(
2089
- error(RangeError, 'Max payload size exceeded', false, 1009)
2090
- );
2091
- }
2092
-
2093
- this._fragments.push(buf);
2094
- }
2095
-
2096
- const er = this.dataMessage();
2097
- if (er) return cb(er);
2098
-
2099
- this.startLoop(cb);
2100
- });
2101
- }
2102
-
2103
- /**
2104
- * Handles a data message.
2105
- *
2106
- * @return {(Error|undefined)} A possible error
2107
- * @private
2108
- */
2109
- dataMessage() {
2110
- if (this._fin) {
2111
- const messageLength = this._messageLength;
2112
- const fragments = this._fragments;
2113
-
2114
- this._totalPayloadLength = 0;
2115
- this._messageLength = 0;
2116
- this._fragmented = 0;
2117
- this._fragments = [];
2118
-
2119
- if (this._opcode === 2) {
2120
- let data;
2121
-
2122
- if (this._binaryType === 'nodebuffer') {
2123
- data = concat(fragments, messageLength);
2124
- } else if (this._binaryType === 'arraybuffer') {
2125
- data = toArrayBuffer(concat(fragments, messageLength));
2126
- } else {
2127
- data = fragments;
2128
- }
2129
-
2130
- this.emit('message', data);
2131
- } else {
2132
- const buf = concat(fragments, messageLength);
2133
-
2134
- if (!isValidUTF8(buf)) {
2135
- this._loop = false;
2136
- return error(Error, 'invalid UTF-8 sequence', true, 1007);
2137
- }
2138
-
2139
- this.emit('message', buf.toString());
2140
- }
2141
- }
2142
-
2143
- this._state = GET_INFO;
2144
- }
2145
-
2146
- /**
2147
- * Handles a control message.
2148
- *
2149
- * @param {Buffer} data Data to handle
2150
- * @return {(Error|RangeError|undefined)} A possible error
2151
- * @private
2152
- */
2153
- controlMessage(data) {
2154
- if (this._opcode === 0x08) {
2155
- this._loop = false;
2156
-
2157
- if (data.length === 0) {
2158
- this.emit('conclude', 1005, '');
2159
- this.end();
2160
- } else if (data.length === 1) {
2161
- return error(RangeError, 'invalid payload length 1', true, 1002);
2162
- } else {
2163
- const code = data.readUInt16BE(0);
2164
-
2165
- if (!isValidStatusCode(code)) {
2166
- return error(RangeError, `invalid status code ${code}`, true, 1002);
2167
- }
2168
-
2169
- const buf = data.slice(2);
2170
-
2171
- if (!isValidUTF8(buf)) {
2172
- return error(Error, 'invalid UTF-8 sequence', true, 1007);
2173
- }
2174
-
2175
- this.emit('conclude', code, buf.toString());
2176
- this.end();
2177
- }
2178
- } else if (this._opcode === 0x09) {
2179
- this.emit('ping', data);
2180
- } else {
2181
- this.emit('pong', data);
2182
- }
2183
-
2184
- this._state = GET_INFO;
2185
- }
2186
- }
2187
-
2188
- module.exports = Receiver;
2189
-
2190
- /**
2191
- * Builds an error object.
2192
- *
2193
- * @param {(Error|RangeError)} ErrorCtor The error constructor
2194
- * @param {String} message The error message
2195
- * @param {Boolean} prefix Specifies whether or not to add a default prefix to
2196
- * `message`
2197
- * @param {Number} statusCode The status code
2198
- * @return {(Error|RangeError)} The error
2199
- * @private
2200
- */
2201
- function error(ErrorCtor, message, prefix, statusCode) {
2202
- const err = new ErrorCtor(
2203
- prefix ? `Invalid WebSocket frame: ${message}` : message
2204
- );
2205
-
2206
- Error.captureStackTrace(err, error);
2207
- err[kStatusCode] = statusCode;
2208
- return err;
2209
- }
2210
-
2211
-
2212
- /***/ }),
2213
- /* 8 */
2214
- /***/ (function(module, exports) {
2215
-
2216
- module.exports = require("stream");
2217
-
2218
- /***/ }),
2219
- /* 9 */
2220
- /***/ (function(module, exports, __webpack_require__) {
2221
-
2222
- "use strict";
2223
-
2224
-
2225
- try {
2226
- const isValidUTF8 = __webpack_require__(!(function webpackMissingModule() { var e = new Error("Cannot find module 'utf-8-validate'"); e.code = 'MODULE_NOT_FOUND'; throw e; }()));
2227
-
2228
- exports.isValidUTF8 =
2229
- typeof isValidUTF8 === 'object'
2230
- ? isValidUTF8.Validation.isValidUTF8 // utf-8-validate@<3.0.0
2231
- : isValidUTF8;
2232
- } catch (e) /* istanbul ignore next */ {
2233
- exports.isValidUTF8 = () => true;
2234
- }
2235
-
2236
- /**
2237
- * Checks if a status code is allowed in a close frame.
2238
- *
2239
- * @param {Number} code The status code
2240
- * @return {Boolean} `true` if the status code is valid, else `false`
2241
- * @public
2242
- */
2243
- exports.isValidStatusCode = (code) => {
2244
- return (
2245
- (code >= 1000 &&
2246
- code <= 1013 &&
2247
- code !== 1004 &&
2248
- code !== 1005 &&
2249
- code !== 1006) ||
2250
- (code >= 3000 && code <= 4999)
2251
- );
2252
- };
2253
-
2254
-
2255
- /***/ }),
2256
- /* 10 */
2257
- /***/ (function(module, exports, __webpack_require__) {
2258
-
2259
- "use strict";
2260
-
2261
-
2262
- const { randomFillSync } = __webpack_require__(3);
2263
-
2264
- const PerMessageDeflate = __webpack_require__(1);
2265
- const { EMPTY_BUFFER } = __webpack_require__(0);
2266
- const { isValidStatusCode } = __webpack_require__(9);
2267
- const { mask: applyMask, toBuffer } = __webpack_require__(2);
2268
-
2269
- const mask = Buffer.alloc(4);
2270
-
2271
- /**
2272
- * HyBi Sender implementation.
2273
- */
2274
- class Sender {
2275
- /**
2276
- * Creates a Sender instance.
2277
- *
2278
- * @param {net.Socket} socket The connection socket
2279
- * @param {Object} extensions An object containing the negotiated extensions
2280
- */
2281
- constructor(socket, extensions) {
2282
- this._extensions = extensions || {};
2283
- this._socket = socket;
2284
-
2285
- this._firstFragment = true;
2286
- this._compress = false;
2287
-
2288
- this._bufferedBytes = 0;
2289
- this._deflating = false;
2290
- this._queue = [];
2291
- }
2292
-
2293
- /**
2294
- * Frames a piece of data according to the HyBi WebSocket protocol.
2295
- *
2296
- * @param {Buffer} data The data to frame
2297
- * @param {Object} options Options object
2298
- * @param {Number} options.opcode The opcode
2299
- * @param {Boolean} options.readOnly Specifies whether `data` can be modified
2300
- * @param {Boolean} options.fin Specifies whether or not to set the FIN bit
2301
- * @param {Boolean} options.mask Specifies whether or not to mask `data`
2302
- * @param {Boolean} options.rsv1 Specifies whether or not to set the RSV1 bit
2303
- * @return {Buffer[]} The framed data as a list of `Buffer` instances
2304
- * @public
2305
- */
2306
- static frame(data, options) {
2307
- const merge = options.mask && options.readOnly;
2308
- let offset = options.mask ? 6 : 2;
2309
- let payloadLength = data.length;
2310
-
2311
- if (data.length >= 65536) {
2312
- offset += 8;
2313
- payloadLength = 127;
2314
- } else if (data.length > 125) {
2315
- offset += 2;
2316
- payloadLength = 126;
2317
- }
2318
-
2319
- const target = Buffer.allocUnsafe(merge ? data.length + offset : offset);
2320
-
2321
- target[0] = options.fin ? options.opcode | 0x80 : options.opcode;
2322
- if (options.rsv1) target[0] |= 0x40;
2323
-
2324
- target[1] = payloadLength;
2325
-
2326
- if (payloadLength === 126) {
2327
- target.writeUInt16BE(data.length, 2);
2328
- } else if (payloadLength === 127) {
2329
- target.writeUInt32BE(0, 2);
2330
- target.writeUInt32BE(data.length, 6);
2331
- }
2332
-
2333
- if (!options.mask) return [target, data];
2334
-
2335
- randomFillSync(mask, 0, 4);
2336
-
2337
- target[1] |= 0x80;
2338
- target[offset - 4] = mask[0];
2339
- target[offset - 3] = mask[1];
2340
- target[offset - 2] = mask[2];
2341
- target[offset - 1] = mask[3];
2342
-
2343
- if (merge) {
2344
- applyMask(data, mask, target, offset, data.length);
2345
- return [target];
2346
- }
2347
-
2348
- applyMask(data, mask, data, 0, data.length);
2349
- return [target, data];
2350
- }
2351
-
2352
- /**
2353
- * Sends a close message to the other peer.
2354
- *
2355
- * @param {(Number|undefined)} code The status code component of the body
2356
- * @param {String} data The message component of the body
2357
- * @param {Boolean} mask Specifies whether or not to mask the message
2358
- * @param {Function} cb Callback
2359
- * @public
2360
- */
2361
- close(code, data, mask, cb) {
2362
- let buf;
2363
-
2364
- if (code === undefined) {
2365
- buf = EMPTY_BUFFER;
2366
- } else if (typeof code !== 'number' || !isValidStatusCode(code)) {
2367
- throw new TypeError('First argument must be a valid error code number');
2368
- } else if (data === undefined || data === '') {
2369
- buf = Buffer.allocUnsafe(2);
2370
- buf.writeUInt16BE(code, 0);
2371
- } else {
2372
- buf = Buffer.allocUnsafe(2 + Buffer.byteLength(data));
2373
- buf.writeUInt16BE(code, 0);
2374
- buf.write(data, 2);
2375
- }
2376
-
2377
- if (this._deflating) {
2378
- this.enqueue([this.doClose, buf, mask, cb]);
2379
- } else {
2380
- this.doClose(buf, mask, cb);
2381
- }
2382
- }
2383
-
2384
- /**
2385
- * Frames and sends a close message.
2386
- *
2387
- * @param {Buffer} data The message to send
2388
- * @param {Boolean} mask Specifies whether or not to mask `data`
2389
- * @param {Function} cb Callback
2390
- * @private
2391
- */
2392
- doClose(data, mask, cb) {
2393
- this.sendFrame(
2394
- Sender.frame(data, {
2395
- fin: true,
2396
- rsv1: false,
2397
- opcode: 0x08,
2398
- mask,
2399
- readOnly: false
2400
- }),
2401
- cb
2402
- );
2403
- }
2404
-
2405
- /**
2406
- * Sends a ping message to the other peer.
2407
- *
2408
- * @param {*} data The message to send
2409
- * @param {Boolean} mask Specifies whether or not to mask `data`
2410
- * @param {Function} cb Callback
2411
- * @public
2412
- */
2413
- ping(data, mask, cb) {
2414
- const buf = toBuffer(data);
2415
-
2416
- if (this._deflating) {
2417
- this.enqueue([this.doPing, buf, mask, toBuffer.readOnly, cb]);
2418
- } else {
2419
- this.doPing(buf, mask, toBuffer.readOnly, cb);
2420
- }
2421
- }
2422
-
2423
- /**
2424
- * Frames and sends a ping message.
2425
- *
2426
- * @param {*} data The message to send
2427
- * @param {Boolean} mask Specifies whether or not to mask `data`
2428
- * @param {Boolean} readOnly Specifies whether `data` can be modified
2429
- * @param {Function} cb Callback
2430
- * @private
2431
- */
2432
- doPing(data, mask, readOnly, cb) {
2433
- this.sendFrame(
2434
- Sender.frame(data, {
2435
- fin: true,
2436
- rsv1: false,
2437
- opcode: 0x09,
2438
- mask,
2439
- readOnly
2440
- }),
2441
- cb
2442
- );
2443
- }
2444
-
2445
- /**
2446
- * Sends a pong message to the other peer.
2447
- *
2448
- * @param {*} data The message to send
2449
- * @param {Boolean} mask Specifies whether or not to mask `data`
2450
- * @param {Function} cb Callback
2451
- * @public
2452
- */
2453
- pong(data, mask, cb) {
2454
- const buf = toBuffer(data);
2455
-
2456
- if (this._deflating) {
2457
- this.enqueue([this.doPong, buf, mask, toBuffer.readOnly, cb]);
2458
- } else {
2459
- this.doPong(buf, mask, toBuffer.readOnly, cb);
2460
- }
2461
- }
2462
-
2463
- /**
2464
- * Frames and sends a pong message.
2465
- *
2466
- * @param {*} data The message to send
2467
- * @param {Boolean} mask Specifies whether or not to mask `data`
2468
- * @param {Boolean} readOnly Specifies whether `data` can be modified
2469
- * @param {Function} cb Callback
2470
- * @private
2471
- */
2472
- doPong(data, mask, readOnly, cb) {
2473
- this.sendFrame(
2474
- Sender.frame(data, {
2475
- fin: true,
2476
- rsv1: false,
2477
- opcode: 0x0a,
2478
- mask,
2479
- readOnly
2480
- }),
2481
- cb
2482
- );
2483
- }
2484
-
2485
- /**
2486
- * Sends a data message to the other peer.
2487
- *
2488
- * @param {*} data The message to send
2489
- * @param {Object} options Options object
2490
- * @param {Boolean} options.compress Specifies whether or not to compress `data`
2491
- * @param {Boolean} options.binary Specifies whether `data` is binary or text
2492
- * @param {Boolean} options.fin Specifies whether the fragment is the last one
2493
- * @param {Boolean} options.mask Specifies whether or not to mask `data`
2494
- * @param {Function} cb Callback
2495
- * @public
2496
- */
2497
- send(data, options, cb) {
2498
- const buf = toBuffer(data);
2499
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
2500
- let opcode = options.binary ? 2 : 1;
2501
- let rsv1 = options.compress;
2502
-
2503
- if (this._firstFragment) {
2504
- this._firstFragment = false;
2505
- if (rsv1 && perMessageDeflate) {
2506
- rsv1 = buf.length >= perMessageDeflate._threshold;
2507
- }
2508
- this._compress = rsv1;
2509
- } else {
2510
- rsv1 = false;
2511
- opcode = 0;
2512
- }
2513
-
2514
- if (options.fin) this._firstFragment = true;
2515
-
2516
- if (perMessageDeflate) {
2517
- const opts = {
2518
- fin: options.fin,
2519
- rsv1,
2520
- opcode,
2521
- mask: options.mask,
2522
- readOnly: toBuffer.readOnly
2523
- };
2524
-
2525
- if (this._deflating) {
2526
- this.enqueue([this.dispatch, buf, this._compress, opts, cb]);
2527
- } else {
2528
- this.dispatch(buf, this._compress, opts, cb);
2529
- }
2530
- } else {
2531
- this.sendFrame(
2532
- Sender.frame(buf, {
2533
- fin: options.fin,
2534
- rsv1: false,
2535
- opcode,
2536
- mask: options.mask,
2537
- readOnly: toBuffer.readOnly
2538
- }),
2539
- cb
2540
- );
2541
- }
2542
- }
2543
-
2544
- /**
2545
- * Dispatches a data message.
2546
- *
2547
- * @param {Buffer} data The message to send
2548
- * @param {Boolean} compress Specifies whether or not to compress `data`
2549
- * @param {Object} options Options object
2550
- * @param {Number} options.opcode The opcode
2551
- * @param {Boolean} options.readOnly Specifies whether `data` can be modified
2552
- * @param {Boolean} options.fin Specifies whether or not to set the FIN bit
2553
- * @param {Boolean} options.mask Specifies whether or not to mask `data`
2554
- * @param {Boolean} options.rsv1 Specifies whether or not to set the RSV1 bit
2555
- * @param {Function} cb Callback
2556
- * @private
2557
- */
2558
- dispatch(data, compress, options, cb) {
2559
- if (!compress) {
2560
- this.sendFrame(Sender.frame(data, options), cb);
2561
- return;
2562
- }
2563
-
2564
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
2565
-
2566
- this._deflating = true;
2567
- perMessageDeflate.compress(data, options.fin, (_, buf) => {
2568
- this._deflating = false;
2569
- options.readOnly = false;
2570
- this.sendFrame(Sender.frame(buf, options), cb);
2571
- this.dequeue();
2572
- });
2573
- }
2574
-
2575
- /**
2576
- * Executes queued send operations.
2577
- *
2578
- * @private
2579
- */
2580
- dequeue() {
2581
- while (!this._deflating && this._queue.length) {
2582
- const params = this._queue.shift();
2583
-
2584
- this._bufferedBytes -= params[1].length;
2585
- Reflect.apply(params[0], this, params.slice(1));
2586
- }
2587
- }
2588
-
2589
- /**
2590
- * Enqueues a send operation.
2591
- *
2592
- * @param {Array} params Send operation parameters.
2593
- * @private
2594
- */
2595
- enqueue(params) {
2596
- this._bufferedBytes += params[1].length;
2597
- this._queue.push(params);
2598
- }
2599
-
2600
- /**
2601
- * Sends a frame.
2602
- *
2603
- * @param {Buffer[]} list The frame to send
2604
- * @param {Function} cb Callback
2605
- * @private
2606
- */
2607
- sendFrame(list, cb) {
2608
- if (list.length === 2) {
2609
- this._socket.cork();
2610
- this._socket.write(list[0]);
2611
- this._socket.write(list[1], cb);
2612
- this._socket.uncork();
2613
- } else {
2614
- this._socket.write(list[0], cb);
2615
- }
2616
- }
2617
- }
2618
-
2619
- module.exports = Sender;
2620
-
2621
-
2622
- /***/ }),
2623
- /* 11 */
2624
- /***/ (function(module, exports, __webpack_require__) {
2625
-
2626
- "use strict";
2627
-
2628
-
2629
- //
2630
- // Allowed token characters:
2631
- //
2632
- // '!', '#', '$', '%', '&', ''', '*', '+', '-',
2633
- // '.', 0-9, A-Z, '^', '_', '`', a-z, '|', '~'
2634
- //
2635
- // tokenChars[32] === 0 // ' '
2636
- // tokenChars[33] === 1 // '!'
2637
- // tokenChars[34] === 0 // '"'
2638
- // ...
2639
- //
2640
- // prettier-ignore
2641
- const tokenChars = [
2642
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15
2643
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31
2644
- 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, // 32 - 47
2645
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 48 - 63
2646
- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 79
2647
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, // 80 - 95
2648
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111
2649
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0 // 112 - 127
2650
- ];
2651
-
2652
- /**
2653
- * Adds an offer to the map of extension offers or a parameter to the map of
2654
- * parameters.
2655
- *
2656
- * @param {Object} dest The map of extension offers or parameters
2657
- * @param {String} name The extension or parameter name
2658
- * @param {(Object|Boolean|String)} elem The extension parameters or the
2659
- * parameter value
2660
- * @private
2661
- */
2662
- function push(dest, name, elem) {
2663
- if (dest[name] === undefined) dest[name] = [elem];
2664
- else dest[name].push(elem);
2665
- }
2666
-
2667
- /**
2668
- * Parses the `Sec-WebSocket-Extensions` header into an object.
2669
- *
2670
- * @param {String} header The field value of the header
2671
- * @return {Object} The parsed object
2672
- * @public
2673
- */
2674
- function parse(header) {
2675
- const offers = Object.create(null);
2676
-
2677
- if (header === undefined || header === '') return offers;
2678
-
2679
- let params = Object.create(null);
2680
- let mustUnescape = false;
2681
- let isEscaping = false;
2682
- let inQuotes = false;
2683
- let extensionName;
2684
- let paramName;
2685
- let start = -1;
2686
- let end = -1;
2687
- let i = 0;
2688
-
2689
- for (; i < header.length; i++) {
2690
- const code = header.charCodeAt(i);
2691
-
2692
- if (extensionName === undefined) {
2693
- if (end === -1 && tokenChars[code] === 1) {
2694
- if (start === -1) start = i;
2695
- } else if (code === 0x20 /* ' ' */ || code === 0x09 /* '\t' */) {
2696
- if (end === -1 && start !== -1) end = i;
2697
- } else if (code === 0x3b /* ';' */ || code === 0x2c /* ',' */) {
2698
- if (start === -1) {
2699
- throw new SyntaxError(`Unexpected character at index ${i}`);
2700
- }
2701
-
2702
- if (end === -1) end = i;
2703
- const name = header.slice(start, end);
2704
- if (code === 0x2c) {
2705
- push(offers, name, params);
2706
- params = Object.create(null);
2707
- } else {
2708
- extensionName = name;
2709
- }
2710
-
2711
- start = end = -1;
2712
- } else {
2713
- throw new SyntaxError(`Unexpected character at index ${i}`);
2714
- }
2715
- } else if (paramName === undefined) {
2716
- if (end === -1 && tokenChars[code] === 1) {
2717
- if (start === -1) start = i;
2718
- } else if (code === 0x20 || code === 0x09) {
2719
- if (end === -1 && start !== -1) end = i;
2720
- } else if (code === 0x3b || code === 0x2c) {
2721
- if (start === -1) {
2722
- throw new SyntaxError(`Unexpected character at index ${i}`);
2723
- }
2724
-
2725
- if (end === -1) end = i;
2726
- push(params, header.slice(start, end), true);
2727
- if (code === 0x2c) {
2728
- push(offers, extensionName, params);
2729
- params = Object.create(null);
2730
- extensionName = undefined;
2731
- }
2732
-
2733
- start = end = -1;
2734
- } else if (code === 0x3d /* '=' */ && start !== -1 && end === -1) {
2735
- paramName = header.slice(start, i);
2736
- start = end = -1;
2737
- } else {
2738
- throw new SyntaxError(`Unexpected character at index ${i}`);
2739
- }
2740
- } else {
2741
- //
2742
- // The value of a quoted-string after unescaping must conform to the
2743
- // token ABNF, so only token characters are valid.
2744
- // Ref: https://tools.ietf.org/html/rfc6455#section-9.1
2745
- //
2746
- if (isEscaping) {
2747
- if (tokenChars[code] !== 1) {
2748
- throw new SyntaxError(`Unexpected character at index ${i}`);
2749
- }
2750
- if (start === -1) start = i;
2751
- else if (!mustUnescape) mustUnescape = true;
2752
- isEscaping = false;
2753
- } else if (inQuotes) {
2754
- if (tokenChars[code] === 1) {
2755
- if (start === -1) start = i;
2756
- } else if (code === 0x22 /* '"' */ && start !== -1) {
2757
- inQuotes = false;
2758
- end = i;
2759
- } else if (code === 0x5c /* '\' */) {
2760
- isEscaping = true;
2761
- } else {
2762
- throw new SyntaxError(`Unexpected character at index ${i}`);
2763
- }
2764
- } else if (code === 0x22 && header.charCodeAt(i - 1) === 0x3d) {
2765
- inQuotes = true;
2766
- } else if (end === -1 && tokenChars[code] === 1) {
2767
- if (start === -1) start = i;
2768
- } else if (start !== -1 && (code === 0x20 || code === 0x09)) {
2769
- if (end === -1) end = i;
2770
- } else if (code === 0x3b || code === 0x2c) {
2771
- if (start === -1) {
2772
- throw new SyntaxError(`Unexpected character at index ${i}`);
2773
- }
2774
-
2775
- if (end === -1) end = i;
2776
- let value = header.slice(start, end);
2777
- if (mustUnescape) {
2778
- value = value.replace(/\\/g, '');
2779
- mustUnescape = false;
2780
- }
2781
- push(params, paramName, value);
2782
- if (code === 0x2c) {
2783
- push(offers, extensionName, params);
2784
- params = Object.create(null);
2785
- extensionName = undefined;
2786
- }
2787
-
2788
- paramName = undefined;
2789
- start = end = -1;
2790
- } else {
2791
- throw new SyntaxError(`Unexpected character at index ${i}`);
2792
- }
2793
- }
2794
- }
2795
-
2796
- if (start === -1 || inQuotes) {
2797
- throw new SyntaxError('Unexpected end of input');
2798
- }
2799
-
2800
- if (end === -1) end = i;
2801
- const token = header.slice(start, end);
2802
- if (extensionName === undefined) {
2803
- push(offers, token, params);
2804
- } else {
2805
- if (paramName === undefined) {
2806
- push(params, token, true);
2807
- } else if (mustUnescape) {
2808
- push(params, paramName, token.replace(/\\/g, ''));
2809
- } else {
2810
- push(params, paramName, token);
2811
- }
2812
- push(offers, extensionName, params);
2813
- }
2814
-
2815
- return offers;
2816
- }
2817
-
2818
- /**
2819
- * Builds the `Sec-WebSocket-Extensions` header field value.
2820
- *
2821
- * @param {Object} extensions The map of extensions and parameters to format
2822
- * @return {String} A string representing the given object
2823
- * @public
2824
- */
2825
- function format(extensions) {
2826
- return Object.keys(extensions)
2827
- .map((extension) => {
2828
- let configurations = extensions[extension];
2829
- if (!Array.isArray(configurations)) configurations = [configurations];
2830
- return configurations
2831
- .map((params) => {
2832
- return [extension]
2833
- .concat(
2834
- Object.keys(params).map((k) => {
2835
- let values = params[k];
2836
- if (!Array.isArray(values)) values = [values];
2837
- return values
2838
- .map((v) => (v === true ? k : `${k}=${v}`))
2839
- .join('; ');
2840
- })
2841
- )
2842
- .join('; ');
2843
- })
2844
- .join(', ');
2845
- })
2846
- .join(', ');
2847
- }
2848
-
2849
- module.exports = { format, parse };
2850
-
2851
-
2852
- /***/ }),
2853
- /* 12 */
2854
- /***/ (function(module, exports, __webpack_require__) {
2855
-
2856
- exports.WebSocket = __webpack_require__(13);
2857
-
2858
-
2859
- /***/ }),
2860
- /* 13 */
2861
- /***/ (function(module, exports, __webpack_require__) {
2862
-
2863
- "use strict";
2864
-
2865
-
2866
- const WebSocket = __webpack_require__(4);
2867
-
2868
- WebSocket.createWebSocketStream = __webpack_require__(21);
2869
- WebSocket.Server = __webpack_require__(22);
2870
- WebSocket.Receiver = __webpack_require__(7);
2871
- WebSocket.Sender = __webpack_require__(10);
2872
-
2873
- module.exports = WebSocket;
2874
-
2875
-
2876
- /***/ }),
2877
- /* 14 */
2878
- /***/ (function(module, exports) {
2879
-
2880
- module.exports = require("https");
2881
-
2882
- /***/ }),
2883
- /* 15 */
2884
- /***/ (function(module, exports) {
2885
-
2886
- module.exports = require("net");
2887
-
2888
- /***/ }),
2889
- /* 16 */
2890
- /***/ (function(module, exports) {
2891
-
2892
- module.exports = require("tls");
2893
-
2894
- /***/ }),
2895
- /* 17 */
2896
- /***/ (function(module, exports) {
2897
-
2898
- module.exports = require("url");
2899
-
2900
- /***/ }),
2901
- /* 18 */
2902
- /***/ (function(module, exports, __webpack_require__) {
2903
-
2904
- "use strict";
2905
-
2906
-
2907
- function Queue(options) {
2908
- if (!(this instanceof Queue)) {
2909
- return new Queue(options);
2910
- }
2911
-
2912
- options = options || {};
2913
- this.concurrency = options.concurrency || Infinity;
2914
- this.pending = 0;
2915
- this.jobs = [];
2916
- this.cbs = [];
2917
- this._done = done.bind(this);
2918
- }
2919
-
2920
- var arrayAddMethods = [
2921
- 'push',
2922
- 'unshift',
2923
- 'splice'
2924
- ];
2925
-
2926
- arrayAddMethods.forEach(function(method) {
2927
- Queue.prototype[method] = function() {
2928
- var methodResult = Array.prototype[method].apply(this.jobs, arguments);
2929
- this._run();
2930
- return methodResult;
2931
- };
2932
- });
2933
-
2934
- Object.defineProperty(Queue.prototype, 'length', {
2935
- get: function() {
2936
- return this.pending + this.jobs.length;
2937
- }
2938
- });
2939
-
2940
- Queue.prototype._run = function() {
2941
- if (this.pending === this.concurrency) {
2942
- return;
2943
- }
2944
- if (this.jobs.length) {
2945
- var job = this.jobs.shift();
2946
- this.pending++;
2947
- job(this._done);
2948
- this._run();
2949
- }
2950
-
2951
- if (this.pending === 0) {
2952
- while (this.cbs.length !== 0) {
2953
- var cb = this.cbs.pop();
2954
- process.nextTick(cb);
2955
- }
2956
- }
2957
- };
2958
-
2959
- Queue.prototype.onDone = function(cb) {
2960
- if (typeof cb === 'function') {
2961
- this.cbs.push(cb);
2962
- this._run();
2963
- }
2964
- };
2965
-
2966
- function done() {
2967
- this.pending--;
2968
- this._run();
2969
- }
2970
-
2971
- module.exports = Queue;
2972
-
2973
-
2974
- /***/ }),
2975
- /* 19 */
2976
- /***/ (function(module, exports) {
2977
-
2978
- module.exports = require("zlib");
2979
-
2980
- /***/ }),
2981
- /* 20 */
2982
- /***/ (function(module, exports, __webpack_require__) {
2983
-
2984
- "use strict";
2985
-
2986
-
2987
- /**
2988
- * Class representing an event.
2989
- *
2990
- * @private
2991
- */
2992
- class Event {
2993
- /**
2994
- * Create a new `Event`.
2995
- *
2996
- * @param {String} type The name of the event
2997
- * @param {Object} target A reference to the target to which the event was dispatched
2998
- */
2999
- constructor(type, target) {
3000
- this.target = target;
3001
- this.type = type;
3002
- }
3003
- }
3004
-
3005
- /**
3006
- * Class representing a message event.
3007
- *
3008
- * @extends Event
3009
- * @private
3010
- */
3011
- class MessageEvent extends Event {
3012
- /**
3013
- * Create a new `MessageEvent`.
3014
- *
3015
- * @param {(String|Buffer|ArrayBuffer|Buffer[])} data The received data
3016
- * @param {WebSocket} target A reference to the target to which the event was dispatched
3017
- */
3018
- constructor(data, target) {
3019
- super('message', target);
3020
-
3021
- this.data = data;
3022
- }
3023
- }
3024
-
3025
- /**
3026
- * Class representing a close event.
3027
- *
3028
- * @extends Event
3029
- * @private
3030
- */
3031
- class CloseEvent extends Event {
3032
- /**
3033
- * Create a new `CloseEvent`.
3034
- *
3035
- * @param {Number} code The status code explaining why the connection is being closed
3036
- * @param {String} reason A human-readable string explaining why the connection is closing
3037
- * @param {WebSocket} target A reference to the target to which the event was dispatched
3038
- */
3039
- constructor(code, reason, target) {
3040
- super('close', target);
3041
-
3042
- this.wasClean = target._closeFrameReceived && target._closeFrameSent;
3043
- this.reason = reason;
3044
- this.code = code;
3045
- }
3046
- }
3047
-
3048
- /**
3049
- * Class representing an open event.
3050
- *
3051
- * @extends Event
3052
- * @private
3053
- */
3054
- class OpenEvent extends Event {
3055
- /**
3056
- * Create a new `OpenEvent`.
3057
- *
3058
- * @param {WebSocket} target A reference to the target to which the event was dispatched
3059
- */
3060
- constructor(target) {
3061
- super('open', target);
3062
- }
3063
- }
3064
-
3065
- /**
3066
- * Class representing an error event.
3067
- *
3068
- * @extends Event
3069
- * @private
3070
- */
3071
- class ErrorEvent extends Event {
3072
- /**
3073
- * Create a new `ErrorEvent`.
3074
- *
3075
- * @param {Object} error The error that generated this event
3076
- * @param {WebSocket} target A reference to the target to which the event was dispatched
3077
- */
3078
- constructor(error, target) {
3079
- super('error', target);
3080
-
3081
- this.message = error.message;
3082
- this.error = error;
3083
- }
3084
- }
3085
-
3086
- /**
3087
- * This provides methods for emulating the `EventTarget` interface. It's not
3088
- * meant to be used directly.
3089
- *
3090
- * @mixin
3091
- */
3092
- const EventTarget = {
3093
- /**
3094
- * Register an event listener.
3095
- *
3096
- * @param {String} method A string representing the event type to listen for
3097
- * @param {Function} listener The listener to add
3098
- * @public
3099
- */
3100
- addEventListener(method, listener) {
3101
- if (typeof listener !== 'function') return;
3102
-
3103
- function onMessage(data) {
3104
- listener.call(this, new MessageEvent(data, this));
3105
- }
3106
-
3107
- function onClose(code, message) {
3108
- listener.call(this, new CloseEvent(code, message, this));
3109
- }
3110
-
3111
- function onError(error) {
3112
- listener.call(this, new ErrorEvent(error, this));
3113
- }
3114
-
3115
- function onOpen() {
3116
- listener.call(this, new OpenEvent(this));
3117
- }
3118
-
3119
- if (method === 'message') {
3120
- onMessage._listener = listener;
3121
- this.on(method, onMessage);
3122
- } else if (method === 'close') {
3123
- onClose._listener = listener;
3124
- this.on(method, onClose);
3125
- } else if (method === 'error') {
3126
- onError._listener = listener;
3127
- this.on(method, onError);
3128
- } else if (method === 'open') {
3129
- onOpen._listener = listener;
3130
- this.on(method, onOpen);
3131
- } else {
3132
- this.on(method, listener);
3133
- }
3134
- },
3135
-
3136
- /**
3137
- * Remove an event listener.
3138
- *
3139
- * @param {String} method A string representing the event type to remove
3140
- * @param {Function} listener The listener to remove
3141
- * @public
3142
- */
3143
- removeEventListener(method, listener) {
3144
- const listeners = this.listeners(method);
3145
-
3146
- for (let i = 0; i < listeners.length; i++) {
3147
- if (listeners[i] === listener || listeners[i]._listener === listener) {
3148
- this.removeListener(method, listeners[i]);
3149
- }
3150
- }
3151
- }
3152
- };
3153
-
3154
- module.exports = EventTarget;
3155
-
3156
-
3157
- /***/ }),
3158
- /* 21 */
3159
- /***/ (function(module, exports, __webpack_require__) {
3160
-
3161
- "use strict";
3162
-
3163
-
3164
- const { Duplex } = __webpack_require__(8);
3165
-
3166
- /**
3167
- * Emits the `'close'` event on a stream.
3168
- *
3169
- * @param {stream.Duplex} The stream.
3170
- * @private
3171
- */
3172
- function emitClose(stream) {
3173
- stream.emit('close');
3174
- }
3175
-
3176
- /**
3177
- * The listener of the `'end'` event.
3178
- *
3179
- * @private
3180
- */
3181
- function duplexOnEnd() {
3182
- if (!this.destroyed && this._writableState.finished) {
3183
- this.destroy();
3184
- }
3185
- }
3186
-
3187
- /**
3188
- * The listener of the `'error'` event.
3189
- *
3190
- * @private
3191
- */
3192
- function duplexOnError(err) {
3193
- this.removeListener('error', duplexOnError);
3194
- this.destroy();
3195
- if (this.listenerCount('error') === 0) {
3196
- // Do not suppress the throwing behavior.
3197
- this.emit('error', err);
3198
- }
3199
- }
3200
-
3201
- /**
3202
- * Wraps a `WebSocket` in a duplex stream.
3203
- *
3204
- * @param {WebSocket} ws The `WebSocket` to wrap
3205
- * @param {Object} options The options for the `Duplex` constructor
3206
- * @return {stream.Duplex} The duplex stream
3207
- * @public
3208
- */
3209
- function createWebSocketStream(ws, options) {
3210
- let resumeOnReceiverDrain = true;
3211
-
3212
- function receiverOnDrain() {
3213
- if (resumeOnReceiverDrain) ws._socket.resume();
3214
- }
3215
-
3216
- if (ws.readyState === ws.CONNECTING) {
3217
- ws.once('open', function open() {
3218
- ws._receiver.removeAllListeners('drain');
3219
- ws._receiver.on('drain', receiverOnDrain);
3220
- });
3221
- } else {
3222
- ws._receiver.removeAllListeners('drain');
3223
- ws._receiver.on('drain', receiverOnDrain);
3224
- }
3225
-
3226
- const duplex = new Duplex({
3227
- ...options,
3228
- autoDestroy: false,
3229
- emitClose: false,
3230
- objectMode: false,
3231
- readableObjectMode: false,
3232
- writableObjectMode: false
3233
- });
3234
-
3235
- ws.on('message', function message(msg) {
3236
- if (!duplex.push(msg)) {
3237
- resumeOnReceiverDrain = false;
3238
- ws._socket.pause();
3239
- }
3240
- });
3241
-
3242
- ws.once('error', function error(err) {
3243
- duplex.destroy(err);
3244
- });
3245
-
3246
- ws.once('close', function close() {
3247
- if (duplex.destroyed) return;
3248
-
3249
- duplex.push(null);
3250
- });
3251
-
3252
- duplex._destroy = function(err, callback) {
3253
- if (ws.readyState === ws.CLOSED) {
3254
- callback(err);
3255
- process.nextTick(emitClose, duplex);
3256
- return;
3257
- }
3258
-
3259
- ws.once('close', function close() {
3260
- callback(err);
3261
- process.nextTick(emitClose, duplex);
3262
- });
3263
- ws.terminate();
3264
- };
3265
-
3266
- duplex._final = function(callback) {
3267
- if (ws.readyState === ws.CONNECTING) {
3268
- ws.once('open', function open() {
3269
- duplex._final(callback);
3270
- });
3271
- return;
3272
- }
3273
-
3274
- if (ws._socket._writableState.finished) {
3275
- if (duplex._readableState.endEmitted) duplex.destroy();
3276
- callback();
3277
- } else {
3278
- ws._socket.once('finish', function finish() {
3279
- // `duplex` is not destroyed here because the `'end'` event will be
3280
- // emitted on `duplex` after this `'finish'` event. The EOF signaling
3281
- // `null` chunk is, in fact, pushed when the WebSocket emits `'close'`.
3282
- callback();
3283
- });
3284
- ws.close();
3285
- }
3286
- };
3287
-
3288
- duplex._read = function() {
3289
- if (ws.readyState === ws.OPEN && !resumeOnReceiverDrain) {
3290
- resumeOnReceiverDrain = true;
3291
- if (!ws._receiver._writableState.needDrain) ws._socket.resume();
3292
- }
3293
- };
3294
-
3295
- duplex._write = function(chunk, encoding, callback) {
3296
- if (ws.readyState === ws.CONNECTING) {
3297
- ws.once('open', function open() {
3298
- duplex._write(chunk, encoding, callback);
3299
- });
3300
- return;
3301
- }
3302
-
3303
- ws.send(chunk, callback);
3304
- };
3305
-
3306
- duplex.on('end', duplexOnEnd);
3307
- duplex.on('error', duplexOnError);
3308
- return duplex;
3309
- }
3310
-
3311
- module.exports = createWebSocketStream;
3312
-
3313
-
3314
- /***/ }),
3315
- /* 22 */
3316
- /***/ (function(module, exports, __webpack_require__) {
3317
-
3318
- "use strict";
3319
-
3320
-
3321
- const EventEmitter = __webpack_require__(5);
3322
- const { createHash } = __webpack_require__(3);
3323
- const { createServer, STATUS_CODES } = __webpack_require__(6);
3324
-
3325
- const PerMessageDeflate = __webpack_require__(1);
3326
- const WebSocket = __webpack_require__(4);
3327
- const { format, parse } = __webpack_require__(11);
3328
- const { GUID } = __webpack_require__(0);
3329
-
3330
- const keyRegex = /^[+/0-9A-Za-z]{22}==$/;
3331
- const kUsedByWebSocketServer = Symbol('kUsedByWebSocketServer');
3332
-
3333
- /**
3334
- * Class representing a WebSocket server.
3335
- *
3336
- * @extends EventEmitter
3337
- */
3338
- class WebSocketServer extends EventEmitter {
3339
- /**
3340
- * Create a `WebSocketServer` instance.
3341
- *
3342
- * @param {Object} options Configuration options
3343
- * @param {Number} options.backlog The maximum length of the queue of pending
3344
- * connections
3345
- * @param {Boolean} options.clientTracking Specifies whether or not to track
3346
- * clients
3347
- * @param {Function} options.handleProtocols A hook to handle protocols
3348
- * @param {String} options.host The hostname where to bind the server
3349
- * @param {Number} options.maxPayload The maximum allowed message size
3350
- * @param {Boolean} options.noServer Enable no server mode
3351
- * @param {String} options.path Accept only connections matching this path
3352
- * @param {(Boolean|Object)} options.perMessageDeflate Enable/disable
3353
- * permessage-deflate
3354
- * @param {Number} options.port The port where to bind the server
3355
- * @param {http.Server} options.server A pre-created HTTP/S server to use
3356
- * @param {Function} options.verifyClient A hook to reject connections
3357
- * @param {Function} callback A listener for the `listening` event
3358
- */
3359
- constructor(options, callback) {
3360
- super();
3361
-
3362
- options = {
3363
- maxPayload: 100 * 1024 * 1024,
3364
- perMessageDeflate: false,
3365
- handleProtocols: null,
3366
- clientTracking: true,
3367
- verifyClient: null,
3368
- noServer: false,
3369
- backlog: null, // use default (511 as implemented in net.js)
3370
- server: null,
3371
- host: null,
3372
- path: null,
3373
- port: null,
3374
- ...options
3375
- };
3376
-
3377
- if (options.port == null && !options.server && !options.noServer) {
3378
- throw new TypeError(
3379
- 'One of the "port", "server", or "noServer" options must be specified'
3380
- );
3381
- }
3382
-
3383
- if (options.port != null) {
3384
- this._server = createServer((req, res) => {
3385
- const body = STATUS_CODES[426];
3386
-
3387
- res.writeHead(426, {
3388
- 'Content-Length': body.length,
3389
- 'Content-Type': 'text/plain'
3390
- });
3391
- res.end(body);
3392
- });
3393
- this._server.listen(
3394
- options.port,
3395
- options.host,
3396
- options.backlog,
3397
- callback
3398
- );
3399
- } else if (options.server) {
3400
- if (options.server[kUsedByWebSocketServer]) {
3401
- throw new Error(
3402
- 'The HTTP/S server is already being used by another WebSocket server'
3403
- );
3404
- }
3405
-
3406
- options.server[kUsedByWebSocketServer] = true;
3407
- this._server = options.server;
3408
- }
3409
-
3410
- if (this._server) {
3411
- this._removeListeners = addListeners(this._server, {
3412
- listening: this.emit.bind(this, 'listening'),
3413
- error: this.emit.bind(this, 'error'),
3414
- upgrade: (req, socket, head) => {
3415
- this.handleUpgrade(req, socket, head, (ws) => {
3416
- this.emit('connection', ws, req);
3417
- });
3418
- }
3419
- });
3420
- }
3421
-
3422
- if (options.perMessageDeflate === true) options.perMessageDeflate = {};
3423
- if (options.clientTracking) this.clients = new Set();
3424
- this.options = options;
3425
- }
3426
-
3427
- /**
3428
- * Returns the bound address, the address family name, and port of the server
3429
- * as reported by the operating system if listening on an IP socket.
3430
- * If the server is listening on a pipe or UNIX domain socket, the name is
3431
- * returned as a string.
3432
- *
3433
- * @return {(Object|String|null)} The address of the server
3434
- * @public
3435
- */
3436
- address() {
3437
- if (this.options.noServer) {
3438
- throw new Error('The server is operating in "noServer" mode');
3439
- }
3440
-
3441
- if (!this._server) return null;
3442
- return this._server.address();
3443
- }
3444
-
3445
- /**
3446
- * Close the server.
3447
- *
3448
- * @param {Function} cb Callback
3449
- * @public
3450
- */
3451
- close(cb) {
3452
- if (cb) this.once('close', cb);
3453
-
3454
- //
3455
- // Terminate all associated clients.
3456
- //
3457
- if (this.clients) {
3458
- for (const client of this.clients) client.terminate();
3459
- }
3460
-
3461
- const server = this._server;
3462
-
3463
- if (server) {
3464
- this._removeListeners();
3465
- this._removeListeners = this._server = null;
3466
-
3467
- //
3468
- // Close the http server if it was internally created.
3469
- //
3470
- if (this.options.port != null) {
3471
- server.close(() => this.emit('close'));
3472
- return;
3473
- }
3474
-
3475
- delete server[kUsedByWebSocketServer];
3476
- }
3477
-
3478
- process.nextTick(emitClose, this);
3479
- }
3480
-
3481
- /**
3482
- * See if a given request should be handled by this server instance.
3483
- *
3484
- * @param {http.IncomingMessage} req Request object to inspect
3485
- * @return {Boolean} `true` if the request is valid, else `false`
3486
- * @public
3487
- */
3488
- shouldHandle(req) {
3489
- if (this.options.path) {
3490
- const index = req.url.indexOf('?');
3491
- const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
3492
-
3493
- if (pathname !== this.options.path) return false;
3494
- }
3495
-
3496
- return true;
3497
- }
3498
-
3499
- /**
3500
- * Handle a HTTP Upgrade request.
3501
- *
3502
- * @param {http.IncomingMessage} req The request object
3503
- * @param {net.Socket} socket The network socket between the server and client
3504
- * @param {Buffer} head The first packet of the upgraded stream
3505
- * @param {Function} cb Callback
3506
- * @public
3507
- */
3508
- handleUpgrade(req, socket, head, cb) {
3509
- socket.on('error', socketOnError);
3510
-
3511
- const key =
3512
- req.headers['sec-websocket-key'] !== undefined
3513
- ? req.headers['sec-websocket-key'].trim()
3514
- : false;
3515
- const version = +req.headers['sec-websocket-version'];
3516
- const extensions = {};
3517
-
3518
- if (
3519
- req.method !== 'GET' ||
3520
- req.headers.upgrade.toLowerCase() !== 'websocket' ||
3521
- !key ||
3522
- !keyRegex.test(key) ||
3523
- (version !== 8 && version !== 13) ||
3524
- !this.shouldHandle(req)
3525
- ) {
3526
- return abortHandshake(socket, 400);
3527
- }
3528
-
3529
- if (this.options.perMessageDeflate) {
3530
- const perMessageDeflate = new PerMessageDeflate(
3531
- this.options.perMessageDeflate,
3532
- true,
3533
- this.options.maxPayload
3534
- );
3535
-
3536
- try {
3537
- const offers = parse(req.headers['sec-websocket-extensions']);
3538
-
3539
- if (offers[PerMessageDeflate.extensionName]) {
3540
- perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
3541
- extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3542
- }
3543
- } catch (err) {
3544
- return abortHandshake(socket, 400);
3545
- }
3546
- }
3547
-
3548
- //
3549
- // Optionally call external client verification handler.
3550
- //
3551
- if (this.options.verifyClient) {
3552
- const info = {
3553
- origin:
3554
- req.headers[`${version === 8 ? 'sec-websocket-origin' : 'origin'}`],
3555
- secure: !!(req.connection.authorized || req.connection.encrypted),
3556
- req
3557
- };
3558
-
3559
- if (this.options.verifyClient.length === 2) {
3560
- this.options.verifyClient(info, (verified, code, message, headers) => {
3561
- if (!verified) {
3562
- return abortHandshake(socket, code || 401, message, headers);
3563
- }
3564
-
3565
- this.completeUpgrade(key, extensions, req, socket, head, cb);
3566
- });
3567
- return;
3568
- }
3569
-
3570
- if (!this.options.verifyClient(info)) return abortHandshake(socket, 401);
3571
- }
3572
-
3573
- this.completeUpgrade(key, extensions, req, socket, head, cb);
3574
- }
3575
-
3576
- /**
3577
- * Upgrade the connection to WebSocket.
3578
- *
3579
- * @param {String} key The value of the `Sec-WebSocket-Key` header
3580
- * @param {Object} extensions The accepted extensions
3581
- * @param {http.IncomingMessage} req The request object
3582
- * @param {net.Socket} socket The network socket between the server and client
3583
- * @param {Buffer} head The first packet of the upgraded stream
3584
- * @param {Function} cb Callback
3585
- * @private
3586
- */
3587
- completeUpgrade(key, extensions, req, socket, head, cb) {
3588
- //
3589
- // Destroy the socket if the client has already sent a FIN packet.
3590
- //
3591
- if (!socket.readable || !socket.writable) return socket.destroy();
3592
-
3593
- const digest = createHash('sha1')
3594
- .update(key + GUID)
3595
- .digest('base64');
3596
-
3597
- const headers = [
3598
- 'HTTP/1.1 101 Switching Protocols',
3599
- 'Upgrade: websocket',
3600
- 'Connection: Upgrade',
3601
- `Sec-WebSocket-Accept: ${digest}`
3602
- ];
3603
-
3604
- const ws = new WebSocket(null);
3605
- let protocol = req.headers['sec-websocket-protocol'];
3606
-
3607
- if (protocol) {
3608
- protocol = protocol.trim().split(/ *, */);
3609
-
3610
- //
3611
- // Optionally call external protocol selection handler.
3612
- //
3613
- if (this.options.handleProtocols) {
3614
- protocol = this.options.handleProtocols(protocol, req);
3615
- } else {
3616
- protocol = protocol[0];
3617
- }
3618
-
3619
- if (protocol) {
3620
- headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
3621
- ws.protocol = protocol;
3622
- }
3623
- }
3624
-
3625
- if (extensions[PerMessageDeflate.extensionName]) {
3626
- const params = extensions[PerMessageDeflate.extensionName].params;
3627
- const value = format({
3628
- [PerMessageDeflate.extensionName]: [params]
3629
- });
3630
- headers.push(`Sec-WebSocket-Extensions: ${value}`);
3631
- ws._extensions = extensions;
3632
- }
3633
-
3634
- //
3635
- // Allow external modification/inspection of handshake headers.
3636
- //
3637
- this.emit('headers', headers, req);
3638
-
3639
- socket.write(headers.concat('\r\n').join('\r\n'));
3640
- socket.removeListener('error', socketOnError);
3641
-
3642
- ws.setSocket(socket, head, this.options.maxPayload);
3643
-
3644
- if (this.clients) {
3645
- this.clients.add(ws);
3646
- ws.on('close', () => this.clients.delete(ws));
3647
- }
3648
-
3649
- cb(ws);
3650
- }
3651
- }
3652
-
3653
- module.exports = WebSocketServer;
3654
-
3655
- /**
3656
- * Add event listeners on an `EventEmitter` using a map of <event, listener>
3657
- * pairs.
3658
- *
3659
- * @param {EventEmitter} server The event emitter
3660
- * @param {Object.<String, Function>} map The listeners to add
3661
- * @return {Function} A function that will remove the added listeners when called
3662
- * @private
3663
- */
3664
- function addListeners(server, map) {
3665
- for (const event of Object.keys(map)) server.on(event, map[event]);
3666
-
3667
- return function removeListeners() {
3668
- for (const event of Object.keys(map)) {
3669
- server.removeListener(event, map[event]);
3670
- }
3671
- };
3672
- }
3673
-
3674
- /**
3675
- * Emit a `'close'` event on an `EventEmitter`.
3676
- *
3677
- * @param {EventEmitter} server The event emitter
3678
- * @private
3679
- */
3680
- function emitClose(server) {
3681
- server.emit('close');
3682
- }
3683
-
3684
- /**
3685
- * Handle premature socket errors.
3686
- *
3687
- * @private
3688
- */
3689
- function socketOnError() {
3690
- this.destroy();
3691
- }
3692
-
3693
- /**
3694
- * Close the connection when preconditions are not fulfilled.
3695
- *
3696
- * @param {net.Socket} socket The socket of the upgrade request
3697
- * @param {Number} code The HTTP response status code
3698
- * @param {String} [message] The HTTP response body
3699
- * @param {Object} [headers] Additional HTTP response headers
3700
- * @private
3701
- */
3702
- function abortHandshake(socket, code, message, headers) {
3703
- if (socket.writable) {
3704
- message = message || STATUS_CODES[code];
3705
- headers = {
3706
- Connection: 'close',
3707
- 'Content-type': 'text/html',
3708
- 'Content-Length': Buffer.byteLength(message),
3709
- ...headers
3710
- };
3711
-
3712
- socket.write(
3713
- `HTTP/1.1 ${code} ${STATUS_CODES[code]}\r\n` +
3714
- Object.keys(headers)
3715
- .map((h) => `${h}: ${headers[h]}`)
3716
- .join('\r\n') +
3717
- '\r\n\r\n' +
3718
- message
3719
- );
3720
- }
3721
-
3722
- socket.removeListener('error', socketOnError);
3723
- socket.destroy();
3724
- }
3725
-
3726
-
3727
- /***/ })
3728
- /******/ ])));