@cfxjs/sirius-next-common 0.2.10 → 0.2.12

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 (329) hide show
  1. package/dist/_esm-TZ4WSCGM.js +4035 -0
  2. package/dist/_esm-TZ4WSCGM.js.map +1 -0
  3. package/dist/abis/CommonError.d.ts +10 -0
  4. package/dist/abis/CommonError.js +8 -0
  5. package/dist/abis/CommonError.js.map +1 -0
  6. package/dist/abis/CommonPanic.d.ts +10 -0
  7. package/dist/abis/CommonPanic.js +8 -0
  8. package/dist/abis/CommonPanic.js.map +1 -0
  9. package/dist/ccip-DBSI27GO.js +15 -0
  10. package/dist/ccip-DBSI27GO.js.map +1 -0
  11. package/dist/chunk-3HO74CMH.js +186 -0
  12. package/dist/chunk-3HO74CMH.js.map +1 -0
  13. package/dist/chunk-3PXUIH3S.js +17 -0
  14. package/dist/chunk-3PXUIH3S.js.map +1 -0
  15. package/dist/chunk-4B6ASBYQ.js +408 -0
  16. package/dist/chunk-4B6ASBYQ.js.map +1 -0
  17. package/dist/chunk-4J3SQGIV.js +82 -0
  18. package/dist/chunk-4J3SQGIV.js.map +1 -0
  19. package/dist/{chunk-LXTR4VAD.js → chunk-5EDEEGZK.js} +42 -19
  20. package/dist/chunk-5EDEEGZK.js.map +1 -0
  21. package/dist/chunk-5TGK2EA2.js +18 -0
  22. package/dist/chunk-5TGK2EA2.js.map +1 -0
  23. package/dist/chunk-5Y7I6VYA.js +145 -0
  24. package/dist/chunk-5Y7I6VYA.js.map +1 -0
  25. package/dist/chunk-6H5A42YS.js +23 -0
  26. package/dist/chunk-6H5A42YS.js.map +1 -0
  27. package/dist/chunk-6HJCR6PQ.js +79 -0
  28. package/dist/chunk-6HJCR6PQ.js.map +1 -0
  29. package/dist/chunk-6SXAFSBF.js +1032 -0
  30. package/dist/chunk-6SXAFSBF.js.map +1 -0
  31. package/dist/chunk-ADNS57X5.js +18 -0
  32. package/dist/chunk-ADNS57X5.js.map +1 -0
  33. package/dist/{chunk-ABDGDYRT.js → chunk-ADULNBMD.js} +5 -5
  34. package/dist/{chunk-IIIPX34H.js → chunk-BUSBM33B.js} +4 -4
  35. package/dist/chunk-CKVDFS45.js +56 -0
  36. package/dist/chunk-CKVDFS45.js.map +1 -0
  37. package/dist/{chunk-WI3G3OD5.js → chunk-CNF26YY7.js} +3 -3
  38. package/dist/{chunk-DFQG46WD.js → chunk-CPPQCJEV.js} +3 -3
  39. package/dist/chunk-CPR4QZT6.js +21 -0
  40. package/dist/chunk-CPR4QZT6.js.map +1 -0
  41. package/dist/{chunk-NUKYY7GO.js → chunk-DF3PVTB5.js} +2 -2
  42. package/dist/chunk-E3ZD2GGG.js +17 -0
  43. package/dist/chunk-E3ZD2GGG.js.map +1 -0
  44. package/dist/chunk-EERNUGUK.js +198 -0
  45. package/dist/chunk-EERNUGUK.js.map +1 -0
  46. package/dist/{chunk-S5QP6EUQ.js → chunk-EMPFZFBS.js} +6 -19
  47. package/dist/chunk-EMPFZFBS.js.map +1 -0
  48. package/dist/chunk-FYLAXC3R.js +82 -0
  49. package/dist/chunk-FYLAXC3R.js.map +1 -0
  50. package/dist/{chunk-IWNT4XVY.js → chunk-GKZK26DZ.js} +3 -3
  51. package/dist/{chunk-IQJOXINX.js → chunk-GSWIFV2B.js} +2 -2
  52. package/dist/chunk-JFFTHCNE.js +344 -0
  53. package/dist/chunk-JFFTHCNE.js.map +1 -0
  54. package/dist/chunk-JIRLY7OG.js +4357 -0
  55. package/dist/chunk-JIRLY7OG.js.map +1 -0
  56. package/dist/chunk-K6FHTS3F.js +115 -0
  57. package/dist/chunk-K6FHTS3F.js.map +1 -0
  58. package/dist/chunk-L62OTV7F.js +71 -0
  59. package/dist/chunk-L62OTV7F.js.map +1 -0
  60. package/dist/{chunk-2R6NJR5T.js → chunk-LVFMTP5H.js} +2 -2
  61. package/dist/chunk-NWVSTRCG.js +20 -0
  62. package/dist/chunk-NWVSTRCG.js.map +1 -0
  63. package/dist/chunk-NXCZ5PMI.js +64 -0
  64. package/dist/chunk-NXCZ5PMI.js.map +1 -0
  65. package/dist/{chunk-HHA2RXLW.js → chunk-NZY53U2H.js} +9 -13
  66. package/dist/chunk-NZY53U2H.js.map +1 -0
  67. package/dist/{chunk-U3F7QHXB.js → chunk-OCQIWTDC.js} +2 -2
  68. package/dist/{chunk-EQWAYCW3.js → chunk-ODJ4QBD5.js} +6 -6
  69. package/dist/chunk-OYESIV3F.js +47 -0
  70. package/dist/chunk-OYESIV3F.js.map +1 -0
  71. package/dist/{chunk-IWGPVXSI.js → chunk-P4EE3QGM.js} +3 -3
  72. package/dist/{chunk-BRST23XX.js → chunk-Q2DX6IDH.js} +2 -2
  73. package/dist/chunk-QMLPHJCA.js +78 -0
  74. package/dist/chunk-QMLPHJCA.js.map +1 -0
  75. package/dist/chunk-SFCNLOQ5.js +37 -0
  76. package/dist/chunk-SFCNLOQ5.js.map +1 -0
  77. package/dist/chunk-SUCQASD3.js +84 -0
  78. package/dist/chunk-SUCQASD3.js.map +1 -0
  79. package/dist/chunk-U6ZN2ABK.js +184 -0
  80. package/dist/chunk-U6ZN2ABK.js.map +1 -0
  81. package/dist/chunk-UM5J477V.js +69 -0
  82. package/dist/chunk-UM5J477V.js.map +1 -0
  83. package/dist/{chunk-7RH7LJYB.js → chunk-WIB76E7O.js} +6 -2
  84. package/dist/{chunk-7RH7LJYB.js.map → chunk-WIB76E7O.js.map} +1 -1
  85. package/dist/chunk-WQG2LZMB.js +50 -0
  86. package/dist/chunk-WQG2LZMB.js.map +1 -0
  87. package/dist/chunk-XZ7IV2FF.js +5947 -0
  88. package/dist/chunk-XZ7IV2FF.js.map +1 -0
  89. package/dist/chunk-Y7OVL5US.js +46 -0
  90. package/dist/chunk-Y7OVL5US.js.map +1 -0
  91. package/dist/chunk-YBQQ72FQ.js +10 -0
  92. package/dist/chunk-YBQQ72FQ.js.map +1 -0
  93. package/dist/{chunk-YEUH2K6Z.js → chunk-YEINMVAR.js} +8 -2
  94. package/dist/chunk-YEINMVAR.js.map +1 -0
  95. package/dist/chunk-YIZCD4WG.js +107 -0
  96. package/dist/chunk-YIZCD4WG.js.map +1 -0
  97. package/dist/components/AceEditor/index.js +9 -143
  98. package/dist/components/AceEditor/index.js.map +1 -1
  99. package/dist/components/AddressContainer/CoreAddressContainer.js +14 -12
  100. package/dist/components/AddressContainer/EVMAddressContainer.js +13 -11
  101. package/dist/components/AddressContainer/addressSwitcher.js +11 -9
  102. package/dist/components/AddressContainer/addressView.js +9 -8
  103. package/dist/components/AddressContainer/label.js +7 -6
  104. package/dist/components/AddressContainer/utils.d.ts +9 -0
  105. package/dist/components/AddressContainer/utils.js +30 -0
  106. package/dist/components/AddressContainer/utils.js.map +1 -0
  107. package/dist/components/Age/index.js +7 -6
  108. package/dist/components/Age/index.js.map +1 -1
  109. package/dist/components/AutoComplete/index.js +6 -5
  110. package/dist/components/AutoComplete/index.js.map +1 -1
  111. package/dist/components/Button/ActionButton/index.js +1 -0
  112. package/dist/components/Button/BaseButton/index.js +1 -0
  113. package/dist/components/Button/IconButton/index.js +1 -0
  114. package/dist/components/Button/index.js +1 -0
  115. package/dist/components/Card/index.js +1 -0
  116. package/dist/components/Charts/BreadcrumbNav.js +1 -0
  117. package/dist/components/Charts/ChartOptions.js +1 -0
  118. package/dist/components/Charts/PreviewChartTemplate.js +3 -2
  119. package/dist/components/Charts/PreviewChartTemplate.js.map +1 -1
  120. package/dist/components/Charts/PreviewTitle.js +1 -0
  121. package/dist/components/Charts/StockChartTemplate.js +10 -9
  122. package/dist/components/Charts/StockChartTemplate.js.map +1 -1
  123. package/dist/components/Charts/StockTitle.js +1 -0
  124. package/dist/components/Charts/config.js +1 -0
  125. package/dist/components/Charts/constants.js +1 -0
  126. package/dist/components/Charts/useHighCharts.js +1 -0
  127. package/dist/components/CookieTip/CookieIcon.js +1 -0
  128. package/dist/components/CookieTip/index.js +2 -1
  129. package/dist/components/CookieTip/index.js.map +1 -1
  130. package/dist/components/CopyButton/index.js +6 -5
  131. package/dist/components/CopyButton/index.js.map +1 -1
  132. package/dist/components/DecimalsSelect/index.js +6 -5
  133. package/dist/components/DecimalsSelect/index.js.map +1 -1
  134. package/dist/components/DeleteIcon/index.js +2 -0
  135. package/dist/components/DeleteIcon/index.js.map +1 -1
  136. package/dist/components/Description/index.js +1 -0
  137. package/dist/components/Divider/index.js +1 -0
  138. package/dist/components/DownloadCSV/index.js +7 -6
  139. package/dist/components/DownloadCSV/index.js.map +1 -1
  140. package/dist/components/Dropdown/index.js +1 -0
  141. package/dist/components/Dropdown/index.js.map +1 -1
  142. package/dist/components/Empty/index.js +4 -40
  143. package/dist/components/Empty/index.js.map +1 -1
  144. package/dist/components/FileUpload/index.js +2 -0
  145. package/dist/components/FileUpload/index.js.map +1 -1
  146. package/dist/components/Footer/index.js +1 -0
  147. package/dist/components/Footer/index.js.map +1 -1
  148. package/dist/components/GasPriceDropdown/index.js +5 -4
  149. package/dist/components/GasPriceDropdown/index.js.map +1 -1
  150. package/dist/components/Highlight/index.js +1 -0
  151. package/dist/components/Highlight/index.js.map +1 -1
  152. package/dist/components/Icons/index.d.ts +8 -1
  153. package/dist/components/Icons/index.js +20 -64
  154. package/dist/components/Icons/index.js.map +1 -1
  155. package/dist/components/ImageSkeleton/index.js +2 -0
  156. package/dist/components/ImageSkeleton/index.js.map +1 -1
  157. package/dist/components/IncreasePercent/Icons.js +1 -0
  158. package/dist/components/IncreasePercent/index.js +5 -4
  159. package/dist/components/IncreasePercent/index.js.map +1 -1
  160. package/dist/components/InfoIconWithTooltip/InfoIcon.js +1 -0
  161. package/dist/components/InfoIconWithTooltip/index.js +7 -6
  162. package/dist/components/InputData/AddressLabel.d.ts +8 -0
  163. package/dist/components/InputData/AddressLabel.js +23 -0
  164. package/dist/components/InputData/AddressLabel.js.map +1 -0
  165. package/dist/components/InputData/ContractDetail.d.ts +22 -0
  166. package/dist/components/InputData/ContractDetail.js +19 -0
  167. package/dist/components/InputData/ContractDetail.js.map +1 -0
  168. package/dist/components/InputData/FunctionName.d.ts +10 -0
  169. package/dist/components/InputData/FunctionName.js +10 -0
  170. package/dist/components/InputData/FunctionName.js.map +1 -0
  171. package/dist/components/InputData/GeneralDecode.d.ts +9 -0
  172. package/dist/components/InputData/GeneralDecode.js +8 -0
  173. package/dist/components/InputData/GeneralDecode.js.map +1 -0
  174. package/dist/components/InputData/JsonDecode.d.ts +18 -0
  175. package/dist/components/InputData/JsonDecode.js +19 -0
  176. package/dist/components/InputData/JsonDecode.js.map +1 -0
  177. package/dist/components/InputData/OptimizationDecode.d.ts +23 -0
  178. package/dist/components/InputData/OptimizationDecode.js +32 -0
  179. package/dist/components/InputData/OptimizationDecode.js.map +1 -0
  180. package/dist/components/InputData/Original.d.ts +8 -0
  181. package/dist/components/InputData/Original.js +8 -0
  182. package/dist/components/InputData/Original.js.map +1 -0
  183. package/dist/components/InputData/UTF8.d.ts +8 -0
  184. package/dist/components/InputData/UTF8.js +14 -0
  185. package/dist/components/InputData/UTF8.js.map +1 -0
  186. package/dist/components/InputData/index.d.ts +15 -0
  187. package/dist/components/InputData/index.js +36 -0
  188. package/dist/components/InputData/index.js.map +1 -0
  189. package/dist/components/InputData/utils.d.ts +5 -0
  190. package/dist/components/InputData/utils.js +8 -0
  191. package/dist/components/InputData/utils.js.map +1 -0
  192. package/dist/components/Link/index.js +1 -0
  193. package/dist/components/List/index.js +1 -0
  194. package/dist/components/List/index.js.map +1 -1
  195. package/dist/components/Loading/index.js +1 -0
  196. package/dist/components/Loading/index.js.map +1 -1
  197. package/dist/components/Loading/loading.js +1 -0
  198. package/dist/components/Modal/index.js +6 -5
  199. package/dist/components/NetworkIcon/index.js +5 -4
  200. package/dist/components/NetworkIcon/index.js.map +1 -1
  201. package/dist/components/OutputData/ErrorDecode.d.ts +14 -0
  202. package/dist/components/OutputData/ErrorDecode.js +39 -0
  203. package/dist/components/OutputData/ErrorDecode.js.map +1 -0
  204. package/dist/components/OutputData/index.d.ts +21 -0
  205. package/dist/components/OutputData/index.js +42 -0
  206. package/dist/components/OutputData/index.js.map +1 -0
  207. package/dist/components/PageHeader/index.js +2 -0
  208. package/dist/components/PageHeader/index.js.map +1 -1
  209. package/dist/components/PhishingAddressContainer/PhishingWarningIcon.js +1 -0
  210. package/dist/components/PhishingAddressContainer/index.js +7 -6
  211. package/dist/components/PhishingAddressContainer/index.js.map +1 -1
  212. package/dist/components/Popover/index.js +6 -5
  213. package/dist/components/Price/index.js +6 -5
  214. package/dist/components/Price/index.js.map +1 -1
  215. package/dist/components/ProxyContractAddress/index.d.ts +24 -0
  216. package/dist/components/ProxyContractAddress/index.js +120 -0
  217. package/dist/components/ProxyContractAddress/index.js.map +1 -0
  218. package/dist/components/Radio/index.js +5 -4
  219. package/dist/components/Radio/index.js.map +1 -1
  220. package/dist/components/Remark/index.js +1 -0
  221. package/dist/components/Remark/index.js.map +1 -1
  222. package/dist/components/SearchIcon/index.js +2 -0
  223. package/dist/components/SearchIcon/index.js.map +1 -1
  224. package/dist/components/SearchInput/index.js +7 -6
  225. package/dist/components/SearchInput/index.js.map +1 -1
  226. package/dist/components/Select/index.d.ts +5 -4
  227. package/dist/components/Select/index.js +10 -105
  228. package/dist/components/Select/index.js.map +1 -1
  229. package/dist/components/Select/select.js +7 -5
  230. package/dist/components/Skeleton/index.js +1 -0
  231. package/dist/components/SkeletonContainer/index.js +1 -0
  232. package/dist/components/Spin/index.js +1 -0
  233. package/dist/components/Switch/index.d.ts +10 -0
  234. package/dist/components/Switch/index.js +81 -0
  235. package/dist/components/Switch/index.js.map +1 -0
  236. package/dist/components/Table/index.d.ts +9 -0
  237. package/dist/components/Table/index.js +12 -0
  238. package/dist/components/Table/index.js.map +1 -0
  239. package/dist/components/Text/index.js +7 -6
  240. package/dist/components/TextLogo/index.js +2 -0
  241. package/dist/components/TextLogo/index.js.map +1 -1
  242. package/dist/components/Tooltip/index.js +6 -5
  243. package/dist/components/TransactionAction/constants.js +1 -0
  244. package/dist/components/TransactionAction/coreTransactionAction.js +15 -13
  245. package/dist/components/TransactionAction/coreTransactionAction.js.map +1 -1
  246. package/dist/components/TransactionAction/evmTransactionAction.js +14 -12
  247. package/dist/components/TransactionAction/evmTransactionAction.js.map +1 -1
  248. package/dist/components/TransactionTrace/TraceDetail.d.ts +20 -0
  249. package/dist/components/TransactionTrace/TraceDetail.js +54 -0
  250. package/dist/components/TransactionTrace/TraceDetail.js.map +1 -0
  251. package/dist/components/TransactionTrace/TreeTraceTable.d.ts +20 -0
  252. package/dist/components/TransactionTrace/TreeTraceTable.js +57 -0
  253. package/dist/components/TransactionTrace/TreeTraceTable.js.map +1 -0
  254. package/dist/components/TransactionTrace/index.d.ts +9 -0
  255. package/dist/components/TransactionTrace/index.js +60 -0
  256. package/dist/components/TransactionTrace/index.js.map +1 -0
  257. package/dist/secp256k1-WGKMGTUQ.js +2255 -0
  258. package/dist/secp256k1-WGKMGTUQ.js.map +1 -0
  259. package/dist/store/index.js +1 -0
  260. package/dist/uno.css +103 -5
  261. package/dist/utils/address.js +5 -4
  262. package/dist/utils/cache.js +2 -1
  263. package/dist/utils/constants.d.ts +3 -1
  264. package/dist/utils/constants.js +6 -1
  265. package/dist/utils/contractManagerTool.js +5 -4
  266. package/dist/utils/contractManagerTool.js.map +1 -1
  267. package/dist/utils/cookie.js +1 -0
  268. package/dist/utils/ga.js +1 -0
  269. package/dist/utils/hooks/useAddressLabel.d.ts +3 -0
  270. package/dist/utils/hooks/useAddressLabel.js +14 -0
  271. package/dist/utils/hooks/useAddressLabel.js.map +1 -0
  272. package/dist/utils/hooks/useAge.js +2 -1
  273. package/dist/utils/hooks/useAge.js.map +1 -1
  274. package/dist/utils/hooks/useAutoSetHolderFilterParams.js +5 -4
  275. package/dist/utils/hooks/useAutoSetHolderFilterParams.js.map +1 -1
  276. package/dist/utils/hooks/useChartQueryParams.js +2 -0
  277. package/dist/utils/hooks/useChartQueryParams.js.map +1 -1
  278. package/dist/utils/hooks/useContractDetail.d.ts +6 -0
  279. package/dist/utils/hooks/useContractDetail.js +12 -0
  280. package/dist/utils/hooks/useContractDetail.js.map +1 -0
  281. package/dist/utils/hooks/useDecodeFunctionData.d.ts +29 -0
  282. package/dist/utils/hooks/useDecodeFunctionData.js +19 -0
  283. package/dist/utils/hooks/useDecodeFunctionData.js.map +1 -0
  284. package/dist/utils/hooks/useDecodeFunctionError.d.ts +17 -0
  285. package/dist/utils/hooks/useDecodeFunctionError.js +19 -0
  286. package/dist/utils/hooks/useDecodeFunctionError.js.map +1 -0
  287. package/dist/utils/hooks/useDecodedDataType.d.ts +18 -0
  288. package/dist/utils/hooks/useDecodedDataType.js +8 -0
  289. package/dist/utils/hooks/useDecodedDataType.js.map +1 -0
  290. package/dist/utils/hooks/useENS.js +6 -5
  291. package/dist/utils/hooks/useGetTxnStatus.js +2 -0
  292. package/dist/utils/hooks/useGetTxnStatus.js.map +1 -1
  293. package/dist/utils/hooks/useMethodAbi.d.ts +8 -0
  294. package/dist/utils/hooks/useMethodAbi.js +12 -0
  295. package/dist/utils/hooks/useMethodAbi.js.map +1 -0
  296. package/dist/utils/hooks/useMultiAceSearch.js +2 -0
  297. package/dist/utils/hooks/useMultiAceSearch.js.map +1 -1
  298. package/dist/utils/hooks/useSearchParams.js +1 -0
  299. package/dist/utils/hooks/useTxTrace.d.ts +124 -0
  300. package/dist/utils/hooks/useTxTrace.js +170 -0
  301. package/dist/utils/hooks/useTxTrace.js.map +1 -0
  302. package/dist/utils/index.js +5 -4
  303. package/dist/utils/media.js +1 -0
  304. package/dist/utils/pubsub.js +1 -0
  305. package/dist/utils/request.d.ts +5 -2
  306. package/dist/utils/request.js +5 -2
  307. package/dist/utils/request.types.d.ts +18 -3
  308. package/dist/utils/rpcRequest.js +1 -0
  309. package/dist/utils/rpcRequest.js.map +1 -1
  310. package/dist/utils/sdk.d.ts +35 -0
  311. package/dist/utils/sdk.js +19 -0
  312. package/dist/utils/sdk.js.map +1 -0
  313. package/package.json +5 -2
  314. package/dist/chunk-HHA2RXLW.js.map +0 -1
  315. package/dist/chunk-LXTR4VAD.js.map +0 -1
  316. package/dist/chunk-S5QP6EUQ.js.map +0 -1
  317. package/dist/chunk-YEUH2K6Z.js.map +0 -1
  318. /package/dist/{chunk-ABDGDYRT.js.map → chunk-ADULNBMD.js.map} +0 -0
  319. /package/dist/{chunk-IIIPX34H.js.map → chunk-BUSBM33B.js.map} +0 -0
  320. /package/dist/{chunk-WI3G3OD5.js.map → chunk-CNF26YY7.js.map} +0 -0
  321. /package/dist/{chunk-DFQG46WD.js.map → chunk-CPPQCJEV.js.map} +0 -0
  322. /package/dist/{chunk-NUKYY7GO.js.map → chunk-DF3PVTB5.js.map} +0 -0
  323. /package/dist/{chunk-IWNT4XVY.js.map → chunk-GKZK26DZ.js.map} +0 -0
  324. /package/dist/{chunk-IQJOXINX.js.map → chunk-GSWIFV2B.js.map} +0 -0
  325. /package/dist/{chunk-2R6NJR5T.js.map → chunk-LVFMTP5H.js.map} +0 -0
  326. /package/dist/{chunk-U3F7QHXB.js.map → chunk-OCQIWTDC.js.map} +0 -0
  327. /package/dist/{chunk-EQWAYCW3.js.map → chunk-ODJ4QBD5.js.map} +0 -0
  328. /package/dist/{chunk-IWGPVXSI.js.map → chunk-P4EE3QGM.js.map} +0 -0
  329. /package/dist/{chunk-BRST23XX.js.map → chunk-Q2DX6IDH.js.map} +0 -0
@@ -0,0 +1,4035 @@
1
+ import {
2
+ __commonJS,
3
+ __export,
4
+ __require,
5
+ __toESM
6
+ } from "./chunk-WQG2LZMB.js";
7
+
8
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/constants.js
9
+ var require_constants = __commonJS({
10
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/constants.js"(exports, module) {
11
+ "use strict";
12
+ var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
13
+ var hasBlob = typeof Blob !== "undefined";
14
+ if (hasBlob)
15
+ BINARY_TYPES.push("blob");
16
+ module.exports = {
17
+ BINARY_TYPES,
18
+ EMPTY_BUFFER: Buffer.alloc(0),
19
+ GUID: "258EAFA5-E914-47DA-95CA-C5AB0DC85B11",
20
+ hasBlob,
21
+ kForOnEventAttribute: Symbol("kIsForOnEventAttribute"),
22
+ kListener: Symbol("kListener"),
23
+ kStatusCode: Symbol("status-code"),
24
+ kWebSocket: Symbol("websocket"),
25
+ NOOP: () => {
26
+ }
27
+ };
28
+ }
29
+ });
30
+
31
+ // ../../node_modules/.pnpm/node-gyp-build@4.8.0/node_modules/node-gyp-build/node-gyp-build.js
32
+ var require_node_gyp_build = __commonJS({
33
+ "../../node_modules/.pnpm/node-gyp-build@4.8.0/node_modules/node-gyp-build/node-gyp-build.js"(exports, module) {
34
+ var fs = __require("fs");
35
+ var path = __require("path");
36
+ var os = __require("os");
37
+ var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
38
+ var vars = process.config && process.config.variables || {};
39
+ var prebuildsOnly = !!process.env.PREBUILDS_ONLY;
40
+ var abi = process.versions.modules;
41
+ var runtime = isElectron() ? "electron" : isNwjs() ? "node-webkit" : "node";
42
+ var arch = process.env.npm_config_arch || os.arch();
43
+ var platform = process.env.npm_config_platform || os.platform();
44
+ var libc = process.env.LIBC || (isAlpine(platform) ? "musl" : "glibc");
45
+ var armv = process.env.ARM_VERSION || (arch === "arm64" ? "8" : vars.arm_version) || "";
46
+ var uv = (process.versions.uv || "").split(".")[0];
47
+ module.exports = load;
48
+ function load(dir) {
49
+ return runtimeRequire(load.resolve(dir));
50
+ }
51
+ load.resolve = load.path = function(dir) {
52
+ dir = path.resolve(dir || ".");
53
+ try {
54
+ var name = runtimeRequire(path.join(dir, "package.json")).name.toUpperCase().replace(/-/g, "_");
55
+ if (process.env[name + "_PREBUILD"])
56
+ dir = process.env[name + "_PREBUILD"];
57
+ } catch (err) {
58
+ }
59
+ if (!prebuildsOnly) {
60
+ var release = getFirst(path.join(dir, "build/Release"), matchBuild);
61
+ if (release)
62
+ return release;
63
+ var debug = getFirst(path.join(dir, "build/Debug"), matchBuild);
64
+ if (debug)
65
+ return debug;
66
+ }
67
+ var prebuild = resolve(dir);
68
+ if (prebuild)
69
+ return prebuild;
70
+ var nearby = resolve(path.dirname(process.execPath));
71
+ if (nearby)
72
+ return nearby;
73
+ var target = [
74
+ "platform=" + platform,
75
+ "arch=" + arch,
76
+ "runtime=" + runtime,
77
+ "abi=" + abi,
78
+ "uv=" + uv,
79
+ armv ? "armv=" + armv : "",
80
+ "libc=" + libc,
81
+ "node=" + process.versions.node,
82
+ process.versions.electron ? "electron=" + process.versions.electron : "",
83
+ typeof __webpack_require__ === "function" ? "webpack=true" : ""
84
+ // eslint-disable-line
85
+ ].filter(Boolean).join(" ");
86
+ throw new Error("No native build was found for " + target + "\n loaded from: " + dir + "\n");
87
+ function resolve(dir2) {
88
+ var tuples = readdirSync(path.join(dir2, "prebuilds")).map(parseTuple);
89
+ var tuple = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0];
90
+ if (!tuple)
91
+ return;
92
+ var prebuilds = path.join(dir2, "prebuilds", tuple.name);
93
+ var parsed = readdirSync(prebuilds).map(parseTags);
94
+ var candidates = parsed.filter(matchTags(runtime, abi));
95
+ var winner = candidates.sort(compareTags(runtime))[0];
96
+ if (winner)
97
+ return path.join(prebuilds, winner.file);
98
+ }
99
+ };
100
+ function readdirSync(dir) {
101
+ try {
102
+ return fs.readdirSync(dir);
103
+ } catch (err) {
104
+ return [];
105
+ }
106
+ }
107
+ function getFirst(dir, filter) {
108
+ var files = readdirSync(dir).filter(filter);
109
+ return files[0] && path.join(dir, files[0]);
110
+ }
111
+ function matchBuild(name) {
112
+ return /\.node$/.test(name);
113
+ }
114
+ function parseTuple(name) {
115
+ var arr = name.split("-");
116
+ if (arr.length !== 2)
117
+ return;
118
+ var platform2 = arr[0];
119
+ var architectures = arr[1].split("+");
120
+ if (!platform2)
121
+ return;
122
+ if (!architectures.length)
123
+ return;
124
+ if (!architectures.every(Boolean))
125
+ return;
126
+ return { name, platform: platform2, architectures };
127
+ }
128
+ function matchTuple(platform2, arch2) {
129
+ return function(tuple) {
130
+ if (tuple == null)
131
+ return false;
132
+ if (tuple.platform !== platform2)
133
+ return false;
134
+ return tuple.architectures.includes(arch2);
135
+ };
136
+ }
137
+ function compareTuples(a, b) {
138
+ return a.architectures.length - b.architectures.length;
139
+ }
140
+ function parseTags(file) {
141
+ var arr = file.split(".");
142
+ var extension = arr.pop();
143
+ var tags = { file, specificity: 0 };
144
+ if (extension !== "node")
145
+ return;
146
+ for (var i = 0; i < arr.length; i++) {
147
+ var tag = arr[i];
148
+ if (tag === "node" || tag === "electron" || tag === "node-webkit") {
149
+ tags.runtime = tag;
150
+ } else if (tag === "napi") {
151
+ tags.napi = true;
152
+ } else if (tag.slice(0, 3) === "abi") {
153
+ tags.abi = tag.slice(3);
154
+ } else if (tag.slice(0, 2) === "uv") {
155
+ tags.uv = tag.slice(2);
156
+ } else if (tag.slice(0, 4) === "armv") {
157
+ tags.armv = tag.slice(4);
158
+ } else if (tag === "glibc" || tag === "musl") {
159
+ tags.libc = tag;
160
+ } else {
161
+ continue;
162
+ }
163
+ tags.specificity++;
164
+ }
165
+ return tags;
166
+ }
167
+ function matchTags(runtime2, abi2) {
168
+ return function(tags) {
169
+ if (tags == null)
170
+ return false;
171
+ if (tags.runtime && tags.runtime !== runtime2 && !runtimeAgnostic(tags))
172
+ return false;
173
+ if (tags.abi && tags.abi !== abi2 && !tags.napi)
174
+ return false;
175
+ if (tags.uv && tags.uv !== uv)
176
+ return false;
177
+ if (tags.armv && tags.armv !== armv)
178
+ return false;
179
+ if (tags.libc && tags.libc !== libc)
180
+ return false;
181
+ return true;
182
+ };
183
+ }
184
+ function runtimeAgnostic(tags) {
185
+ return tags.runtime === "node" && tags.napi;
186
+ }
187
+ function compareTags(runtime2) {
188
+ return function(a, b) {
189
+ if (a.runtime !== b.runtime) {
190
+ return a.runtime === runtime2 ? -1 : 1;
191
+ } else if (a.abi !== b.abi) {
192
+ return a.abi ? -1 : 1;
193
+ } else if (a.specificity !== b.specificity) {
194
+ return a.specificity > b.specificity ? -1 : 1;
195
+ } else {
196
+ return 0;
197
+ }
198
+ };
199
+ }
200
+ function isNwjs() {
201
+ return !!(process.versions && process.versions.nw);
202
+ }
203
+ function isElectron() {
204
+ if (process.versions && process.versions.electron)
205
+ return true;
206
+ if (process.env.ELECTRON_RUN_AS_NODE)
207
+ return true;
208
+ return typeof window !== "undefined" && window.process && window.process.type === "renderer";
209
+ }
210
+ function isAlpine(platform2) {
211
+ return platform2 === "linux" && fs.existsSync("/etc/alpine-release");
212
+ }
213
+ load.parseTags = parseTags;
214
+ load.matchTags = matchTags;
215
+ load.compareTags = compareTags;
216
+ load.parseTuple = parseTuple;
217
+ load.matchTuple = matchTuple;
218
+ load.compareTuples = compareTuples;
219
+ }
220
+ });
221
+
222
+ // ../../node_modules/.pnpm/node-gyp-build@4.8.0/node_modules/node-gyp-build/index.js
223
+ var require_node_gyp_build2 = __commonJS({
224
+ "../../node_modules/.pnpm/node-gyp-build@4.8.0/node_modules/node-gyp-build/index.js"(exports, module) {
225
+ var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : __require;
226
+ if (typeof runtimeRequire.addon === "function") {
227
+ module.exports = runtimeRequire.addon.bind(runtimeRequire);
228
+ } else {
229
+ module.exports = require_node_gyp_build();
230
+ }
231
+ }
232
+ });
233
+
234
+ // ../../node_modules/.pnpm/bufferutil@4.0.8/node_modules/bufferutil/fallback.js
235
+ var require_fallback = __commonJS({
236
+ "../../node_modules/.pnpm/bufferutil@4.0.8/node_modules/bufferutil/fallback.js"(exports, module) {
237
+ "use strict";
238
+ var mask = (source, mask2, output, offset, length) => {
239
+ for (var i = 0; i < length; i++) {
240
+ output[offset + i] = source[i] ^ mask2[i & 3];
241
+ }
242
+ };
243
+ var unmask = (buffer, mask2) => {
244
+ const length = buffer.length;
245
+ for (var i = 0; i < length; i++) {
246
+ buffer[i] ^= mask2[i & 3];
247
+ }
248
+ };
249
+ module.exports = { mask, unmask };
250
+ }
251
+ });
252
+
253
+ // ../../node_modules/.pnpm/bufferutil@4.0.8/node_modules/bufferutil/index.js
254
+ var require_bufferutil = __commonJS({
255
+ "../../node_modules/.pnpm/bufferutil@4.0.8/node_modules/bufferutil/index.js"(exports, module) {
256
+ "use strict";
257
+ try {
258
+ module.exports = require_node_gyp_build2()(__dirname);
259
+ } catch (e) {
260
+ module.exports = require_fallback();
261
+ }
262
+ }
263
+ });
264
+
265
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/buffer-util.js
266
+ var require_buffer_util = __commonJS({
267
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/buffer-util.js"(exports, module) {
268
+ "use strict";
269
+ var { EMPTY_BUFFER } = require_constants();
270
+ var FastBuffer = Buffer[Symbol.species];
271
+ function concat(list, totalLength) {
272
+ if (list.length === 0)
273
+ return EMPTY_BUFFER;
274
+ if (list.length === 1)
275
+ return list[0];
276
+ const target = Buffer.allocUnsafe(totalLength);
277
+ let offset = 0;
278
+ for (let i = 0; i < list.length; i++) {
279
+ const buf = list[i];
280
+ target.set(buf, offset);
281
+ offset += buf.length;
282
+ }
283
+ if (offset < totalLength) {
284
+ return new FastBuffer(target.buffer, target.byteOffset, offset);
285
+ }
286
+ return target;
287
+ }
288
+ function _mask(source, mask, output, offset, length) {
289
+ for (let i = 0; i < length; i++) {
290
+ output[offset + i] = source[i] ^ mask[i & 3];
291
+ }
292
+ }
293
+ function _unmask(buffer, mask) {
294
+ for (let i = 0; i < buffer.length; i++) {
295
+ buffer[i] ^= mask[i & 3];
296
+ }
297
+ }
298
+ function toArrayBuffer(buf) {
299
+ if (buf.length === buf.buffer.byteLength) {
300
+ return buf.buffer;
301
+ }
302
+ return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.length);
303
+ }
304
+ function toBuffer(data) {
305
+ toBuffer.readOnly = true;
306
+ if (Buffer.isBuffer(data))
307
+ return data;
308
+ let buf;
309
+ if (data instanceof ArrayBuffer) {
310
+ buf = new FastBuffer(data);
311
+ } else if (ArrayBuffer.isView(data)) {
312
+ buf = new FastBuffer(data.buffer, data.byteOffset, data.byteLength);
313
+ } else {
314
+ buf = Buffer.from(data);
315
+ toBuffer.readOnly = false;
316
+ }
317
+ return buf;
318
+ }
319
+ module.exports = {
320
+ concat,
321
+ mask: _mask,
322
+ toArrayBuffer,
323
+ toBuffer,
324
+ unmask: _unmask
325
+ };
326
+ if (!process.env.WS_NO_BUFFER_UTIL) {
327
+ try {
328
+ const bufferUtil = require_bufferutil();
329
+ module.exports.mask = function(source, mask, output, offset, length) {
330
+ if (length < 48)
331
+ _mask(source, mask, output, offset, length);
332
+ else
333
+ bufferUtil.mask(source, mask, output, offset, length);
334
+ };
335
+ module.exports.unmask = function(buffer, mask) {
336
+ if (buffer.length < 32)
337
+ _unmask(buffer, mask);
338
+ else
339
+ bufferUtil.unmask(buffer, mask);
340
+ };
341
+ } catch (e) {
342
+ }
343
+ }
344
+ }
345
+ });
346
+
347
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/limiter.js
348
+ var require_limiter = __commonJS({
349
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/limiter.js"(exports, module) {
350
+ "use strict";
351
+ var kDone = Symbol("kDone");
352
+ var kRun = Symbol("kRun");
353
+ var Limiter = class {
354
+ /**
355
+ * Creates a new `Limiter`.
356
+ *
357
+ * @param {Number} [concurrency=Infinity] The maximum number of jobs allowed
358
+ * to run concurrently
359
+ */
360
+ constructor(concurrency) {
361
+ this[kDone] = () => {
362
+ this.pending--;
363
+ this[kRun]();
364
+ };
365
+ this.concurrency = concurrency || Infinity;
366
+ this.jobs = [];
367
+ this.pending = 0;
368
+ }
369
+ /**
370
+ * Adds a job to the queue.
371
+ *
372
+ * @param {Function} job The job to run
373
+ * @public
374
+ */
375
+ add(job) {
376
+ this.jobs.push(job);
377
+ this[kRun]();
378
+ }
379
+ /**
380
+ * Removes a job from the queue and runs it if possible.
381
+ *
382
+ * @private
383
+ */
384
+ [kRun]() {
385
+ if (this.pending === this.concurrency)
386
+ return;
387
+ if (this.jobs.length) {
388
+ const job = this.jobs.shift();
389
+ this.pending++;
390
+ job(this[kDone]);
391
+ }
392
+ }
393
+ };
394
+ module.exports = Limiter;
395
+ }
396
+ });
397
+
398
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/permessage-deflate.js
399
+ var require_permessage_deflate = __commonJS({
400
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/permessage-deflate.js"(exports, module) {
401
+ "use strict";
402
+ var zlib = __require("zlib");
403
+ var bufferUtil = require_buffer_util();
404
+ var Limiter = require_limiter();
405
+ var { kStatusCode } = require_constants();
406
+ var FastBuffer = Buffer[Symbol.species];
407
+ var TRAILER = Buffer.from([0, 0, 255, 255]);
408
+ var kPerMessageDeflate = Symbol("permessage-deflate");
409
+ var kTotalLength = Symbol("total-length");
410
+ var kCallback = Symbol("callback");
411
+ var kBuffers = Symbol("buffers");
412
+ var kError = Symbol("error");
413
+ var zlibLimiter;
414
+ var PerMessageDeflate = class {
415
+ /**
416
+ * Creates a PerMessageDeflate instance.
417
+ *
418
+ * @param {Object} [options] Configuration options
419
+ * @param {(Boolean|Number)} [options.clientMaxWindowBits] Advertise support
420
+ * for, or request, a custom client window size
421
+ * @param {Boolean} [options.clientNoContextTakeover=false] Advertise/
422
+ * acknowledge disabling of client context takeover
423
+ * @param {Number} [options.concurrencyLimit=10] The number of concurrent
424
+ * calls to zlib
425
+ * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
426
+ * use of a custom server window size
427
+ * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
428
+ * disabling of server context takeover
429
+ * @param {Number} [options.threshold=1024] Size (in bytes) below which
430
+ * messages should not be compressed if context takeover is disabled
431
+ * @param {Object} [options.zlibDeflateOptions] Options to pass to zlib on
432
+ * deflate
433
+ * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
434
+ * inflate
435
+ * @param {Boolean} [isServer=false] Create the instance in either server or
436
+ * client mode
437
+ * @param {Number} [maxPayload=0] The maximum allowed message length
438
+ */
439
+ constructor(options, isServer, maxPayload) {
440
+ this._maxPayload = maxPayload | 0;
441
+ this._options = options || {};
442
+ this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
443
+ this._isServer = !!isServer;
444
+ this._deflate = null;
445
+ this._inflate = null;
446
+ this.params = null;
447
+ if (!zlibLimiter) {
448
+ const concurrency = this._options.concurrencyLimit !== void 0 ? this._options.concurrencyLimit : 10;
449
+ zlibLimiter = new Limiter(concurrency);
450
+ }
451
+ }
452
+ /**
453
+ * @type {String}
454
+ */
455
+ static get extensionName() {
456
+ return "permessage-deflate";
457
+ }
458
+ /**
459
+ * Create an extension negotiation offer.
460
+ *
461
+ * @return {Object} Extension parameters
462
+ * @public
463
+ */
464
+ offer() {
465
+ const params = {};
466
+ if (this._options.serverNoContextTakeover) {
467
+ params.server_no_context_takeover = true;
468
+ }
469
+ if (this._options.clientNoContextTakeover) {
470
+ params.client_no_context_takeover = true;
471
+ }
472
+ if (this._options.serverMaxWindowBits) {
473
+ params.server_max_window_bits = this._options.serverMaxWindowBits;
474
+ }
475
+ if (this._options.clientMaxWindowBits) {
476
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
477
+ } else if (this._options.clientMaxWindowBits == null) {
478
+ params.client_max_window_bits = true;
479
+ }
480
+ return params;
481
+ }
482
+ /**
483
+ * Accept an extension negotiation offer/response.
484
+ *
485
+ * @param {Array} configurations The extension negotiation offers/reponse
486
+ * @return {Object} Accepted configuration
487
+ * @public
488
+ */
489
+ accept(configurations) {
490
+ configurations = this.normalizeParams(configurations);
491
+ this.params = this._isServer ? this.acceptAsServer(configurations) : this.acceptAsClient(configurations);
492
+ return this.params;
493
+ }
494
+ /**
495
+ * Releases all resources used by the extension.
496
+ *
497
+ * @public
498
+ */
499
+ cleanup() {
500
+ if (this._inflate) {
501
+ this._inflate.close();
502
+ this._inflate = null;
503
+ }
504
+ if (this._deflate) {
505
+ const callback = this._deflate[kCallback];
506
+ this._deflate.close();
507
+ this._deflate = null;
508
+ if (callback) {
509
+ callback(
510
+ new Error(
511
+ "The deflate stream was closed while data was being processed"
512
+ )
513
+ );
514
+ }
515
+ }
516
+ }
517
+ /**
518
+ * Accept an extension negotiation offer.
519
+ *
520
+ * @param {Array} offers The extension negotiation offers
521
+ * @return {Object} Accepted configuration
522
+ * @private
523
+ */
524
+ acceptAsServer(offers) {
525
+ const opts = this._options;
526
+ const accepted = offers.find((params) => {
527
+ if (opts.serverNoContextTakeover === false && params.server_no_context_takeover || params.server_max_window_bits && (opts.serverMaxWindowBits === false || typeof opts.serverMaxWindowBits === "number" && opts.serverMaxWindowBits > params.server_max_window_bits) || typeof opts.clientMaxWindowBits === "number" && !params.client_max_window_bits) {
528
+ return false;
529
+ }
530
+ return true;
531
+ });
532
+ if (!accepted) {
533
+ throw new Error("None of the extension offers can be accepted");
534
+ }
535
+ if (opts.serverNoContextTakeover) {
536
+ accepted.server_no_context_takeover = true;
537
+ }
538
+ if (opts.clientNoContextTakeover) {
539
+ accepted.client_no_context_takeover = true;
540
+ }
541
+ if (typeof opts.serverMaxWindowBits === "number") {
542
+ accepted.server_max_window_bits = opts.serverMaxWindowBits;
543
+ }
544
+ if (typeof opts.clientMaxWindowBits === "number") {
545
+ accepted.client_max_window_bits = opts.clientMaxWindowBits;
546
+ } else if (accepted.client_max_window_bits === true || opts.clientMaxWindowBits === false) {
547
+ delete accepted.client_max_window_bits;
548
+ }
549
+ return accepted;
550
+ }
551
+ /**
552
+ * Accept the extension negotiation response.
553
+ *
554
+ * @param {Array} response The extension negotiation response
555
+ * @return {Object} Accepted configuration
556
+ * @private
557
+ */
558
+ acceptAsClient(response) {
559
+ const params = response[0];
560
+ if (this._options.clientNoContextTakeover === false && params.client_no_context_takeover) {
561
+ throw new Error('Unexpected parameter "client_no_context_takeover"');
562
+ }
563
+ if (!params.client_max_window_bits) {
564
+ if (typeof this._options.clientMaxWindowBits === "number") {
565
+ params.client_max_window_bits = this._options.clientMaxWindowBits;
566
+ }
567
+ } else if (this._options.clientMaxWindowBits === false || typeof this._options.clientMaxWindowBits === "number" && params.client_max_window_bits > this._options.clientMaxWindowBits) {
568
+ throw new Error(
569
+ 'Unexpected or invalid parameter "client_max_window_bits"'
570
+ );
571
+ }
572
+ return params;
573
+ }
574
+ /**
575
+ * Normalize parameters.
576
+ *
577
+ * @param {Array} configurations The extension negotiation offers/reponse
578
+ * @return {Array} The offers/response with normalized parameters
579
+ * @private
580
+ */
581
+ normalizeParams(configurations) {
582
+ configurations.forEach((params) => {
583
+ Object.keys(params).forEach((key) => {
584
+ let value = params[key];
585
+ if (value.length > 1) {
586
+ throw new Error(`Parameter "${key}" must have only a single value`);
587
+ }
588
+ value = value[0];
589
+ if (key === "client_max_window_bits") {
590
+ if (value !== true) {
591
+ const num = +value;
592
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
593
+ throw new TypeError(
594
+ `Invalid value for parameter "${key}": ${value}`
595
+ );
596
+ }
597
+ value = num;
598
+ } else if (!this._isServer) {
599
+ throw new TypeError(
600
+ `Invalid value for parameter "${key}": ${value}`
601
+ );
602
+ }
603
+ } else if (key === "server_max_window_bits") {
604
+ const num = +value;
605
+ if (!Number.isInteger(num) || num < 8 || num > 15) {
606
+ throw new TypeError(
607
+ `Invalid value for parameter "${key}": ${value}`
608
+ );
609
+ }
610
+ value = num;
611
+ } else if (key === "client_no_context_takeover" || key === "server_no_context_takeover") {
612
+ if (value !== true) {
613
+ throw new TypeError(
614
+ `Invalid value for parameter "${key}": ${value}`
615
+ );
616
+ }
617
+ } else {
618
+ throw new Error(`Unknown parameter "${key}"`);
619
+ }
620
+ params[key] = value;
621
+ });
622
+ });
623
+ return configurations;
624
+ }
625
+ /**
626
+ * Decompress data. Concurrency limited.
627
+ *
628
+ * @param {Buffer} data Compressed data
629
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
630
+ * @param {Function} callback Callback
631
+ * @public
632
+ */
633
+ decompress(data, fin, callback) {
634
+ zlibLimiter.add((done) => {
635
+ this._decompress(data, fin, (err, result) => {
636
+ done();
637
+ callback(err, result);
638
+ });
639
+ });
640
+ }
641
+ /**
642
+ * Compress data. Concurrency limited.
643
+ *
644
+ * @param {(Buffer|String)} data Data to compress
645
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
646
+ * @param {Function} callback Callback
647
+ * @public
648
+ */
649
+ compress(data, fin, callback) {
650
+ zlibLimiter.add((done) => {
651
+ this._compress(data, fin, (err, result) => {
652
+ done();
653
+ callback(err, result);
654
+ });
655
+ });
656
+ }
657
+ /**
658
+ * Decompress data.
659
+ *
660
+ * @param {Buffer} data Compressed data
661
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
662
+ * @param {Function} callback Callback
663
+ * @private
664
+ */
665
+ _decompress(data, fin, callback) {
666
+ const endpoint = this._isServer ? "client" : "server";
667
+ if (!this._inflate) {
668
+ const key = `${endpoint}_max_window_bits`;
669
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
670
+ this._inflate = zlib.createInflateRaw({
671
+ ...this._options.zlibInflateOptions,
672
+ windowBits
673
+ });
674
+ this._inflate[kPerMessageDeflate] = this;
675
+ this._inflate[kTotalLength] = 0;
676
+ this._inflate[kBuffers] = [];
677
+ this._inflate.on("error", inflateOnError);
678
+ this._inflate.on("data", inflateOnData);
679
+ }
680
+ this._inflate[kCallback] = callback;
681
+ this._inflate.write(data);
682
+ if (fin)
683
+ this._inflate.write(TRAILER);
684
+ this._inflate.flush(() => {
685
+ const err = this._inflate[kError];
686
+ if (err) {
687
+ this._inflate.close();
688
+ this._inflate = null;
689
+ callback(err);
690
+ return;
691
+ }
692
+ const data2 = bufferUtil.concat(
693
+ this._inflate[kBuffers],
694
+ this._inflate[kTotalLength]
695
+ );
696
+ if (this._inflate._readableState.endEmitted) {
697
+ this._inflate.close();
698
+ this._inflate = null;
699
+ } else {
700
+ this._inflate[kTotalLength] = 0;
701
+ this._inflate[kBuffers] = [];
702
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
703
+ this._inflate.reset();
704
+ }
705
+ }
706
+ callback(null, data2);
707
+ });
708
+ }
709
+ /**
710
+ * Compress data.
711
+ *
712
+ * @param {(Buffer|String)} data Data to compress
713
+ * @param {Boolean} fin Specifies whether or not this is the last fragment
714
+ * @param {Function} callback Callback
715
+ * @private
716
+ */
717
+ _compress(data, fin, callback) {
718
+ const endpoint = this._isServer ? "server" : "client";
719
+ if (!this._deflate) {
720
+ const key = `${endpoint}_max_window_bits`;
721
+ const windowBits = typeof this.params[key] !== "number" ? zlib.Z_DEFAULT_WINDOWBITS : this.params[key];
722
+ this._deflate = zlib.createDeflateRaw({
723
+ ...this._options.zlibDeflateOptions,
724
+ windowBits
725
+ });
726
+ this._deflate[kTotalLength] = 0;
727
+ this._deflate[kBuffers] = [];
728
+ this._deflate.on("data", deflateOnData);
729
+ }
730
+ this._deflate[kCallback] = callback;
731
+ this._deflate.write(data);
732
+ this._deflate.flush(zlib.Z_SYNC_FLUSH, () => {
733
+ if (!this._deflate) {
734
+ return;
735
+ }
736
+ let data2 = bufferUtil.concat(
737
+ this._deflate[kBuffers],
738
+ this._deflate[kTotalLength]
739
+ );
740
+ if (fin) {
741
+ data2 = new FastBuffer(data2.buffer, data2.byteOffset, data2.length - 4);
742
+ }
743
+ this._deflate[kCallback] = null;
744
+ this._deflate[kTotalLength] = 0;
745
+ this._deflate[kBuffers] = [];
746
+ if (fin && this.params[`${endpoint}_no_context_takeover`]) {
747
+ this._deflate.reset();
748
+ }
749
+ callback(null, data2);
750
+ });
751
+ }
752
+ };
753
+ module.exports = PerMessageDeflate;
754
+ function deflateOnData(chunk) {
755
+ this[kBuffers].push(chunk);
756
+ this[kTotalLength] += chunk.length;
757
+ }
758
+ function inflateOnData(chunk) {
759
+ this[kTotalLength] += chunk.length;
760
+ if (this[kPerMessageDeflate]._maxPayload < 1 || this[kTotalLength] <= this[kPerMessageDeflate]._maxPayload) {
761
+ this[kBuffers].push(chunk);
762
+ return;
763
+ }
764
+ this[kError] = new RangeError("Max payload size exceeded");
765
+ this[kError].code = "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH";
766
+ this[kError][kStatusCode] = 1009;
767
+ this.removeListener("data", inflateOnData);
768
+ this.reset();
769
+ }
770
+ function inflateOnError(err) {
771
+ this[kPerMessageDeflate]._inflate = null;
772
+ if (this[kError]) {
773
+ this[kCallback](this[kError]);
774
+ return;
775
+ }
776
+ err[kStatusCode] = 1007;
777
+ this[kCallback](err);
778
+ }
779
+ }
780
+ });
781
+
782
+ // ../../node_modules/.pnpm/utf-8-validate@5.0.10/node_modules/utf-8-validate/fallback.js
783
+ var require_fallback2 = __commonJS({
784
+ "../../node_modules/.pnpm/utf-8-validate@5.0.10/node_modules/utf-8-validate/fallback.js"(exports, module) {
785
+ "use strict";
786
+ function isValidUTF8(buf) {
787
+ const len = buf.length;
788
+ let i = 0;
789
+ while (i < len) {
790
+ if ((buf[i] & 128) === 0) {
791
+ i++;
792
+ } else if ((buf[i] & 224) === 192) {
793
+ if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
794
+ return false;
795
+ }
796
+ i += 2;
797
+ } else if ((buf[i] & 240) === 224) {
798
+ if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || // overlong
799
+ buf[i] === 237 && (buf[i + 1] & 224) === 160) {
800
+ return false;
801
+ }
802
+ i += 3;
803
+ } else if ((buf[i] & 248) === 240) {
804
+ if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || // overlong
805
+ buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
806
+ return false;
807
+ }
808
+ i += 4;
809
+ } else {
810
+ return false;
811
+ }
812
+ }
813
+ return true;
814
+ }
815
+ module.exports = isValidUTF8;
816
+ }
817
+ });
818
+
819
+ // ../../node_modules/.pnpm/utf-8-validate@5.0.10/node_modules/utf-8-validate/index.js
820
+ var require_utf_8_validate = __commonJS({
821
+ "../../node_modules/.pnpm/utf-8-validate@5.0.10/node_modules/utf-8-validate/index.js"(exports, module) {
822
+ "use strict";
823
+ try {
824
+ module.exports = require_node_gyp_build2()(__dirname);
825
+ } catch (e) {
826
+ module.exports = require_fallback2();
827
+ }
828
+ }
829
+ });
830
+
831
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/validation.js
832
+ var require_validation = __commonJS({
833
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/validation.js"(exports, module) {
834
+ "use strict";
835
+ var { isUtf8 } = __require("buffer");
836
+ var { hasBlob } = require_constants();
837
+ var tokenChars = [
838
+ 0,
839
+ 0,
840
+ 0,
841
+ 0,
842
+ 0,
843
+ 0,
844
+ 0,
845
+ 0,
846
+ 0,
847
+ 0,
848
+ 0,
849
+ 0,
850
+ 0,
851
+ 0,
852
+ 0,
853
+ 0,
854
+ // 0 - 15
855
+ 0,
856
+ 0,
857
+ 0,
858
+ 0,
859
+ 0,
860
+ 0,
861
+ 0,
862
+ 0,
863
+ 0,
864
+ 0,
865
+ 0,
866
+ 0,
867
+ 0,
868
+ 0,
869
+ 0,
870
+ 0,
871
+ // 16 - 31
872
+ 0,
873
+ 1,
874
+ 0,
875
+ 1,
876
+ 1,
877
+ 1,
878
+ 1,
879
+ 1,
880
+ 0,
881
+ 0,
882
+ 1,
883
+ 1,
884
+ 0,
885
+ 1,
886
+ 1,
887
+ 0,
888
+ // 32 - 47
889
+ 1,
890
+ 1,
891
+ 1,
892
+ 1,
893
+ 1,
894
+ 1,
895
+ 1,
896
+ 1,
897
+ 1,
898
+ 1,
899
+ 0,
900
+ 0,
901
+ 0,
902
+ 0,
903
+ 0,
904
+ 0,
905
+ // 48 - 63
906
+ 0,
907
+ 1,
908
+ 1,
909
+ 1,
910
+ 1,
911
+ 1,
912
+ 1,
913
+ 1,
914
+ 1,
915
+ 1,
916
+ 1,
917
+ 1,
918
+ 1,
919
+ 1,
920
+ 1,
921
+ 1,
922
+ // 64 - 79
923
+ 1,
924
+ 1,
925
+ 1,
926
+ 1,
927
+ 1,
928
+ 1,
929
+ 1,
930
+ 1,
931
+ 1,
932
+ 1,
933
+ 1,
934
+ 0,
935
+ 0,
936
+ 0,
937
+ 1,
938
+ 1,
939
+ // 80 - 95
940
+ 1,
941
+ 1,
942
+ 1,
943
+ 1,
944
+ 1,
945
+ 1,
946
+ 1,
947
+ 1,
948
+ 1,
949
+ 1,
950
+ 1,
951
+ 1,
952
+ 1,
953
+ 1,
954
+ 1,
955
+ 1,
956
+ // 96 - 111
957
+ 1,
958
+ 1,
959
+ 1,
960
+ 1,
961
+ 1,
962
+ 1,
963
+ 1,
964
+ 1,
965
+ 1,
966
+ 1,
967
+ 1,
968
+ 0,
969
+ 1,
970
+ 0,
971
+ 1,
972
+ 0
973
+ // 112 - 127
974
+ ];
975
+ function isValidStatusCode(code) {
976
+ return code >= 1e3 && code <= 1014 && code !== 1004 && code !== 1005 && code !== 1006 || code >= 3e3 && code <= 4999;
977
+ }
978
+ function _isValidUTF8(buf) {
979
+ const len = buf.length;
980
+ let i = 0;
981
+ while (i < len) {
982
+ if ((buf[i] & 128) === 0) {
983
+ i++;
984
+ } else if ((buf[i] & 224) === 192) {
985
+ if (i + 1 === len || (buf[i + 1] & 192) !== 128 || (buf[i] & 254) === 192) {
986
+ return false;
987
+ }
988
+ i += 2;
989
+ } else if ((buf[i] & 240) === 224) {
990
+ if (i + 2 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || buf[i] === 224 && (buf[i + 1] & 224) === 128 || // Overlong
991
+ buf[i] === 237 && (buf[i + 1] & 224) === 160) {
992
+ return false;
993
+ }
994
+ i += 3;
995
+ } else if ((buf[i] & 248) === 240) {
996
+ if (i + 3 >= len || (buf[i + 1] & 192) !== 128 || (buf[i + 2] & 192) !== 128 || (buf[i + 3] & 192) !== 128 || buf[i] === 240 && (buf[i + 1] & 240) === 128 || // Overlong
997
+ buf[i] === 244 && buf[i + 1] > 143 || buf[i] > 244) {
998
+ return false;
999
+ }
1000
+ i += 4;
1001
+ } else {
1002
+ return false;
1003
+ }
1004
+ }
1005
+ return true;
1006
+ }
1007
+ function isBlob(value) {
1008
+ return hasBlob && typeof value === "object" && typeof value.arrayBuffer === "function" && typeof value.type === "string" && typeof value.stream === "function" && (value[Symbol.toStringTag] === "Blob" || value[Symbol.toStringTag] === "File");
1009
+ }
1010
+ module.exports = {
1011
+ isBlob,
1012
+ isValidStatusCode,
1013
+ isValidUTF8: _isValidUTF8,
1014
+ tokenChars
1015
+ };
1016
+ if (isUtf8) {
1017
+ module.exports.isValidUTF8 = function(buf) {
1018
+ return buf.length < 24 ? _isValidUTF8(buf) : isUtf8(buf);
1019
+ };
1020
+ } else if (!process.env.WS_NO_UTF_8_VALIDATE) {
1021
+ try {
1022
+ const isValidUTF8 = require_utf_8_validate();
1023
+ module.exports.isValidUTF8 = function(buf) {
1024
+ return buf.length < 32 ? _isValidUTF8(buf) : isValidUTF8(buf);
1025
+ };
1026
+ } catch (e) {
1027
+ }
1028
+ }
1029
+ }
1030
+ });
1031
+
1032
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/receiver.js
1033
+ var require_receiver = __commonJS({
1034
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/receiver.js"(exports, module) {
1035
+ "use strict";
1036
+ var { Writable } = __require("stream");
1037
+ var PerMessageDeflate = require_permessage_deflate();
1038
+ var {
1039
+ BINARY_TYPES,
1040
+ EMPTY_BUFFER,
1041
+ kStatusCode,
1042
+ kWebSocket
1043
+ } = require_constants();
1044
+ var { concat, toArrayBuffer, unmask } = require_buffer_util();
1045
+ var { isValidStatusCode, isValidUTF8 } = require_validation();
1046
+ var FastBuffer = Buffer[Symbol.species];
1047
+ var GET_INFO = 0;
1048
+ var GET_PAYLOAD_LENGTH_16 = 1;
1049
+ var GET_PAYLOAD_LENGTH_64 = 2;
1050
+ var GET_MASK = 3;
1051
+ var GET_DATA = 4;
1052
+ var INFLATING = 5;
1053
+ var DEFER_EVENT = 6;
1054
+ var Receiver2 = class extends Writable {
1055
+ /**
1056
+ * Creates a Receiver instance.
1057
+ *
1058
+ * @param {Object} [options] Options object
1059
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
1060
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
1061
+ * multiple times in the same tick
1062
+ * @param {String} [options.binaryType=nodebuffer] The type for binary data
1063
+ * @param {Object} [options.extensions] An object containing the negotiated
1064
+ * extensions
1065
+ * @param {Boolean} [options.isServer=false] Specifies whether to operate in
1066
+ * client or server mode
1067
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
1068
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
1069
+ * not to skip UTF-8 validation for text and close messages
1070
+ */
1071
+ constructor(options = {}) {
1072
+ super();
1073
+ this._allowSynchronousEvents = options.allowSynchronousEvents !== void 0 ? options.allowSynchronousEvents : true;
1074
+ this._binaryType = options.binaryType || BINARY_TYPES[0];
1075
+ this._extensions = options.extensions || {};
1076
+ this._isServer = !!options.isServer;
1077
+ this._maxPayload = options.maxPayload | 0;
1078
+ this._skipUTF8Validation = !!options.skipUTF8Validation;
1079
+ this[kWebSocket] = void 0;
1080
+ this._bufferedBytes = 0;
1081
+ this._buffers = [];
1082
+ this._compressed = false;
1083
+ this._payloadLength = 0;
1084
+ this._mask = void 0;
1085
+ this._fragmented = 0;
1086
+ this._masked = false;
1087
+ this._fin = false;
1088
+ this._opcode = 0;
1089
+ this._totalPayloadLength = 0;
1090
+ this._messageLength = 0;
1091
+ this._fragments = [];
1092
+ this._errored = false;
1093
+ this._loop = false;
1094
+ this._state = GET_INFO;
1095
+ }
1096
+ /**
1097
+ * Implements `Writable.prototype._write()`.
1098
+ *
1099
+ * @param {Buffer} chunk The chunk of data to write
1100
+ * @param {String} encoding The character encoding of `chunk`
1101
+ * @param {Function} cb Callback
1102
+ * @private
1103
+ */
1104
+ _write(chunk, encoding, cb) {
1105
+ if (this._opcode === 8 && this._state == GET_INFO)
1106
+ return cb();
1107
+ this._bufferedBytes += chunk.length;
1108
+ this._buffers.push(chunk);
1109
+ this.startLoop(cb);
1110
+ }
1111
+ /**
1112
+ * Consumes `n` bytes from the buffered data.
1113
+ *
1114
+ * @param {Number} n The number of bytes to consume
1115
+ * @return {Buffer} The consumed bytes
1116
+ * @private
1117
+ */
1118
+ consume(n) {
1119
+ this._bufferedBytes -= n;
1120
+ if (n === this._buffers[0].length)
1121
+ return this._buffers.shift();
1122
+ if (n < this._buffers[0].length) {
1123
+ const buf = this._buffers[0];
1124
+ this._buffers[0] = new FastBuffer(
1125
+ buf.buffer,
1126
+ buf.byteOffset + n,
1127
+ buf.length - n
1128
+ );
1129
+ return new FastBuffer(buf.buffer, buf.byteOffset, n);
1130
+ }
1131
+ const dst = Buffer.allocUnsafe(n);
1132
+ do {
1133
+ const buf = this._buffers[0];
1134
+ const offset = dst.length - n;
1135
+ if (n >= buf.length) {
1136
+ dst.set(this._buffers.shift(), offset);
1137
+ } else {
1138
+ dst.set(new Uint8Array(buf.buffer, buf.byteOffset, n), offset);
1139
+ this._buffers[0] = new FastBuffer(
1140
+ buf.buffer,
1141
+ buf.byteOffset + n,
1142
+ buf.length - n
1143
+ );
1144
+ }
1145
+ n -= buf.length;
1146
+ } while (n > 0);
1147
+ return dst;
1148
+ }
1149
+ /**
1150
+ * Starts the parsing loop.
1151
+ *
1152
+ * @param {Function} cb Callback
1153
+ * @private
1154
+ */
1155
+ startLoop(cb) {
1156
+ this._loop = true;
1157
+ do {
1158
+ switch (this._state) {
1159
+ case GET_INFO:
1160
+ this.getInfo(cb);
1161
+ break;
1162
+ case GET_PAYLOAD_LENGTH_16:
1163
+ this.getPayloadLength16(cb);
1164
+ break;
1165
+ case GET_PAYLOAD_LENGTH_64:
1166
+ this.getPayloadLength64(cb);
1167
+ break;
1168
+ case GET_MASK:
1169
+ this.getMask();
1170
+ break;
1171
+ case GET_DATA:
1172
+ this.getData(cb);
1173
+ break;
1174
+ case INFLATING:
1175
+ case DEFER_EVENT:
1176
+ this._loop = false;
1177
+ return;
1178
+ }
1179
+ } while (this._loop);
1180
+ if (!this._errored)
1181
+ cb();
1182
+ }
1183
+ /**
1184
+ * Reads the first two bytes of a frame.
1185
+ *
1186
+ * @param {Function} cb Callback
1187
+ * @private
1188
+ */
1189
+ getInfo(cb) {
1190
+ if (this._bufferedBytes < 2) {
1191
+ this._loop = false;
1192
+ return;
1193
+ }
1194
+ const buf = this.consume(2);
1195
+ if ((buf[0] & 48) !== 0) {
1196
+ const error = this.createError(
1197
+ RangeError,
1198
+ "RSV2 and RSV3 must be clear",
1199
+ true,
1200
+ 1002,
1201
+ "WS_ERR_UNEXPECTED_RSV_2_3"
1202
+ );
1203
+ cb(error);
1204
+ return;
1205
+ }
1206
+ const compressed = (buf[0] & 64) === 64;
1207
+ if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
1208
+ const error = this.createError(
1209
+ RangeError,
1210
+ "RSV1 must be clear",
1211
+ true,
1212
+ 1002,
1213
+ "WS_ERR_UNEXPECTED_RSV_1"
1214
+ );
1215
+ cb(error);
1216
+ return;
1217
+ }
1218
+ this._fin = (buf[0] & 128) === 128;
1219
+ this._opcode = buf[0] & 15;
1220
+ this._payloadLength = buf[1] & 127;
1221
+ if (this._opcode === 0) {
1222
+ if (compressed) {
1223
+ const error = this.createError(
1224
+ RangeError,
1225
+ "RSV1 must be clear",
1226
+ true,
1227
+ 1002,
1228
+ "WS_ERR_UNEXPECTED_RSV_1"
1229
+ );
1230
+ cb(error);
1231
+ return;
1232
+ }
1233
+ if (!this._fragmented) {
1234
+ const error = this.createError(
1235
+ RangeError,
1236
+ "invalid opcode 0",
1237
+ true,
1238
+ 1002,
1239
+ "WS_ERR_INVALID_OPCODE"
1240
+ );
1241
+ cb(error);
1242
+ return;
1243
+ }
1244
+ this._opcode = this._fragmented;
1245
+ } else if (this._opcode === 1 || this._opcode === 2) {
1246
+ if (this._fragmented) {
1247
+ const error = this.createError(
1248
+ RangeError,
1249
+ `invalid opcode ${this._opcode}`,
1250
+ true,
1251
+ 1002,
1252
+ "WS_ERR_INVALID_OPCODE"
1253
+ );
1254
+ cb(error);
1255
+ return;
1256
+ }
1257
+ this._compressed = compressed;
1258
+ } else if (this._opcode > 7 && this._opcode < 11) {
1259
+ if (!this._fin) {
1260
+ const error = this.createError(
1261
+ RangeError,
1262
+ "FIN must be set",
1263
+ true,
1264
+ 1002,
1265
+ "WS_ERR_EXPECTED_FIN"
1266
+ );
1267
+ cb(error);
1268
+ return;
1269
+ }
1270
+ if (compressed) {
1271
+ const error = this.createError(
1272
+ RangeError,
1273
+ "RSV1 must be clear",
1274
+ true,
1275
+ 1002,
1276
+ "WS_ERR_UNEXPECTED_RSV_1"
1277
+ );
1278
+ cb(error);
1279
+ return;
1280
+ }
1281
+ if (this._payloadLength > 125 || this._opcode === 8 && this._payloadLength === 1) {
1282
+ const error = this.createError(
1283
+ RangeError,
1284
+ `invalid payload length ${this._payloadLength}`,
1285
+ true,
1286
+ 1002,
1287
+ "WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH"
1288
+ );
1289
+ cb(error);
1290
+ return;
1291
+ }
1292
+ } else {
1293
+ const error = this.createError(
1294
+ RangeError,
1295
+ `invalid opcode ${this._opcode}`,
1296
+ true,
1297
+ 1002,
1298
+ "WS_ERR_INVALID_OPCODE"
1299
+ );
1300
+ cb(error);
1301
+ return;
1302
+ }
1303
+ if (!this._fin && !this._fragmented)
1304
+ this._fragmented = this._opcode;
1305
+ this._masked = (buf[1] & 128) === 128;
1306
+ if (this._isServer) {
1307
+ if (!this._masked) {
1308
+ const error = this.createError(
1309
+ RangeError,
1310
+ "MASK must be set",
1311
+ true,
1312
+ 1002,
1313
+ "WS_ERR_EXPECTED_MASK"
1314
+ );
1315
+ cb(error);
1316
+ return;
1317
+ }
1318
+ } else if (this._masked) {
1319
+ const error = this.createError(
1320
+ RangeError,
1321
+ "MASK must be clear",
1322
+ true,
1323
+ 1002,
1324
+ "WS_ERR_UNEXPECTED_MASK"
1325
+ );
1326
+ cb(error);
1327
+ return;
1328
+ }
1329
+ if (this._payloadLength === 126)
1330
+ this._state = GET_PAYLOAD_LENGTH_16;
1331
+ else if (this._payloadLength === 127)
1332
+ this._state = GET_PAYLOAD_LENGTH_64;
1333
+ else
1334
+ this.haveLength(cb);
1335
+ }
1336
+ /**
1337
+ * Gets extended payload length (7+16).
1338
+ *
1339
+ * @param {Function} cb Callback
1340
+ * @private
1341
+ */
1342
+ getPayloadLength16(cb) {
1343
+ if (this._bufferedBytes < 2) {
1344
+ this._loop = false;
1345
+ return;
1346
+ }
1347
+ this._payloadLength = this.consume(2).readUInt16BE(0);
1348
+ this.haveLength(cb);
1349
+ }
1350
+ /**
1351
+ * Gets extended payload length (7+64).
1352
+ *
1353
+ * @param {Function} cb Callback
1354
+ * @private
1355
+ */
1356
+ getPayloadLength64(cb) {
1357
+ if (this._bufferedBytes < 8) {
1358
+ this._loop = false;
1359
+ return;
1360
+ }
1361
+ const buf = this.consume(8);
1362
+ const num = buf.readUInt32BE(0);
1363
+ if (num > Math.pow(2, 53 - 32) - 1) {
1364
+ const error = this.createError(
1365
+ RangeError,
1366
+ "Unsupported WebSocket frame: payload length > 2^53 - 1",
1367
+ false,
1368
+ 1009,
1369
+ "WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH"
1370
+ );
1371
+ cb(error);
1372
+ return;
1373
+ }
1374
+ this._payloadLength = num * Math.pow(2, 32) + buf.readUInt32BE(4);
1375
+ this.haveLength(cb);
1376
+ }
1377
+ /**
1378
+ * Payload length has been read.
1379
+ *
1380
+ * @param {Function} cb Callback
1381
+ * @private
1382
+ */
1383
+ haveLength(cb) {
1384
+ if (this._payloadLength && this._opcode < 8) {
1385
+ this._totalPayloadLength += this._payloadLength;
1386
+ if (this._totalPayloadLength > this._maxPayload && this._maxPayload > 0) {
1387
+ const error = this.createError(
1388
+ RangeError,
1389
+ "Max payload size exceeded",
1390
+ false,
1391
+ 1009,
1392
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1393
+ );
1394
+ cb(error);
1395
+ return;
1396
+ }
1397
+ }
1398
+ if (this._masked)
1399
+ this._state = GET_MASK;
1400
+ else
1401
+ this._state = GET_DATA;
1402
+ }
1403
+ /**
1404
+ * Reads mask bytes.
1405
+ *
1406
+ * @private
1407
+ */
1408
+ getMask() {
1409
+ if (this._bufferedBytes < 4) {
1410
+ this._loop = false;
1411
+ return;
1412
+ }
1413
+ this._mask = this.consume(4);
1414
+ this._state = GET_DATA;
1415
+ }
1416
+ /**
1417
+ * Reads data bytes.
1418
+ *
1419
+ * @param {Function} cb Callback
1420
+ * @private
1421
+ */
1422
+ getData(cb) {
1423
+ let data = EMPTY_BUFFER;
1424
+ if (this._payloadLength) {
1425
+ if (this._bufferedBytes < this._payloadLength) {
1426
+ this._loop = false;
1427
+ return;
1428
+ }
1429
+ data = this.consume(this._payloadLength);
1430
+ if (this._masked && (this._mask[0] | this._mask[1] | this._mask[2] | this._mask[3]) !== 0) {
1431
+ unmask(data, this._mask);
1432
+ }
1433
+ }
1434
+ if (this._opcode > 7) {
1435
+ this.controlMessage(data, cb);
1436
+ return;
1437
+ }
1438
+ if (this._compressed) {
1439
+ this._state = INFLATING;
1440
+ this.decompress(data, cb);
1441
+ return;
1442
+ }
1443
+ if (data.length) {
1444
+ this._messageLength = this._totalPayloadLength;
1445
+ this._fragments.push(data);
1446
+ }
1447
+ this.dataMessage(cb);
1448
+ }
1449
+ /**
1450
+ * Decompresses data.
1451
+ *
1452
+ * @param {Buffer} data Compressed data
1453
+ * @param {Function} cb Callback
1454
+ * @private
1455
+ */
1456
+ decompress(data, cb) {
1457
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1458
+ perMessageDeflate.decompress(data, this._fin, (err, buf) => {
1459
+ if (err)
1460
+ return cb(err);
1461
+ if (buf.length) {
1462
+ this._messageLength += buf.length;
1463
+ if (this._messageLength > this._maxPayload && this._maxPayload > 0) {
1464
+ const error = this.createError(
1465
+ RangeError,
1466
+ "Max payload size exceeded",
1467
+ false,
1468
+ 1009,
1469
+ "WS_ERR_UNSUPPORTED_MESSAGE_LENGTH"
1470
+ );
1471
+ cb(error);
1472
+ return;
1473
+ }
1474
+ this._fragments.push(buf);
1475
+ }
1476
+ this.dataMessage(cb);
1477
+ if (this._state === GET_INFO)
1478
+ this.startLoop(cb);
1479
+ });
1480
+ }
1481
+ /**
1482
+ * Handles a data message.
1483
+ *
1484
+ * @param {Function} cb Callback
1485
+ * @private
1486
+ */
1487
+ dataMessage(cb) {
1488
+ if (!this._fin) {
1489
+ this._state = GET_INFO;
1490
+ return;
1491
+ }
1492
+ const messageLength = this._messageLength;
1493
+ const fragments = this._fragments;
1494
+ this._totalPayloadLength = 0;
1495
+ this._messageLength = 0;
1496
+ this._fragmented = 0;
1497
+ this._fragments = [];
1498
+ if (this._opcode === 2) {
1499
+ let data;
1500
+ if (this._binaryType === "nodebuffer") {
1501
+ data = concat(fragments, messageLength);
1502
+ } else if (this._binaryType === "arraybuffer") {
1503
+ data = toArrayBuffer(concat(fragments, messageLength));
1504
+ } else if (this._binaryType === "blob") {
1505
+ data = new Blob(fragments);
1506
+ } else {
1507
+ data = fragments;
1508
+ }
1509
+ if (this._allowSynchronousEvents) {
1510
+ this.emit("message", data, true);
1511
+ this._state = GET_INFO;
1512
+ } else {
1513
+ this._state = DEFER_EVENT;
1514
+ setImmediate(() => {
1515
+ this.emit("message", data, true);
1516
+ this._state = GET_INFO;
1517
+ this.startLoop(cb);
1518
+ });
1519
+ }
1520
+ } else {
1521
+ const buf = concat(fragments, messageLength);
1522
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1523
+ const error = this.createError(
1524
+ Error,
1525
+ "invalid UTF-8 sequence",
1526
+ true,
1527
+ 1007,
1528
+ "WS_ERR_INVALID_UTF8"
1529
+ );
1530
+ cb(error);
1531
+ return;
1532
+ }
1533
+ if (this._state === INFLATING || this._allowSynchronousEvents) {
1534
+ this.emit("message", buf, false);
1535
+ this._state = GET_INFO;
1536
+ } else {
1537
+ this._state = DEFER_EVENT;
1538
+ setImmediate(() => {
1539
+ this.emit("message", buf, false);
1540
+ this._state = GET_INFO;
1541
+ this.startLoop(cb);
1542
+ });
1543
+ }
1544
+ }
1545
+ }
1546
+ /**
1547
+ * Handles a control message.
1548
+ *
1549
+ * @param {Buffer} data Data to handle
1550
+ * @return {(Error|RangeError|undefined)} A possible error
1551
+ * @private
1552
+ */
1553
+ controlMessage(data, cb) {
1554
+ if (this._opcode === 8) {
1555
+ if (data.length === 0) {
1556
+ this._loop = false;
1557
+ this.emit("conclude", 1005, EMPTY_BUFFER);
1558
+ this.end();
1559
+ } else {
1560
+ const code = data.readUInt16BE(0);
1561
+ if (!isValidStatusCode(code)) {
1562
+ const error = this.createError(
1563
+ RangeError,
1564
+ `invalid status code ${code}`,
1565
+ true,
1566
+ 1002,
1567
+ "WS_ERR_INVALID_CLOSE_CODE"
1568
+ );
1569
+ cb(error);
1570
+ return;
1571
+ }
1572
+ const buf = new FastBuffer(
1573
+ data.buffer,
1574
+ data.byteOffset + 2,
1575
+ data.length - 2
1576
+ );
1577
+ if (!this._skipUTF8Validation && !isValidUTF8(buf)) {
1578
+ const error = this.createError(
1579
+ Error,
1580
+ "invalid UTF-8 sequence",
1581
+ true,
1582
+ 1007,
1583
+ "WS_ERR_INVALID_UTF8"
1584
+ );
1585
+ cb(error);
1586
+ return;
1587
+ }
1588
+ this._loop = false;
1589
+ this.emit("conclude", code, buf);
1590
+ this.end();
1591
+ }
1592
+ this._state = GET_INFO;
1593
+ return;
1594
+ }
1595
+ if (this._allowSynchronousEvents) {
1596
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1597
+ this._state = GET_INFO;
1598
+ } else {
1599
+ this._state = DEFER_EVENT;
1600
+ setImmediate(() => {
1601
+ this.emit(this._opcode === 9 ? "ping" : "pong", data);
1602
+ this._state = GET_INFO;
1603
+ this.startLoop(cb);
1604
+ });
1605
+ }
1606
+ }
1607
+ /**
1608
+ * Builds an error object.
1609
+ *
1610
+ * @param {function(new:Error|RangeError)} ErrorCtor The error constructor
1611
+ * @param {String} message The error message
1612
+ * @param {Boolean} prefix Specifies whether or not to add a default prefix to
1613
+ * `message`
1614
+ * @param {Number} statusCode The status code
1615
+ * @param {String} errorCode The exposed error code
1616
+ * @return {(Error|RangeError)} The error
1617
+ * @private
1618
+ */
1619
+ createError(ErrorCtor, message, prefix, statusCode, errorCode) {
1620
+ this._loop = false;
1621
+ this._errored = true;
1622
+ const err = new ErrorCtor(
1623
+ prefix ? `Invalid WebSocket frame: ${message}` : message
1624
+ );
1625
+ Error.captureStackTrace(err, this.createError);
1626
+ err.code = errorCode;
1627
+ err[kStatusCode] = statusCode;
1628
+ return err;
1629
+ }
1630
+ };
1631
+ module.exports = Receiver2;
1632
+ }
1633
+ });
1634
+
1635
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/sender.js
1636
+ var require_sender = __commonJS({
1637
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/sender.js"(exports, module) {
1638
+ "use strict";
1639
+ var { Duplex } = __require("stream");
1640
+ var { randomFillSync } = __require("crypto");
1641
+ var PerMessageDeflate = require_permessage_deflate();
1642
+ var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
1643
+ var { isBlob, isValidStatusCode } = require_validation();
1644
+ var { mask: applyMask, toBuffer } = require_buffer_util();
1645
+ var kByteLength = Symbol("kByteLength");
1646
+ var maskBuffer = Buffer.alloc(4);
1647
+ var RANDOM_POOL_SIZE = 8 * 1024;
1648
+ var randomPool;
1649
+ var randomPoolPointer = RANDOM_POOL_SIZE;
1650
+ var DEFAULT = 0;
1651
+ var DEFLATING = 1;
1652
+ var GET_BLOB_DATA = 2;
1653
+ var Sender2 = class {
1654
+ /**
1655
+ * Creates a Sender instance.
1656
+ *
1657
+ * @param {Duplex} socket The connection socket
1658
+ * @param {Object} [extensions] An object containing the negotiated extensions
1659
+ * @param {Function} [generateMask] The function used to generate the masking
1660
+ * key
1661
+ */
1662
+ constructor(socket, extensions, generateMask) {
1663
+ this._extensions = extensions || {};
1664
+ if (generateMask) {
1665
+ this._generateMask = generateMask;
1666
+ this._maskBuffer = Buffer.alloc(4);
1667
+ }
1668
+ this._socket = socket;
1669
+ this._firstFragment = true;
1670
+ this._compress = false;
1671
+ this._bufferedBytes = 0;
1672
+ this._queue = [];
1673
+ this._state = DEFAULT;
1674
+ this.onerror = NOOP;
1675
+ this[kWebSocket] = void 0;
1676
+ }
1677
+ /**
1678
+ * Frames a piece of data according to the HyBi WebSocket protocol.
1679
+ *
1680
+ * @param {(Buffer|String)} data The data to frame
1681
+ * @param {Object} options Options object
1682
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1683
+ * FIN bit
1684
+ * @param {Function} [options.generateMask] The function used to generate the
1685
+ * masking key
1686
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1687
+ * `data`
1688
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1689
+ * key
1690
+ * @param {Number} options.opcode The opcode
1691
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1692
+ * modified
1693
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1694
+ * RSV1 bit
1695
+ * @return {(Buffer|String)[]} The framed data
1696
+ * @public
1697
+ */
1698
+ static frame(data, options) {
1699
+ let mask;
1700
+ let merge = false;
1701
+ let offset = 2;
1702
+ let skipMasking = false;
1703
+ if (options.mask) {
1704
+ mask = options.maskBuffer || maskBuffer;
1705
+ if (options.generateMask) {
1706
+ options.generateMask(mask);
1707
+ } else {
1708
+ if (randomPoolPointer === RANDOM_POOL_SIZE) {
1709
+ if (randomPool === void 0) {
1710
+ randomPool = Buffer.alloc(RANDOM_POOL_SIZE);
1711
+ }
1712
+ randomFillSync(randomPool, 0, RANDOM_POOL_SIZE);
1713
+ randomPoolPointer = 0;
1714
+ }
1715
+ mask[0] = randomPool[randomPoolPointer++];
1716
+ mask[1] = randomPool[randomPoolPointer++];
1717
+ mask[2] = randomPool[randomPoolPointer++];
1718
+ mask[3] = randomPool[randomPoolPointer++];
1719
+ }
1720
+ skipMasking = (mask[0] | mask[1] | mask[2] | mask[3]) === 0;
1721
+ offset = 6;
1722
+ }
1723
+ let dataLength;
1724
+ if (typeof data === "string") {
1725
+ if ((!options.mask || skipMasking) && options[kByteLength] !== void 0) {
1726
+ dataLength = options[kByteLength];
1727
+ } else {
1728
+ data = Buffer.from(data);
1729
+ dataLength = data.length;
1730
+ }
1731
+ } else {
1732
+ dataLength = data.length;
1733
+ merge = options.mask && options.readOnly && !skipMasking;
1734
+ }
1735
+ let payloadLength = dataLength;
1736
+ if (dataLength >= 65536) {
1737
+ offset += 8;
1738
+ payloadLength = 127;
1739
+ } else if (dataLength > 125) {
1740
+ offset += 2;
1741
+ payloadLength = 126;
1742
+ }
1743
+ const target = Buffer.allocUnsafe(merge ? dataLength + offset : offset);
1744
+ target[0] = options.fin ? options.opcode | 128 : options.opcode;
1745
+ if (options.rsv1)
1746
+ target[0] |= 64;
1747
+ target[1] = payloadLength;
1748
+ if (payloadLength === 126) {
1749
+ target.writeUInt16BE(dataLength, 2);
1750
+ } else if (payloadLength === 127) {
1751
+ target[2] = target[3] = 0;
1752
+ target.writeUIntBE(dataLength, 4, 6);
1753
+ }
1754
+ if (!options.mask)
1755
+ return [target, data];
1756
+ target[1] |= 128;
1757
+ target[offset - 4] = mask[0];
1758
+ target[offset - 3] = mask[1];
1759
+ target[offset - 2] = mask[2];
1760
+ target[offset - 1] = mask[3];
1761
+ if (skipMasking)
1762
+ return [target, data];
1763
+ if (merge) {
1764
+ applyMask(data, mask, target, offset, dataLength);
1765
+ return [target];
1766
+ }
1767
+ applyMask(data, mask, data, 0, dataLength);
1768
+ return [target, data];
1769
+ }
1770
+ /**
1771
+ * Sends a close message to the other peer.
1772
+ *
1773
+ * @param {Number} [code] The status code component of the body
1774
+ * @param {(String|Buffer)} [data] The message component of the body
1775
+ * @param {Boolean} [mask=false] Specifies whether or not to mask the message
1776
+ * @param {Function} [cb] Callback
1777
+ * @public
1778
+ */
1779
+ close(code, data, mask, cb) {
1780
+ let buf;
1781
+ if (code === void 0) {
1782
+ buf = EMPTY_BUFFER;
1783
+ } else if (typeof code !== "number" || !isValidStatusCode(code)) {
1784
+ throw new TypeError("First argument must be a valid error code number");
1785
+ } else if (data === void 0 || !data.length) {
1786
+ buf = Buffer.allocUnsafe(2);
1787
+ buf.writeUInt16BE(code, 0);
1788
+ } else {
1789
+ const length = Buffer.byteLength(data);
1790
+ if (length > 123) {
1791
+ throw new RangeError("The message must not be greater than 123 bytes");
1792
+ }
1793
+ buf = Buffer.allocUnsafe(2 + length);
1794
+ buf.writeUInt16BE(code, 0);
1795
+ if (typeof data === "string") {
1796
+ buf.write(data, 2);
1797
+ } else {
1798
+ buf.set(data, 2);
1799
+ }
1800
+ }
1801
+ const options = {
1802
+ [kByteLength]: buf.length,
1803
+ fin: true,
1804
+ generateMask: this._generateMask,
1805
+ mask,
1806
+ maskBuffer: this._maskBuffer,
1807
+ opcode: 8,
1808
+ readOnly: false,
1809
+ rsv1: false
1810
+ };
1811
+ if (this._state !== DEFAULT) {
1812
+ this.enqueue([this.dispatch, buf, false, options, cb]);
1813
+ } else {
1814
+ this.sendFrame(Sender2.frame(buf, options), cb);
1815
+ }
1816
+ }
1817
+ /**
1818
+ * Sends a ping message to the other peer.
1819
+ *
1820
+ * @param {*} data The message to send
1821
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1822
+ * @param {Function} [cb] Callback
1823
+ * @public
1824
+ */
1825
+ ping(data, mask, cb) {
1826
+ let byteLength;
1827
+ let readOnly;
1828
+ if (typeof data === "string") {
1829
+ byteLength = Buffer.byteLength(data);
1830
+ readOnly = false;
1831
+ } else if (isBlob(data)) {
1832
+ byteLength = data.size;
1833
+ readOnly = false;
1834
+ } else {
1835
+ data = toBuffer(data);
1836
+ byteLength = data.length;
1837
+ readOnly = toBuffer.readOnly;
1838
+ }
1839
+ if (byteLength > 125) {
1840
+ throw new RangeError("The data size must not be greater than 125 bytes");
1841
+ }
1842
+ const options = {
1843
+ [kByteLength]: byteLength,
1844
+ fin: true,
1845
+ generateMask: this._generateMask,
1846
+ mask,
1847
+ maskBuffer: this._maskBuffer,
1848
+ opcode: 9,
1849
+ readOnly,
1850
+ rsv1: false
1851
+ };
1852
+ if (isBlob(data)) {
1853
+ if (this._state !== DEFAULT) {
1854
+ this.enqueue([this.getBlobData, data, false, options, cb]);
1855
+ } else {
1856
+ this.getBlobData(data, false, options, cb);
1857
+ }
1858
+ } else if (this._state !== DEFAULT) {
1859
+ this.enqueue([this.dispatch, data, false, options, cb]);
1860
+ } else {
1861
+ this.sendFrame(Sender2.frame(data, options), cb);
1862
+ }
1863
+ }
1864
+ /**
1865
+ * Sends a pong message to the other peer.
1866
+ *
1867
+ * @param {*} data The message to send
1868
+ * @param {Boolean} [mask=false] Specifies whether or not to mask `data`
1869
+ * @param {Function} [cb] Callback
1870
+ * @public
1871
+ */
1872
+ pong(data, mask, cb) {
1873
+ let byteLength;
1874
+ let readOnly;
1875
+ if (typeof data === "string") {
1876
+ byteLength = Buffer.byteLength(data);
1877
+ readOnly = false;
1878
+ } else if (isBlob(data)) {
1879
+ byteLength = data.size;
1880
+ readOnly = false;
1881
+ } else {
1882
+ data = toBuffer(data);
1883
+ byteLength = data.length;
1884
+ readOnly = toBuffer.readOnly;
1885
+ }
1886
+ if (byteLength > 125) {
1887
+ throw new RangeError("The data size must not be greater than 125 bytes");
1888
+ }
1889
+ const options = {
1890
+ [kByteLength]: byteLength,
1891
+ fin: true,
1892
+ generateMask: this._generateMask,
1893
+ mask,
1894
+ maskBuffer: this._maskBuffer,
1895
+ opcode: 10,
1896
+ readOnly,
1897
+ rsv1: false
1898
+ };
1899
+ if (isBlob(data)) {
1900
+ if (this._state !== DEFAULT) {
1901
+ this.enqueue([this.getBlobData, data, false, options, cb]);
1902
+ } else {
1903
+ this.getBlobData(data, false, options, cb);
1904
+ }
1905
+ } else if (this._state !== DEFAULT) {
1906
+ this.enqueue([this.dispatch, data, false, options, cb]);
1907
+ } else {
1908
+ this.sendFrame(Sender2.frame(data, options), cb);
1909
+ }
1910
+ }
1911
+ /**
1912
+ * Sends a data message to the other peer.
1913
+ *
1914
+ * @param {*} data The message to send
1915
+ * @param {Object} options Options object
1916
+ * @param {Boolean} [options.binary=false] Specifies whether `data` is binary
1917
+ * or text
1918
+ * @param {Boolean} [options.compress=false] Specifies whether or not to
1919
+ * compress `data`
1920
+ * @param {Boolean} [options.fin=false] Specifies whether the fragment is the
1921
+ * last one
1922
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1923
+ * `data`
1924
+ * @param {Function} [cb] Callback
1925
+ * @public
1926
+ */
1927
+ send(data, options, cb) {
1928
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1929
+ let opcode = options.binary ? 2 : 1;
1930
+ let rsv1 = options.compress;
1931
+ let byteLength;
1932
+ let readOnly;
1933
+ if (typeof data === "string") {
1934
+ byteLength = Buffer.byteLength(data);
1935
+ readOnly = false;
1936
+ } else if (isBlob(data)) {
1937
+ byteLength = data.size;
1938
+ readOnly = false;
1939
+ } else {
1940
+ data = toBuffer(data);
1941
+ byteLength = data.length;
1942
+ readOnly = toBuffer.readOnly;
1943
+ }
1944
+ if (this._firstFragment) {
1945
+ this._firstFragment = false;
1946
+ if (rsv1 && perMessageDeflate && perMessageDeflate.params[perMessageDeflate._isServer ? "server_no_context_takeover" : "client_no_context_takeover"]) {
1947
+ rsv1 = byteLength >= perMessageDeflate._threshold;
1948
+ }
1949
+ this._compress = rsv1;
1950
+ } else {
1951
+ rsv1 = false;
1952
+ opcode = 0;
1953
+ }
1954
+ if (options.fin)
1955
+ this._firstFragment = true;
1956
+ const opts = {
1957
+ [kByteLength]: byteLength,
1958
+ fin: options.fin,
1959
+ generateMask: this._generateMask,
1960
+ mask: options.mask,
1961
+ maskBuffer: this._maskBuffer,
1962
+ opcode,
1963
+ readOnly,
1964
+ rsv1
1965
+ };
1966
+ if (isBlob(data)) {
1967
+ if (this._state !== DEFAULT) {
1968
+ this.enqueue([this.getBlobData, data, this._compress, opts, cb]);
1969
+ } else {
1970
+ this.getBlobData(data, this._compress, opts, cb);
1971
+ }
1972
+ } else if (this._state !== DEFAULT) {
1973
+ this.enqueue([this.dispatch, data, this._compress, opts, cb]);
1974
+ } else {
1975
+ this.dispatch(data, this._compress, opts, cb);
1976
+ }
1977
+ }
1978
+ /**
1979
+ * Gets the contents of a blob as binary data.
1980
+ *
1981
+ * @param {Blob} blob The blob
1982
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
1983
+ * the data
1984
+ * @param {Object} options Options object
1985
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
1986
+ * FIN bit
1987
+ * @param {Function} [options.generateMask] The function used to generate the
1988
+ * masking key
1989
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
1990
+ * `data`
1991
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
1992
+ * key
1993
+ * @param {Number} options.opcode The opcode
1994
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
1995
+ * modified
1996
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
1997
+ * RSV1 bit
1998
+ * @param {Function} [cb] Callback
1999
+ * @private
2000
+ */
2001
+ getBlobData(blob, compress, options, cb) {
2002
+ this._bufferedBytes += options[kByteLength];
2003
+ this._state = GET_BLOB_DATA;
2004
+ blob.arrayBuffer().then((arrayBuffer) => {
2005
+ if (this._socket.destroyed) {
2006
+ const err = new Error(
2007
+ "The socket was closed while the blob was being read"
2008
+ );
2009
+ process.nextTick(callCallbacks, this, err, cb);
2010
+ return;
2011
+ }
2012
+ this._bufferedBytes -= options[kByteLength];
2013
+ const data = toBuffer(arrayBuffer);
2014
+ if (!compress) {
2015
+ this._state = DEFAULT;
2016
+ this.sendFrame(Sender2.frame(data, options), cb);
2017
+ this.dequeue();
2018
+ } else {
2019
+ this.dispatch(data, compress, options, cb);
2020
+ }
2021
+ }).catch((err) => {
2022
+ process.nextTick(onError, this, err, cb);
2023
+ });
2024
+ }
2025
+ /**
2026
+ * Dispatches a message.
2027
+ *
2028
+ * @param {(Buffer|String)} data The message to send
2029
+ * @param {Boolean} [compress=false] Specifies whether or not to compress
2030
+ * `data`
2031
+ * @param {Object} options Options object
2032
+ * @param {Boolean} [options.fin=false] Specifies whether or not to set the
2033
+ * FIN bit
2034
+ * @param {Function} [options.generateMask] The function used to generate the
2035
+ * masking key
2036
+ * @param {Boolean} [options.mask=false] Specifies whether or not to mask
2037
+ * `data`
2038
+ * @param {Buffer} [options.maskBuffer] The buffer used to store the masking
2039
+ * key
2040
+ * @param {Number} options.opcode The opcode
2041
+ * @param {Boolean} [options.readOnly=false] Specifies whether `data` can be
2042
+ * modified
2043
+ * @param {Boolean} [options.rsv1=false] Specifies whether or not to set the
2044
+ * RSV1 bit
2045
+ * @param {Function} [cb] Callback
2046
+ * @private
2047
+ */
2048
+ dispatch(data, compress, options, cb) {
2049
+ if (!compress) {
2050
+ this.sendFrame(Sender2.frame(data, options), cb);
2051
+ return;
2052
+ }
2053
+ const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
2054
+ this._bufferedBytes += options[kByteLength];
2055
+ this._state = DEFLATING;
2056
+ perMessageDeflate.compress(data, options.fin, (_, buf) => {
2057
+ if (this._socket.destroyed) {
2058
+ const err = new Error(
2059
+ "The socket was closed while data was being compressed"
2060
+ );
2061
+ callCallbacks(this, err, cb);
2062
+ return;
2063
+ }
2064
+ this._bufferedBytes -= options[kByteLength];
2065
+ this._state = DEFAULT;
2066
+ options.readOnly = false;
2067
+ this.sendFrame(Sender2.frame(buf, options), cb);
2068
+ this.dequeue();
2069
+ });
2070
+ }
2071
+ /**
2072
+ * Executes queued send operations.
2073
+ *
2074
+ * @private
2075
+ */
2076
+ dequeue() {
2077
+ while (this._state === DEFAULT && this._queue.length) {
2078
+ const params = this._queue.shift();
2079
+ this._bufferedBytes -= params[3][kByteLength];
2080
+ Reflect.apply(params[0], this, params.slice(1));
2081
+ }
2082
+ }
2083
+ /**
2084
+ * Enqueues a send operation.
2085
+ *
2086
+ * @param {Array} params Send operation parameters.
2087
+ * @private
2088
+ */
2089
+ enqueue(params) {
2090
+ this._bufferedBytes += params[3][kByteLength];
2091
+ this._queue.push(params);
2092
+ }
2093
+ /**
2094
+ * Sends a frame.
2095
+ *
2096
+ * @param {(Buffer | String)[]} list The frame to send
2097
+ * @param {Function} [cb] Callback
2098
+ * @private
2099
+ */
2100
+ sendFrame(list, cb) {
2101
+ if (list.length === 2) {
2102
+ this._socket.cork();
2103
+ this._socket.write(list[0]);
2104
+ this._socket.write(list[1], cb);
2105
+ this._socket.uncork();
2106
+ } else {
2107
+ this._socket.write(list[0], cb);
2108
+ }
2109
+ }
2110
+ };
2111
+ module.exports = Sender2;
2112
+ function callCallbacks(sender, err, cb) {
2113
+ if (typeof cb === "function")
2114
+ cb(err);
2115
+ for (let i = 0; i < sender._queue.length; i++) {
2116
+ const params = sender._queue[i];
2117
+ const callback = params[params.length - 1];
2118
+ if (typeof callback === "function")
2119
+ callback(err);
2120
+ }
2121
+ }
2122
+ function onError(sender, err, cb) {
2123
+ callCallbacks(sender, err, cb);
2124
+ sender.onerror(err);
2125
+ }
2126
+ }
2127
+ });
2128
+
2129
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/event-target.js
2130
+ var require_event_target = __commonJS({
2131
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/event-target.js"(exports, module) {
2132
+ "use strict";
2133
+ var { kForOnEventAttribute, kListener } = require_constants();
2134
+ var kCode = Symbol("kCode");
2135
+ var kData = Symbol("kData");
2136
+ var kError = Symbol("kError");
2137
+ var kMessage = Symbol("kMessage");
2138
+ var kReason = Symbol("kReason");
2139
+ var kTarget = Symbol("kTarget");
2140
+ var kType = Symbol("kType");
2141
+ var kWasClean = Symbol("kWasClean");
2142
+ var Event = class {
2143
+ /**
2144
+ * Create a new `Event`.
2145
+ *
2146
+ * @param {String} type The name of the event
2147
+ * @throws {TypeError} If the `type` argument is not specified
2148
+ */
2149
+ constructor(type) {
2150
+ this[kTarget] = null;
2151
+ this[kType] = type;
2152
+ }
2153
+ /**
2154
+ * @type {*}
2155
+ */
2156
+ get target() {
2157
+ return this[kTarget];
2158
+ }
2159
+ /**
2160
+ * @type {String}
2161
+ */
2162
+ get type() {
2163
+ return this[kType];
2164
+ }
2165
+ };
2166
+ Object.defineProperty(Event.prototype, "target", { enumerable: true });
2167
+ Object.defineProperty(Event.prototype, "type", { enumerable: true });
2168
+ var CloseEvent = class extends Event {
2169
+ /**
2170
+ * Create a new `CloseEvent`.
2171
+ *
2172
+ * @param {String} type The name of the event
2173
+ * @param {Object} [options] A dictionary object that allows for setting
2174
+ * attributes via object members of the same name
2175
+ * @param {Number} [options.code=0] The status code explaining why the
2176
+ * connection was closed
2177
+ * @param {String} [options.reason=''] A human-readable string explaining why
2178
+ * the connection was closed
2179
+ * @param {Boolean} [options.wasClean=false] Indicates whether or not the
2180
+ * connection was cleanly closed
2181
+ */
2182
+ constructor(type, options = {}) {
2183
+ super(type);
2184
+ this[kCode] = options.code === void 0 ? 0 : options.code;
2185
+ this[kReason] = options.reason === void 0 ? "" : options.reason;
2186
+ this[kWasClean] = options.wasClean === void 0 ? false : options.wasClean;
2187
+ }
2188
+ /**
2189
+ * @type {Number}
2190
+ */
2191
+ get code() {
2192
+ return this[kCode];
2193
+ }
2194
+ /**
2195
+ * @type {String}
2196
+ */
2197
+ get reason() {
2198
+ return this[kReason];
2199
+ }
2200
+ /**
2201
+ * @type {Boolean}
2202
+ */
2203
+ get wasClean() {
2204
+ return this[kWasClean];
2205
+ }
2206
+ };
2207
+ Object.defineProperty(CloseEvent.prototype, "code", { enumerable: true });
2208
+ Object.defineProperty(CloseEvent.prototype, "reason", { enumerable: true });
2209
+ Object.defineProperty(CloseEvent.prototype, "wasClean", { enumerable: true });
2210
+ var ErrorEvent = class extends Event {
2211
+ /**
2212
+ * Create a new `ErrorEvent`.
2213
+ *
2214
+ * @param {String} type The name of the event
2215
+ * @param {Object} [options] A dictionary object that allows for setting
2216
+ * attributes via object members of the same name
2217
+ * @param {*} [options.error=null] The error that generated this event
2218
+ * @param {String} [options.message=''] The error message
2219
+ */
2220
+ constructor(type, options = {}) {
2221
+ super(type);
2222
+ this[kError] = options.error === void 0 ? null : options.error;
2223
+ this[kMessage] = options.message === void 0 ? "" : options.message;
2224
+ }
2225
+ /**
2226
+ * @type {*}
2227
+ */
2228
+ get error() {
2229
+ return this[kError];
2230
+ }
2231
+ /**
2232
+ * @type {String}
2233
+ */
2234
+ get message() {
2235
+ return this[kMessage];
2236
+ }
2237
+ };
2238
+ Object.defineProperty(ErrorEvent.prototype, "error", { enumerable: true });
2239
+ Object.defineProperty(ErrorEvent.prototype, "message", { enumerable: true });
2240
+ var MessageEvent = class extends Event {
2241
+ /**
2242
+ * Create a new `MessageEvent`.
2243
+ *
2244
+ * @param {String} type The name of the event
2245
+ * @param {Object} [options] A dictionary object that allows for setting
2246
+ * attributes via object members of the same name
2247
+ * @param {*} [options.data=null] The message content
2248
+ */
2249
+ constructor(type, options = {}) {
2250
+ super(type);
2251
+ this[kData] = options.data === void 0 ? null : options.data;
2252
+ }
2253
+ /**
2254
+ * @type {*}
2255
+ */
2256
+ get data() {
2257
+ return this[kData];
2258
+ }
2259
+ };
2260
+ Object.defineProperty(MessageEvent.prototype, "data", { enumerable: true });
2261
+ var EventTarget = {
2262
+ /**
2263
+ * Register an event listener.
2264
+ *
2265
+ * @param {String} type A string representing the event type to listen for
2266
+ * @param {(Function|Object)} handler The listener to add
2267
+ * @param {Object} [options] An options object specifies characteristics about
2268
+ * the event listener
2269
+ * @param {Boolean} [options.once=false] A `Boolean` indicating that the
2270
+ * listener should be invoked at most once after being added. If `true`,
2271
+ * the listener would be automatically removed when invoked.
2272
+ * @public
2273
+ */
2274
+ addEventListener(type, handler, options = {}) {
2275
+ for (const listener of this.listeners(type)) {
2276
+ if (!options[kForOnEventAttribute] && listener[kListener] === handler && !listener[kForOnEventAttribute]) {
2277
+ return;
2278
+ }
2279
+ }
2280
+ let wrapper;
2281
+ if (type === "message") {
2282
+ wrapper = function onMessage(data, isBinary) {
2283
+ const event = new MessageEvent("message", {
2284
+ data: isBinary ? data : data.toString()
2285
+ });
2286
+ event[kTarget] = this;
2287
+ callListener(handler, this, event);
2288
+ };
2289
+ } else if (type === "close") {
2290
+ wrapper = function onClose(code, message) {
2291
+ const event = new CloseEvent("close", {
2292
+ code,
2293
+ reason: message.toString(),
2294
+ wasClean: this._closeFrameReceived && this._closeFrameSent
2295
+ });
2296
+ event[kTarget] = this;
2297
+ callListener(handler, this, event);
2298
+ };
2299
+ } else if (type === "error") {
2300
+ wrapper = function onError(error) {
2301
+ const event = new ErrorEvent("error", {
2302
+ error,
2303
+ message: error.message
2304
+ });
2305
+ event[kTarget] = this;
2306
+ callListener(handler, this, event);
2307
+ };
2308
+ } else if (type === "open") {
2309
+ wrapper = function onOpen() {
2310
+ const event = new Event("open");
2311
+ event[kTarget] = this;
2312
+ callListener(handler, this, event);
2313
+ };
2314
+ } else {
2315
+ return;
2316
+ }
2317
+ wrapper[kForOnEventAttribute] = !!options[kForOnEventAttribute];
2318
+ wrapper[kListener] = handler;
2319
+ if (options.once) {
2320
+ this.once(type, wrapper);
2321
+ } else {
2322
+ this.on(type, wrapper);
2323
+ }
2324
+ },
2325
+ /**
2326
+ * Remove an event listener.
2327
+ *
2328
+ * @param {String} type A string representing the event type to remove
2329
+ * @param {(Function|Object)} handler The listener to remove
2330
+ * @public
2331
+ */
2332
+ removeEventListener(type, handler) {
2333
+ for (const listener of this.listeners(type)) {
2334
+ if (listener[kListener] === handler && !listener[kForOnEventAttribute]) {
2335
+ this.removeListener(type, listener);
2336
+ break;
2337
+ }
2338
+ }
2339
+ }
2340
+ };
2341
+ module.exports = {
2342
+ CloseEvent,
2343
+ ErrorEvent,
2344
+ Event,
2345
+ EventTarget,
2346
+ MessageEvent
2347
+ };
2348
+ function callListener(listener, thisArg, event) {
2349
+ if (typeof listener === "object" && listener.handleEvent) {
2350
+ listener.handleEvent.call(listener, event);
2351
+ } else {
2352
+ listener.call(thisArg, event);
2353
+ }
2354
+ }
2355
+ }
2356
+ });
2357
+
2358
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/extension.js
2359
+ var require_extension = __commonJS({
2360
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/extension.js"(exports, module) {
2361
+ "use strict";
2362
+ var { tokenChars } = require_validation();
2363
+ function push(dest, name, elem) {
2364
+ if (dest[name] === void 0)
2365
+ dest[name] = [elem];
2366
+ else
2367
+ dest[name].push(elem);
2368
+ }
2369
+ function parse(header) {
2370
+ const offers = /* @__PURE__ */ Object.create(null);
2371
+ let params = /* @__PURE__ */ Object.create(null);
2372
+ let mustUnescape = false;
2373
+ let isEscaping = false;
2374
+ let inQuotes = false;
2375
+ let extensionName;
2376
+ let paramName;
2377
+ let start = -1;
2378
+ let code = -1;
2379
+ let end = -1;
2380
+ let i = 0;
2381
+ for (; i < header.length; i++) {
2382
+ code = header.charCodeAt(i);
2383
+ if (extensionName === void 0) {
2384
+ if (end === -1 && tokenChars[code] === 1) {
2385
+ if (start === -1)
2386
+ start = i;
2387
+ } else if (i !== 0 && (code === 32 || code === 9)) {
2388
+ if (end === -1 && start !== -1)
2389
+ end = i;
2390
+ } else if (code === 59 || code === 44) {
2391
+ if (start === -1) {
2392
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2393
+ }
2394
+ if (end === -1)
2395
+ end = i;
2396
+ const name = header.slice(start, end);
2397
+ if (code === 44) {
2398
+ push(offers, name, params);
2399
+ params = /* @__PURE__ */ Object.create(null);
2400
+ } else {
2401
+ extensionName = name;
2402
+ }
2403
+ start = end = -1;
2404
+ } else {
2405
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2406
+ }
2407
+ } else if (paramName === void 0) {
2408
+ if (end === -1 && tokenChars[code] === 1) {
2409
+ if (start === -1)
2410
+ start = i;
2411
+ } else if (code === 32 || code === 9) {
2412
+ if (end === -1 && start !== -1)
2413
+ end = i;
2414
+ } else if (code === 59 || code === 44) {
2415
+ if (start === -1) {
2416
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2417
+ }
2418
+ if (end === -1)
2419
+ end = i;
2420
+ push(params, header.slice(start, end), true);
2421
+ if (code === 44) {
2422
+ push(offers, extensionName, params);
2423
+ params = /* @__PURE__ */ Object.create(null);
2424
+ extensionName = void 0;
2425
+ }
2426
+ start = end = -1;
2427
+ } else if (code === 61 && start !== -1 && end === -1) {
2428
+ paramName = header.slice(start, i);
2429
+ start = end = -1;
2430
+ } else {
2431
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2432
+ }
2433
+ } else {
2434
+ if (isEscaping) {
2435
+ if (tokenChars[code] !== 1) {
2436
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2437
+ }
2438
+ if (start === -1)
2439
+ start = i;
2440
+ else if (!mustUnescape)
2441
+ mustUnescape = true;
2442
+ isEscaping = false;
2443
+ } else if (inQuotes) {
2444
+ if (tokenChars[code] === 1) {
2445
+ if (start === -1)
2446
+ start = i;
2447
+ } else if (code === 34 && start !== -1) {
2448
+ inQuotes = false;
2449
+ end = i;
2450
+ } else if (code === 92) {
2451
+ isEscaping = true;
2452
+ } else {
2453
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2454
+ }
2455
+ } else if (code === 34 && header.charCodeAt(i - 1) === 61) {
2456
+ inQuotes = true;
2457
+ } else if (end === -1 && tokenChars[code] === 1) {
2458
+ if (start === -1)
2459
+ start = i;
2460
+ } else if (start !== -1 && (code === 32 || code === 9)) {
2461
+ if (end === -1)
2462
+ end = i;
2463
+ } else if (code === 59 || code === 44) {
2464
+ if (start === -1) {
2465
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2466
+ }
2467
+ if (end === -1)
2468
+ end = i;
2469
+ let value = header.slice(start, end);
2470
+ if (mustUnescape) {
2471
+ value = value.replace(/\\/g, "");
2472
+ mustUnescape = false;
2473
+ }
2474
+ push(params, paramName, value);
2475
+ if (code === 44) {
2476
+ push(offers, extensionName, params);
2477
+ params = /* @__PURE__ */ Object.create(null);
2478
+ extensionName = void 0;
2479
+ }
2480
+ paramName = void 0;
2481
+ start = end = -1;
2482
+ } else {
2483
+ throw new SyntaxError(`Unexpected character at index ${i}`);
2484
+ }
2485
+ }
2486
+ }
2487
+ if (start === -1 || inQuotes || code === 32 || code === 9) {
2488
+ throw new SyntaxError("Unexpected end of input");
2489
+ }
2490
+ if (end === -1)
2491
+ end = i;
2492
+ const token = header.slice(start, end);
2493
+ if (extensionName === void 0) {
2494
+ push(offers, token, params);
2495
+ } else {
2496
+ if (paramName === void 0) {
2497
+ push(params, token, true);
2498
+ } else if (mustUnescape) {
2499
+ push(params, paramName, token.replace(/\\/g, ""));
2500
+ } else {
2501
+ push(params, paramName, token);
2502
+ }
2503
+ push(offers, extensionName, params);
2504
+ }
2505
+ return offers;
2506
+ }
2507
+ function format(extensions) {
2508
+ return Object.keys(extensions).map((extension) => {
2509
+ let configurations = extensions[extension];
2510
+ if (!Array.isArray(configurations))
2511
+ configurations = [configurations];
2512
+ return configurations.map((params) => {
2513
+ return [extension].concat(
2514
+ Object.keys(params).map((k) => {
2515
+ let values = params[k];
2516
+ if (!Array.isArray(values))
2517
+ values = [values];
2518
+ return values.map((v) => v === true ? k : `${k}=${v}`).join("; ");
2519
+ })
2520
+ ).join("; ");
2521
+ }).join(", ");
2522
+ }).join(", ");
2523
+ }
2524
+ module.exports = { format, parse };
2525
+ }
2526
+ });
2527
+
2528
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/websocket.js
2529
+ var require_websocket = __commonJS({
2530
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/websocket.js"(exports, module) {
2531
+ "use strict";
2532
+ var EventEmitter = __require("events");
2533
+ var https = __require("https");
2534
+ var http = __require("http");
2535
+ var net = __require("net");
2536
+ var tls = __require("tls");
2537
+ var { randomBytes, createHash } = __require("crypto");
2538
+ var { Duplex, Readable } = __require("stream");
2539
+ var { URL } = __require("url");
2540
+ var PerMessageDeflate = require_permessage_deflate();
2541
+ var Receiver2 = require_receiver();
2542
+ var Sender2 = require_sender();
2543
+ var { isBlob } = require_validation();
2544
+ var {
2545
+ BINARY_TYPES,
2546
+ EMPTY_BUFFER,
2547
+ GUID,
2548
+ kForOnEventAttribute,
2549
+ kListener,
2550
+ kStatusCode,
2551
+ kWebSocket,
2552
+ NOOP
2553
+ } = require_constants();
2554
+ var {
2555
+ EventTarget: { addEventListener, removeEventListener }
2556
+ } = require_event_target();
2557
+ var { format, parse } = require_extension();
2558
+ var { toBuffer } = require_buffer_util();
2559
+ var closeTimeout = 30 * 1e3;
2560
+ var kAborted = Symbol("kAborted");
2561
+ var protocolVersions = [8, 13];
2562
+ var readyStates = ["CONNECTING", "OPEN", "CLOSING", "CLOSED"];
2563
+ var subprotocolRegex = /^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/;
2564
+ var WebSocket4 = class extends EventEmitter {
2565
+ /**
2566
+ * Create a new `WebSocket`.
2567
+ *
2568
+ * @param {(String|URL)} address The URL to which to connect
2569
+ * @param {(String|String[])} [protocols] The subprotocols
2570
+ * @param {Object} [options] Connection options
2571
+ */
2572
+ constructor(address, protocols, options) {
2573
+ super();
2574
+ this._binaryType = BINARY_TYPES[0];
2575
+ this._closeCode = 1006;
2576
+ this._closeFrameReceived = false;
2577
+ this._closeFrameSent = false;
2578
+ this._closeMessage = EMPTY_BUFFER;
2579
+ this._closeTimer = null;
2580
+ this._errorEmitted = false;
2581
+ this._extensions = {};
2582
+ this._paused = false;
2583
+ this._protocol = "";
2584
+ this._readyState = WebSocket4.CONNECTING;
2585
+ this._receiver = null;
2586
+ this._sender = null;
2587
+ this._socket = null;
2588
+ if (address !== null) {
2589
+ this._bufferedAmount = 0;
2590
+ this._isServer = false;
2591
+ this._redirects = 0;
2592
+ if (protocols === void 0) {
2593
+ protocols = [];
2594
+ } else if (!Array.isArray(protocols)) {
2595
+ if (typeof protocols === "object" && protocols !== null) {
2596
+ options = protocols;
2597
+ protocols = [];
2598
+ } else {
2599
+ protocols = [protocols];
2600
+ }
2601
+ }
2602
+ initAsClient(this, address, protocols, options);
2603
+ } else {
2604
+ this._autoPong = options.autoPong;
2605
+ this._isServer = true;
2606
+ }
2607
+ }
2608
+ /**
2609
+ * For historical reasons, the custom "nodebuffer" type is used by the default
2610
+ * instead of "blob".
2611
+ *
2612
+ * @type {String}
2613
+ */
2614
+ get binaryType() {
2615
+ return this._binaryType;
2616
+ }
2617
+ set binaryType(type) {
2618
+ if (!BINARY_TYPES.includes(type))
2619
+ return;
2620
+ this._binaryType = type;
2621
+ if (this._receiver)
2622
+ this._receiver._binaryType = type;
2623
+ }
2624
+ /**
2625
+ * @type {Number}
2626
+ */
2627
+ get bufferedAmount() {
2628
+ if (!this._socket)
2629
+ return this._bufferedAmount;
2630
+ return this._socket._writableState.length + this._sender._bufferedBytes;
2631
+ }
2632
+ /**
2633
+ * @type {String}
2634
+ */
2635
+ get extensions() {
2636
+ return Object.keys(this._extensions).join();
2637
+ }
2638
+ /**
2639
+ * @type {Boolean}
2640
+ */
2641
+ get isPaused() {
2642
+ return this._paused;
2643
+ }
2644
+ /**
2645
+ * @type {Function}
2646
+ */
2647
+ /* istanbul ignore next */
2648
+ get onclose() {
2649
+ return null;
2650
+ }
2651
+ /**
2652
+ * @type {Function}
2653
+ */
2654
+ /* istanbul ignore next */
2655
+ get onerror() {
2656
+ return null;
2657
+ }
2658
+ /**
2659
+ * @type {Function}
2660
+ */
2661
+ /* istanbul ignore next */
2662
+ get onopen() {
2663
+ return null;
2664
+ }
2665
+ /**
2666
+ * @type {Function}
2667
+ */
2668
+ /* istanbul ignore next */
2669
+ get onmessage() {
2670
+ return null;
2671
+ }
2672
+ /**
2673
+ * @type {String}
2674
+ */
2675
+ get protocol() {
2676
+ return this._protocol;
2677
+ }
2678
+ /**
2679
+ * @type {Number}
2680
+ */
2681
+ get readyState() {
2682
+ return this._readyState;
2683
+ }
2684
+ /**
2685
+ * @type {String}
2686
+ */
2687
+ get url() {
2688
+ return this._url;
2689
+ }
2690
+ /**
2691
+ * Set up the socket and the internal resources.
2692
+ *
2693
+ * @param {Duplex} socket The network socket between the server and client
2694
+ * @param {Buffer} head The first packet of the upgraded stream
2695
+ * @param {Object} options Options object
2696
+ * @param {Boolean} [options.allowSynchronousEvents=false] Specifies whether
2697
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
2698
+ * multiple times in the same tick
2699
+ * @param {Function} [options.generateMask] The function used to generate the
2700
+ * masking key
2701
+ * @param {Number} [options.maxPayload=0] The maximum allowed message size
2702
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2703
+ * not to skip UTF-8 validation for text and close messages
2704
+ * @private
2705
+ */
2706
+ setSocket(socket, head, options) {
2707
+ const receiver = new Receiver2({
2708
+ allowSynchronousEvents: options.allowSynchronousEvents,
2709
+ binaryType: this.binaryType,
2710
+ extensions: this._extensions,
2711
+ isServer: this._isServer,
2712
+ maxPayload: options.maxPayload,
2713
+ skipUTF8Validation: options.skipUTF8Validation
2714
+ });
2715
+ const sender = new Sender2(socket, this._extensions, options.generateMask);
2716
+ this._receiver = receiver;
2717
+ this._sender = sender;
2718
+ this._socket = socket;
2719
+ receiver[kWebSocket] = this;
2720
+ sender[kWebSocket] = this;
2721
+ socket[kWebSocket] = this;
2722
+ receiver.on("conclude", receiverOnConclude);
2723
+ receiver.on("drain", receiverOnDrain);
2724
+ receiver.on("error", receiverOnError);
2725
+ receiver.on("message", receiverOnMessage);
2726
+ receiver.on("ping", receiverOnPing);
2727
+ receiver.on("pong", receiverOnPong);
2728
+ sender.onerror = senderOnError;
2729
+ if (socket.setTimeout)
2730
+ socket.setTimeout(0);
2731
+ if (socket.setNoDelay)
2732
+ socket.setNoDelay();
2733
+ if (head.length > 0)
2734
+ socket.unshift(head);
2735
+ socket.on("close", socketOnClose);
2736
+ socket.on("data", socketOnData);
2737
+ socket.on("end", socketOnEnd);
2738
+ socket.on("error", socketOnError);
2739
+ this._readyState = WebSocket4.OPEN;
2740
+ this.emit("open");
2741
+ }
2742
+ /**
2743
+ * Emit the `'close'` event.
2744
+ *
2745
+ * @private
2746
+ */
2747
+ emitClose() {
2748
+ if (!this._socket) {
2749
+ this._readyState = WebSocket4.CLOSED;
2750
+ this.emit("close", this._closeCode, this._closeMessage);
2751
+ return;
2752
+ }
2753
+ if (this._extensions[PerMessageDeflate.extensionName]) {
2754
+ this._extensions[PerMessageDeflate.extensionName].cleanup();
2755
+ }
2756
+ this._receiver.removeAllListeners();
2757
+ this._readyState = WebSocket4.CLOSED;
2758
+ this.emit("close", this._closeCode, this._closeMessage);
2759
+ }
2760
+ /**
2761
+ * Start a closing handshake.
2762
+ *
2763
+ * +----------+ +-----------+ +----------+
2764
+ * - - -|ws.close()|-->|close frame|-->|ws.close()|- - -
2765
+ * | +----------+ +-----------+ +----------+ |
2766
+ * +----------+ +-----------+ |
2767
+ * CLOSING |ws.close()|<--|close frame|<--+-----+ CLOSING
2768
+ * +----------+ +-----------+ |
2769
+ * | | | +---+ |
2770
+ * +------------------------+-->|fin| - - - -
2771
+ * | +---+ | +---+
2772
+ * - - - - -|fin|<---------------------+
2773
+ * +---+
2774
+ *
2775
+ * @param {Number} [code] Status code explaining why the connection is closing
2776
+ * @param {(String|Buffer)} [data] The reason why the connection is
2777
+ * closing
2778
+ * @public
2779
+ */
2780
+ close(code, data) {
2781
+ if (this.readyState === WebSocket4.CLOSED)
2782
+ return;
2783
+ if (this.readyState === WebSocket4.CONNECTING) {
2784
+ const msg = "WebSocket was closed before the connection was established";
2785
+ abortHandshake(this, this._req, msg);
2786
+ return;
2787
+ }
2788
+ if (this.readyState === WebSocket4.CLOSING) {
2789
+ if (this._closeFrameSent && (this._closeFrameReceived || this._receiver._writableState.errorEmitted)) {
2790
+ this._socket.end();
2791
+ }
2792
+ return;
2793
+ }
2794
+ this._readyState = WebSocket4.CLOSING;
2795
+ this._sender.close(code, data, !this._isServer, (err) => {
2796
+ if (err)
2797
+ return;
2798
+ this._closeFrameSent = true;
2799
+ if (this._closeFrameReceived || this._receiver._writableState.errorEmitted) {
2800
+ this._socket.end();
2801
+ }
2802
+ });
2803
+ setCloseTimer(this);
2804
+ }
2805
+ /**
2806
+ * Pause the socket.
2807
+ *
2808
+ * @public
2809
+ */
2810
+ pause() {
2811
+ if (this.readyState === WebSocket4.CONNECTING || this.readyState === WebSocket4.CLOSED) {
2812
+ return;
2813
+ }
2814
+ this._paused = true;
2815
+ this._socket.pause();
2816
+ }
2817
+ /**
2818
+ * Send a ping.
2819
+ *
2820
+ * @param {*} [data] The data to send
2821
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
2822
+ * @param {Function} [cb] Callback which is executed when the ping is sent
2823
+ * @public
2824
+ */
2825
+ ping(data, mask, cb) {
2826
+ if (this.readyState === WebSocket4.CONNECTING) {
2827
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2828
+ }
2829
+ if (typeof data === "function") {
2830
+ cb = data;
2831
+ data = mask = void 0;
2832
+ } else if (typeof mask === "function") {
2833
+ cb = mask;
2834
+ mask = void 0;
2835
+ }
2836
+ if (typeof data === "number")
2837
+ data = data.toString();
2838
+ if (this.readyState !== WebSocket4.OPEN) {
2839
+ sendAfterClose(this, data, cb);
2840
+ return;
2841
+ }
2842
+ if (mask === void 0)
2843
+ mask = !this._isServer;
2844
+ this._sender.ping(data || EMPTY_BUFFER, mask, cb);
2845
+ }
2846
+ /**
2847
+ * Send a pong.
2848
+ *
2849
+ * @param {*} [data] The data to send
2850
+ * @param {Boolean} [mask] Indicates whether or not to mask `data`
2851
+ * @param {Function} [cb] Callback which is executed when the pong is sent
2852
+ * @public
2853
+ */
2854
+ pong(data, mask, cb) {
2855
+ if (this.readyState === WebSocket4.CONNECTING) {
2856
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2857
+ }
2858
+ if (typeof data === "function") {
2859
+ cb = data;
2860
+ data = mask = void 0;
2861
+ } else if (typeof mask === "function") {
2862
+ cb = mask;
2863
+ mask = void 0;
2864
+ }
2865
+ if (typeof data === "number")
2866
+ data = data.toString();
2867
+ if (this.readyState !== WebSocket4.OPEN) {
2868
+ sendAfterClose(this, data, cb);
2869
+ return;
2870
+ }
2871
+ if (mask === void 0)
2872
+ mask = !this._isServer;
2873
+ this._sender.pong(data || EMPTY_BUFFER, mask, cb);
2874
+ }
2875
+ /**
2876
+ * Resume the socket.
2877
+ *
2878
+ * @public
2879
+ */
2880
+ resume() {
2881
+ if (this.readyState === WebSocket4.CONNECTING || this.readyState === WebSocket4.CLOSED) {
2882
+ return;
2883
+ }
2884
+ this._paused = false;
2885
+ if (!this._receiver._writableState.needDrain)
2886
+ this._socket.resume();
2887
+ }
2888
+ /**
2889
+ * Send a data message.
2890
+ *
2891
+ * @param {*} data The message to send
2892
+ * @param {Object} [options] Options object
2893
+ * @param {Boolean} [options.binary] Specifies whether `data` is binary or
2894
+ * text
2895
+ * @param {Boolean} [options.compress] Specifies whether or not to compress
2896
+ * `data`
2897
+ * @param {Boolean} [options.fin=true] Specifies whether the fragment is the
2898
+ * last one
2899
+ * @param {Boolean} [options.mask] Specifies whether or not to mask `data`
2900
+ * @param {Function} [cb] Callback which is executed when data is written out
2901
+ * @public
2902
+ */
2903
+ send(data, options, cb) {
2904
+ if (this.readyState === WebSocket4.CONNECTING) {
2905
+ throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");
2906
+ }
2907
+ if (typeof options === "function") {
2908
+ cb = options;
2909
+ options = {};
2910
+ }
2911
+ if (typeof data === "number")
2912
+ data = data.toString();
2913
+ if (this.readyState !== WebSocket4.OPEN) {
2914
+ sendAfterClose(this, data, cb);
2915
+ return;
2916
+ }
2917
+ const opts = {
2918
+ binary: typeof data !== "string",
2919
+ mask: !this._isServer,
2920
+ compress: true,
2921
+ fin: true,
2922
+ ...options
2923
+ };
2924
+ if (!this._extensions[PerMessageDeflate.extensionName]) {
2925
+ opts.compress = false;
2926
+ }
2927
+ this._sender.send(data || EMPTY_BUFFER, opts, cb);
2928
+ }
2929
+ /**
2930
+ * Forcibly close the connection.
2931
+ *
2932
+ * @public
2933
+ */
2934
+ terminate() {
2935
+ if (this.readyState === WebSocket4.CLOSED)
2936
+ return;
2937
+ if (this.readyState === WebSocket4.CONNECTING) {
2938
+ const msg = "WebSocket was closed before the connection was established";
2939
+ abortHandshake(this, this._req, msg);
2940
+ return;
2941
+ }
2942
+ if (this._socket) {
2943
+ this._readyState = WebSocket4.CLOSING;
2944
+ this._socket.destroy();
2945
+ }
2946
+ }
2947
+ };
2948
+ Object.defineProperty(WebSocket4, "CONNECTING", {
2949
+ enumerable: true,
2950
+ value: readyStates.indexOf("CONNECTING")
2951
+ });
2952
+ Object.defineProperty(WebSocket4.prototype, "CONNECTING", {
2953
+ enumerable: true,
2954
+ value: readyStates.indexOf("CONNECTING")
2955
+ });
2956
+ Object.defineProperty(WebSocket4, "OPEN", {
2957
+ enumerable: true,
2958
+ value: readyStates.indexOf("OPEN")
2959
+ });
2960
+ Object.defineProperty(WebSocket4.prototype, "OPEN", {
2961
+ enumerable: true,
2962
+ value: readyStates.indexOf("OPEN")
2963
+ });
2964
+ Object.defineProperty(WebSocket4, "CLOSING", {
2965
+ enumerable: true,
2966
+ value: readyStates.indexOf("CLOSING")
2967
+ });
2968
+ Object.defineProperty(WebSocket4.prototype, "CLOSING", {
2969
+ enumerable: true,
2970
+ value: readyStates.indexOf("CLOSING")
2971
+ });
2972
+ Object.defineProperty(WebSocket4, "CLOSED", {
2973
+ enumerable: true,
2974
+ value: readyStates.indexOf("CLOSED")
2975
+ });
2976
+ Object.defineProperty(WebSocket4.prototype, "CLOSED", {
2977
+ enumerable: true,
2978
+ value: readyStates.indexOf("CLOSED")
2979
+ });
2980
+ [
2981
+ "binaryType",
2982
+ "bufferedAmount",
2983
+ "extensions",
2984
+ "isPaused",
2985
+ "protocol",
2986
+ "readyState",
2987
+ "url"
2988
+ ].forEach((property) => {
2989
+ Object.defineProperty(WebSocket4.prototype, property, { enumerable: true });
2990
+ });
2991
+ ["open", "error", "close", "message"].forEach((method) => {
2992
+ Object.defineProperty(WebSocket4.prototype, `on${method}`, {
2993
+ enumerable: true,
2994
+ get() {
2995
+ for (const listener of this.listeners(method)) {
2996
+ if (listener[kForOnEventAttribute])
2997
+ return listener[kListener];
2998
+ }
2999
+ return null;
3000
+ },
3001
+ set(handler) {
3002
+ for (const listener of this.listeners(method)) {
3003
+ if (listener[kForOnEventAttribute]) {
3004
+ this.removeListener(method, listener);
3005
+ break;
3006
+ }
3007
+ }
3008
+ if (typeof handler !== "function")
3009
+ return;
3010
+ this.addEventListener(method, handler, {
3011
+ [kForOnEventAttribute]: true
3012
+ });
3013
+ }
3014
+ });
3015
+ });
3016
+ WebSocket4.prototype.addEventListener = addEventListener;
3017
+ WebSocket4.prototype.removeEventListener = removeEventListener;
3018
+ module.exports = WebSocket4;
3019
+ function initAsClient(websocket, address, protocols, options) {
3020
+ const opts = {
3021
+ allowSynchronousEvents: true,
3022
+ autoPong: true,
3023
+ protocolVersion: protocolVersions[1],
3024
+ maxPayload: 100 * 1024 * 1024,
3025
+ skipUTF8Validation: false,
3026
+ perMessageDeflate: true,
3027
+ followRedirects: false,
3028
+ maxRedirects: 10,
3029
+ ...options,
3030
+ socketPath: void 0,
3031
+ hostname: void 0,
3032
+ protocol: void 0,
3033
+ timeout: void 0,
3034
+ method: "GET",
3035
+ host: void 0,
3036
+ path: void 0,
3037
+ port: void 0
3038
+ };
3039
+ websocket._autoPong = opts.autoPong;
3040
+ if (!protocolVersions.includes(opts.protocolVersion)) {
3041
+ throw new RangeError(
3042
+ `Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(", ")})`
3043
+ );
3044
+ }
3045
+ let parsedUrl;
3046
+ if (address instanceof URL) {
3047
+ parsedUrl = address;
3048
+ } else {
3049
+ try {
3050
+ parsedUrl = new URL(address);
3051
+ } catch (e) {
3052
+ throw new SyntaxError(`Invalid URL: ${address}`);
3053
+ }
3054
+ }
3055
+ if (parsedUrl.protocol === "http:") {
3056
+ parsedUrl.protocol = "ws:";
3057
+ } else if (parsedUrl.protocol === "https:") {
3058
+ parsedUrl.protocol = "wss:";
3059
+ }
3060
+ websocket._url = parsedUrl.href;
3061
+ const isSecure = parsedUrl.protocol === "wss:";
3062
+ const isIpcUrl = parsedUrl.protocol === "ws+unix:";
3063
+ let invalidUrlMessage;
3064
+ if (parsedUrl.protocol !== "ws:" && !isSecure && !isIpcUrl) {
3065
+ invalidUrlMessage = `The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`;
3066
+ } else if (isIpcUrl && !parsedUrl.pathname) {
3067
+ invalidUrlMessage = "The URL's pathname is empty";
3068
+ } else if (parsedUrl.hash) {
3069
+ invalidUrlMessage = "The URL contains a fragment identifier";
3070
+ }
3071
+ if (invalidUrlMessage) {
3072
+ const err = new SyntaxError(invalidUrlMessage);
3073
+ if (websocket._redirects === 0) {
3074
+ throw err;
3075
+ } else {
3076
+ emitErrorAndClose(websocket, err);
3077
+ return;
3078
+ }
3079
+ }
3080
+ const defaultPort = isSecure ? 443 : 80;
3081
+ const key = randomBytes(16).toString("base64");
3082
+ const request = isSecure ? https.request : http.request;
3083
+ const protocolSet = /* @__PURE__ */ new Set();
3084
+ let perMessageDeflate;
3085
+ opts.createConnection = opts.createConnection || (isSecure ? tlsConnect : netConnect);
3086
+ opts.defaultPort = opts.defaultPort || defaultPort;
3087
+ opts.port = parsedUrl.port || defaultPort;
3088
+ opts.host = parsedUrl.hostname.startsWith("[") ? parsedUrl.hostname.slice(1, -1) : parsedUrl.hostname;
3089
+ opts.headers = {
3090
+ ...opts.headers,
3091
+ "Sec-WebSocket-Version": opts.protocolVersion,
3092
+ "Sec-WebSocket-Key": key,
3093
+ Connection: "Upgrade",
3094
+ Upgrade: "websocket"
3095
+ };
3096
+ opts.path = parsedUrl.pathname + parsedUrl.search;
3097
+ opts.timeout = opts.handshakeTimeout;
3098
+ if (opts.perMessageDeflate) {
3099
+ perMessageDeflate = new PerMessageDeflate(
3100
+ opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
3101
+ false,
3102
+ opts.maxPayload
3103
+ );
3104
+ opts.headers["Sec-WebSocket-Extensions"] = format({
3105
+ [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
3106
+ });
3107
+ }
3108
+ if (protocols.length) {
3109
+ for (const protocol of protocols) {
3110
+ if (typeof protocol !== "string" || !subprotocolRegex.test(protocol) || protocolSet.has(protocol)) {
3111
+ throw new SyntaxError(
3112
+ "An invalid or duplicated subprotocol was specified"
3113
+ );
3114
+ }
3115
+ protocolSet.add(protocol);
3116
+ }
3117
+ opts.headers["Sec-WebSocket-Protocol"] = protocols.join(",");
3118
+ }
3119
+ if (opts.origin) {
3120
+ if (opts.protocolVersion < 13) {
3121
+ opts.headers["Sec-WebSocket-Origin"] = opts.origin;
3122
+ } else {
3123
+ opts.headers.Origin = opts.origin;
3124
+ }
3125
+ }
3126
+ if (parsedUrl.username || parsedUrl.password) {
3127
+ opts.auth = `${parsedUrl.username}:${parsedUrl.password}`;
3128
+ }
3129
+ if (isIpcUrl) {
3130
+ const parts = opts.path.split(":");
3131
+ opts.socketPath = parts[0];
3132
+ opts.path = parts[1];
3133
+ }
3134
+ let req;
3135
+ if (opts.followRedirects) {
3136
+ if (websocket._redirects === 0) {
3137
+ websocket._originalIpc = isIpcUrl;
3138
+ websocket._originalSecure = isSecure;
3139
+ websocket._originalHostOrSocketPath = isIpcUrl ? opts.socketPath : parsedUrl.host;
3140
+ const headers = options && options.headers;
3141
+ options = { ...options, headers: {} };
3142
+ if (headers) {
3143
+ for (const [key2, value] of Object.entries(headers)) {
3144
+ options.headers[key2.toLowerCase()] = value;
3145
+ }
3146
+ }
3147
+ } else if (websocket.listenerCount("redirect") === 0) {
3148
+ const isSameHost = isIpcUrl ? websocket._originalIpc ? opts.socketPath === websocket._originalHostOrSocketPath : false : websocket._originalIpc ? false : parsedUrl.host === websocket._originalHostOrSocketPath;
3149
+ if (!isSameHost || websocket._originalSecure && !isSecure) {
3150
+ delete opts.headers.authorization;
3151
+ delete opts.headers.cookie;
3152
+ if (!isSameHost)
3153
+ delete opts.headers.host;
3154
+ opts.auth = void 0;
3155
+ }
3156
+ }
3157
+ if (opts.auth && !options.headers.authorization) {
3158
+ options.headers.authorization = "Basic " + Buffer.from(opts.auth).toString("base64");
3159
+ }
3160
+ req = websocket._req = request(opts);
3161
+ if (websocket._redirects) {
3162
+ websocket.emit("redirect", websocket.url, req);
3163
+ }
3164
+ } else {
3165
+ req = websocket._req = request(opts);
3166
+ }
3167
+ if (opts.timeout) {
3168
+ req.on("timeout", () => {
3169
+ abortHandshake(websocket, req, "Opening handshake has timed out");
3170
+ });
3171
+ }
3172
+ req.on("error", (err) => {
3173
+ if (req === null || req[kAborted])
3174
+ return;
3175
+ req = websocket._req = null;
3176
+ emitErrorAndClose(websocket, err);
3177
+ });
3178
+ req.on("response", (res) => {
3179
+ const location = res.headers.location;
3180
+ const statusCode = res.statusCode;
3181
+ if (location && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
3182
+ if (++websocket._redirects > opts.maxRedirects) {
3183
+ abortHandshake(websocket, req, "Maximum redirects exceeded");
3184
+ return;
3185
+ }
3186
+ req.abort();
3187
+ let addr;
3188
+ try {
3189
+ addr = new URL(location, address);
3190
+ } catch (e) {
3191
+ const err = new SyntaxError(`Invalid URL: ${location}`);
3192
+ emitErrorAndClose(websocket, err);
3193
+ return;
3194
+ }
3195
+ initAsClient(websocket, addr, protocols, options);
3196
+ } else if (!websocket.emit("unexpected-response", req, res)) {
3197
+ abortHandshake(
3198
+ websocket,
3199
+ req,
3200
+ `Unexpected server response: ${res.statusCode}`
3201
+ );
3202
+ }
3203
+ });
3204
+ req.on("upgrade", (res, socket, head) => {
3205
+ websocket.emit("upgrade", res);
3206
+ if (websocket.readyState !== WebSocket4.CONNECTING)
3207
+ return;
3208
+ req = websocket._req = null;
3209
+ const upgrade = res.headers.upgrade;
3210
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
3211
+ abortHandshake(websocket, socket, "Invalid Upgrade header");
3212
+ return;
3213
+ }
3214
+ const digest = createHash("sha1").update(key + GUID).digest("base64");
3215
+ if (res.headers["sec-websocket-accept"] !== digest) {
3216
+ abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
3217
+ return;
3218
+ }
3219
+ const serverProt = res.headers["sec-websocket-protocol"];
3220
+ let protError;
3221
+ if (serverProt !== void 0) {
3222
+ if (!protocolSet.size) {
3223
+ protError = "Server sent a subprotocol but none was requested";
3224
+ } else if (!protocolSet.has(serverProt)) {
3225
+ protError = "Server sent an invalid subprotocol";
3226
+ }
3227
+ } else if (protocolSet.size) {
3228
+ protError = "Server sent no subprotocol";
3229
+ }
3230
+ if (protError) {
3231
+ abortHandshake(websocket, socket, protError);
3232
+ return;
3233
+ }
3234
+ if (serverProt)
3235
+ websocket._protocol = serverProt;
3236
+ const secWebSocketExtensions = res.headers["sec-websocket-extensions"];
3237
+ if (secWebSocketExtensions !== void 0) {
3238
+ if (!perMessageDeflate) {
3239
+ const message = "Server sent a Sec-WebSocket-Extensions header but no extension was requested";
3240
+ abortHandshake(websocket, socket, message);
3241
+ return;
3242
+ }
3243
+ let extensions;
3244
+ try {
3245
+ extensions = parse(secWebSocketExtensions);
3246
+ } catch (err) {
3247
+ const message = "Invalid Sec-WebSocket-Extensions header";
3248
+ abortHandshake(websocket, socket, message);
3249
+ return;
3250
+ }
3251
+ const extensionNames = Object.keys(extensions);
3252
+ if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
3253
+ const message = "Server indicated an extension that was not requested";
3254
+ abortHandshake(websocket, socket, message);
3255
+ return;
3256
+ }
3257
+ try {
3258
+ perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
3259
+ } catch (err) {
3260
+ const message = "Invalid Sec-WebSocket-Extensions header";
3261
+ abortHandshake(websocket, socket, message);
3262
+ return;
3263
+ }
3264
+ websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3265
+ }
3266
+ websocket.setSocket(socket, head, {
3267
+ allowSynchronousEvents: opts.allowSynchronousEvents,
3268
+ generateMask: opts.generateMask,
3269
+ maxPayload: opts.maxPayload,
3270
+ skipUTF8Validation: opts.skipUTF8Validation
3271
+ });
3272
+ });
3273
+ if (opts.finishRequest) {
3274
+ opts.finishRequest(req, websocket);
3275
+ } else {
3276
+ req.end();
3277
+ }
3278
+ }
3279
+ function emitErrorAndClose(websocket, err) {
3280
+ websocket._readyState = WebSocket4.CLOSING;
3281
+ websocket._errorEmitted = true;
3282
+ websocket.emit("error", err);
3283
+ websocket.emitClose();
3284
+ }
3285
+ function netConnect(options) {
3286
+ options.path = options.socketPath;
3287
+ return net.connect(options);
3288
+ }
3289
+ function tlsConnect(options) {
3290
+ options.path = void 0;
3291
+ if (!options.servername && options.servername !== "") {
3292
+ options.servername = net.isIP(options.host) ? "" : options.host;
3293
+ }
3294
+ return tls.connect(options);
3295
+ }
3296
+ function abortHandshake(websocket, stream, message) {
3297
+ websocket._readyState = WebSocket4.CLOSING;
3298
+ const err = new Error(message);
3299
+ Error.captureStackTrace(err, abortHandshake);
3300
+ if (stream.setHeader) {
3301
+ stream[kAborted] = true;
3302
+ stream.abort();
3303
+ if (stream.socket && !stream.socket.destroyed) {
3304
+ stream.socket.destroy();
3305
+ }
3306
+ process.nextTick(emitErrorAndClose, websocket, err);
3307
+ } else {
3308
+ stream.destroy(err);
3309
+ stream.once("error", websocket.emit.bind(websocket, "error"));
3310
+ stream.once("close", websocket.emitClose.bind(websocket));
3311
+ }
3312
+ }
3313
+ function sendAfterClose(websocket, data, cb) {
3314
+ if (data) {
3315
+ const length = isBlob(data) ? data.size : toBuffer(data).length;
3316
+ if (websocket._socket)
3317
+ websocket._sender._bufferedBytes += length;
3318
+ else
3319
+ websocket._bufferedAmount += length;
3320
+ }
3321
+ if (cb) {
3322
+ const err = new Error(
3323
+ `WebSocket is not open: readyState ${websocket.readyState} (${readyStates[websocket.readyState]})`
3324
+ );
3325
+ process.nextTick(cb, err);
3326
+ }
3327
+ }
3328
+ function receiverOnConclude(code, reason) {
3329
+ const websocket = this[kWebSocket];
3330
+ websocket._closeFrameReceived = true;
3331
+ websocket._closeMessage = reason;
3332
+ websocket._closeCode = code;
3333
+ if (websocket._socket[kWebSocket] === void 0)
3334
+ return;
3335
+ websocket._socket.removeListener("data", socketOnData);
3336
+ process.nextTick(resume, websocket._socket);
3337
+ if (code === 1005)
3338
+ websocket.close();
3339
+ else
3340
+ websocket.close(code, reason);
3341
+ }
3342
+ function receiverOnDrain() {
3343
+ const websocket = this[kWebSocket];
3344
+ if (!websocket.isPaused)
3345
+ websocket._socket.resume();
3346
+ }
3347
+ function receiverOnError(err) {
3348
+ const websocket = this[kWebSocket];
3349
+ if (websocket._socket[kWebSocket] !== void 0) {
3350
+ websocket._socket.removeListener("data", socketOnData);
3351
+ process.nextTick(resume, websocket._socket);
3352
+ websocket.close(err[kStatusCode]);
3353
+ }
3354
+ if (!websocket._errorEmitted) {
3355
+ websocket._errorEmitted = true;
3356
+ websocket.emit("error", err);
3357
+ }
3358
+ }
3359
+ function receiverOnFinish() {
3360
+ this[kWebSocket].emitClose();
3361
+ }
3362
+ function receiverOnMessage(data, isBinary) {
3363
+ this[kWebSocket].emit("message", data, isBinary);
3364
+ }
3365
+ function receiverOnPing(data) {
3366
+ const websocket = this[kWebSocket];
3367
+ if (websocket._autoPong)
3368
+ websocket.pong(data, !this._isServer, NOOP);
3369
+ websocket.emit("ping", data);
3370
+ }
3371
+ function receiverOnPong(data) {
3372
+ this[kWebSocket].emit("pong", data);
3373
+ }
3374
+ function resume(stream) {
3375
+ stream.resume();
3376
+ }
3377
+ function senderOnError(err) {
3378
+ const websocket = this[kWebSocket];
3379
+ if (websocket.readyState === WebSocket4.CLOSED)
3380
+ return;
3381
+ if (websocket.readyState === WebSocket4.OPEN) {
3382
+ websocket._readyState = WebSocket4.CLOSING;
3383
+ setCloseTimer(websocket);
3384
+ }
3385
+ this._socket.end();
3386
+ if (!websocket._errorEmitted) {
3387
+ websocket._errorEmitted = true;
3388
+ websocket.emit("error", err);
3389
+ }
3390
+ }
3391
+ function setCloseTimer(websocket) {
3392
+ websocket._closeTimer = setTimeout(
3393
+ websocket._socket.destroy.bind(websocket._socket),
3394
+ closeTimeout
3395
+ );
3396
+ }
3397
+ function socketOnClose() {
3398
+ const websocket = this[kWebSocket];
3399
+ this.removeListener("close", socketOnClose);
3400
+ this.removeListener("data", socketOnData);
3401
+ this.removeListener("end", socketOnEnd);
3402
+ websocket._readyState = WebSocket4.CLOSING;
3403
+ let chunk;
3404
+ if (!this._readableState.endEmitted && !websocket._closeFrameReceived && !websocket._receiver._writableState.errorEmitted && (chunk = websocket._socket.read()) !== null) {
3405
+ websocket._receiver.write(chunk);
3406
+ }
3407
+ websocket._receiver.end();
3408
+ this[kWebSocket] = void 0;
3409
+ clearTimeout(websocket._closeTimer);
3410
+ if (websocket._receiver._writableState.finished || websocket._receiver._writableState.errorEmitted) {
3411
+ websocket.emitClose();
3412
+ } else {
3413
+ websocket._receiver.on("error", receiverOnFinish);
3414
+ websocket._receiver.on("finish", receiverOnFinish);
3415
+ }
3416
+ }
3417
+ function socketOnData(chunk) {
3418
+ if (!this[kWebSocket]._receiver.write(chunk)) {
3419
+ this.pause();
3420
+ }
3421
+ }
3422
+ function socketOnEnd() {
3423
+ const websocket = this[kWebSocket];
3424
+ websocket._readyState = WebSocket4.CLOSING;
3425
+ websocket._receiver.end();
3426
+ this.end();
3427
+ }
3428
+ function socketOnError() {
3429
+ const websocket = this[kWebSocket];
3430
+ this.removeListener("error", socketOnError);
3431
+ this.on("error", NOOP);
3432
+ if (websocket) {
3433
+ websocket._readyState = WebSocket4.CLOSING;
3434
+ this.destroy();
3435
+ }
3436
+ }
3437
+ }
3438
+ });
3439
+
3440
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/stream.js
3441
+ var require_stream = __commonJS({
3442
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/stream.js"(exports, module) {
3443
+ "use strict";
3444
+ var WebSocket4 = require_websocket();
3445
+ var { Duplex } = __require("stream");
3446
+ function emitClose(stream) {
3447
+ stream.emit("close");
3448
+ }
3449
+ function duplexOnEnd() {
3450
+ if (!this.destroyed && this._writableState.finished) {
3451
+ this.destroy();
3452
+ }
3453
+ }
3454
+ function duplexOnError(err) {
3455
+ this.removeListener("error", duplexOnError);
3456
+ this.destroy();
3457
+ if (this.listenerCount("error") === 0) {
3458
+ this.emit("error", err);
3459
+ }
3460
+ }
3461
+ function createWebSocketStream2(ws, options) {
3462
+ let terminateOnDestroy = true;
3463
+ const duplex = new Duplex({
3464
+ ...options,
3465
+ autoDestroy: false,
3466
+ emitClose: false,
3467
+ objectMode: false,
3468
+ writableObjectMode: false
3469
+ });
3470
+ ws.on("message", function message(msg, isBinary) {
3471
+ const data = !isBinary && duplex._readableState.objectMode ? msg.toString() : msg;
3472
+ if (!duplex.push(data))
3473
+ ws.pause();
3474
+ });
3475
+ ws.once("error", function error(err) {
3476
+ if (duplex.destroyed)
3477
+ return;
3478
+ terminateOnDestroy = false;
3479
+ duplex.destroy(err);
3480
+ });
3481
+ ws.once("close", function close() {
3482
+ if (duplex.destroyed)
3483
+ return;
3484
+ duplex.push(null);
3485
+ });
3486
+ duplex._destroy = function(err, callback) {
3487
+ if (ws.readyState === ws.CLOSED) {
3488
+ callback(err);
3489
+ process.nextTick(emitClose, duplex);
3490
+ return;
3491
+ }
3492
+ let called = false;
3493
+ ws.once("error", function error(err2) {
3494
+ called = true;
3495
+ callback(err2);
3496
+ });
3497
+ ws.once("close", function close() {
3498
+ if (!called)
3499
+ callback(err);
3500
+ process.nextTick(emitClose, duplex);
3501
+ });
3502
+ if (terminateOnDestroy)
3503
+ ws.terminate();
3504
+ };
3505
+ duplex._final = function(callback) {
3506
+ if (ws.readyState === ws.CONNECTING) {
3507
+ ws.once("open", function open() {
3508
+ duplex._final(callback);
3509
+ });
3510
+ return;
3511
+ }
3512
+ if (ws._socket === null)
3513
+ return;
3514
+ if (ws._socket._writableState.finished) {
3515
+ callback();
3516
+ if (duplex._readableState.endEmitted)
3517
+ duplex.destroy();
3518
+ } else {
3519
+ ws._socket.once("finish", function finish() {
3520
+ callback();
3521
+ });
3522
+ ws.close();
3523
+ }
3524
+ };
3525
+ duplex._read = function() {
3526
+ if (ws.isPaused)
3527
+ ws.resume();
3528
+ };
3529
+ duplex._write = function(chunk, encoding, callback) {
3530
+ if (ws.readyState === ws.CONNECTING) {
3531
+ ws.once("open", function open() {
3532
+ duplex._write(chunk, encoding, callback);
3533
+ });
3534
+ return;
3535
+ }
3536
+ ws.send(chunk, callback);
3537
+ };
3538
+ duplex.on("end", duplexOnEnd);
3539
+ duplex.on("error", duplexOnError);
3540
+ return duplex;
3541
+ }
3542
+ module.exports = createWebSocketStream2;
3543
+ }
3544
+ });
3545
+
3546
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/subprotocol.js
3547
+ var require_subprotocol = __commonJS({
3548
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/subprotocol.js"(exports, module) {
3549
+ "use strict";
3550
+ var { tokenChars } = require_validation();
3551
+ function parse(header) {
3552
+ const protocols = /* @__PURE__ */ new Set();
3553
+ let start = -1;
3554
+ let end = -1;
3555
+ let i = 0;
3556
+ for (i; i < header.length; i++) {
3557
+ const code = header.charCodeAt(i);
3558
+ if (end === -1 && tokenChars[code] === 1) {
3559
+ if (start === -1)
3560
+ start = i;
3561
+ } else if (i !== 0 && (code === 32 || code === 9)) {
3562
+ if (end === -1 && start !== -1)
3563
+ end = i;
3564
+ } else if (code === 44) {
3565
+ if (start === -1) {
3566
+ throw new SyntaxError(`Unexpected character at index ${i}`);
3567
+ }
3568
+ if (end === -1)
3569
+ end = i;
3570
+ const protocol2 = header.slice(start, end);
3571
+ if (protocols.has(protocol2)) {
3572
+ throw new SyntaxError(`The "${protocol2}" subprotocol is duplicated`);
3573
+ }
3574
+ protocols.add(protocol2);
3575
+ start = end = -1;
3576
+ } else {
3577
+ throw new SyntaxError(`Unexpected character at index ${i}`);
3578
+ }
3579
+ }
3580
+ if (start === -1 || end !== -1) {
3581
+ throw new SyntaxError("Unexpected end of input");
3582
+ }
3583
+ const protocol = header.slice(start, i);
3584
+ if (protocols.has(protocol)) {
3585
+ throw new SyntaxError(`The "${protocol}" subprotocol is duplicated`);
3586
+ }
3587
+ protocols.add(protocol);
3588
+ return protocols;
3589
+ }
3590
+ module.exports = { parse };
3591
+ }
3592
+ });
3593
+
3594
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/websocket-server.js
3595
+ var require_websocket_server = __commonJS({
3596
+ "../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/lib/websocket-server.js"(exports, module) {
3597
+ "use strict";
3598
+ var EventEmitter = __require("events");
3599
+ var http = __require("http");
3600
+ var { Duplex } = __require("stream");
3601
+ var { createHash } = __require("crypto");
3602
+ var extension = require_extension();
3603
+ var PerMessageDeflate = require_permessage_deflate();
3604
+ var subprotocol = require_subprotocol();
3605
+ var WebSocket4 = require_websocket();
3606
+ var { GUID, kWebSocket } = require_constants();
3607
+ var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
3608
+ var RUNNING = 0;
3609
+ var CLOSING = 1;
3610
+ var CLOSED = 2;
3611
+ var WebSocketServer2 = class extends EventEmitter {
3612
+ /**
3613
+ * Create a `WebSocketServer` instance.
3614
+ *
3615
+ * @param {Object} options Configuration options
3616
+ * @param {Boolean} [options.allowSynchronousEvents=true] Specifies whether
3617
+ * any of the `'message'`, `'ping'`, and `'pong'` events can be emitted
3618
+ * multiple times in the same tick
3619
+ * @param {Boolean} [options.autoPong=true] Specifies whether or not to
3620
+ * automatically send a pong in response to a ping
3621
+ * @param {Number} [options.backlog=511] The maximum length of the queue of
3622
+ * pending connections
3623
+ * @param {Boolean} [options.clientTracking=true] Specifies whether or not to
3624
+ * track clients
3625
+ * @param {Function} [options.handleProtocols] A hook to handle protocols
3626
+ * @param {String} [options.host] The hostname where to bind the server
3627
+ * @param {Number} [options.maxPayload=104857600] The maximum allowed message
3628
+ * size
3629
+ * @param {Boolean} [options.noServer=false] Enable no server mode
3630
+ * @param {String} [options.path] Accept only connections matching this path
3631
+ * @param {(Boolean|Object)} [options.perMessageDeflate=false] Enable/disable
3632
+ * permessage-deflate
3633
+ * @param {Number} [options.port] The port where to bind the server
3634
+ * @param {(http.Server|https.Server)} [options.server] A pre-created HTTP/S
3635
+ * server to use
3636
+ * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
3637
+ * not to skip UTF-8 validation for text and close messages
3638
+ * @param {Function} [options.verifyClient] A hook to reject connections
3639
+ * @param {Function} [options.WebSocket=WebSocket] Specifies the `WebSocket`
3640
+ * class to use. It must be the `WebSocket` class or class that extends it
3641
+ * @param {Function} [callback] A listener for the `listening` event
3642
+ */
3643
+ constructor(options, callback) {
3644
+ super();
3645
+ options = {
3646
+ allowSynchronousEvents: true,
3647
+ autoPong: true,
3648
+ maxPayload: 100 * 1024 * 1024,
3649
+ skipUTF8Validation: false,
3650
+ perMessageDeflate: false,
3651
+ handleProtocols: null,
3652
+ clientTracking: true,
3653
+ verifyClient: null,
3654
+ noServer: false,
3655
+ backlog: null,
3656
+ // use default (511 as implemented in net.js)
3657
+ server: null,
3658
+ host: null,
3659
+ path: null,
3660
+ port: null,
3661
+ WebSocket: WebSocket4,
3662
+ ...options
3663
+ };
3664
+ if (options.port == null && !options.server && !options.noServer || options.port != null && (options.server || options.noServer) || options.server && options.noServer) {
3665
+ throw new TypeError(
3666
+ 'One and only one of the "port", "server", or "noServer" options must be specified'
3667
+ );
3668
+ }
3669
+ if (options.port != null) {
3670
+ this._server = http.createServer((req, res) => {
3671
+ const body = http.STATUS_CODES[426];
3672
+ res.writeHead(426, {
3673
+ "Content-Length": body.length,
3674
+ "Content-Type": "text/plain"
3675
+ });
3676
+ res.end(body);
3677
+ });
3678
+ this._server.listen(
3679
+ options.port,
3680
+ options.host,
3681
+ options.backlog,
3682
+ callback
3683
+ );
3684
+ } else if (options.server) {
3685
+ this._server = options.server;
3686
+ }
3687
+ if (this._server) {
3688
+ const emitConnection = this.emit.bind(this, "connection");
3689
+ this._removeListeners = addListeners(this._server, {
3690
+ listening: this.emit.bind(this, "listening"),
3691
+ error: this.emit.bind(this, "error"),
3692
+ upgrade: (req, socket, head) => {
3693
+ this.handleUpgrade(req, socket, head, emitConnection);
3694
+ }
3695
+ });
3696
+ }
3697
+ if (options.perMessageDeflate === true)
3698
+ options.perMessageDeflate = {};
3699
+ if (options.clientTracking) {
3700
+ this.clients = /* @__PURE__ */ new Set();
3701
+ this._shouldEmitClose = false;
3702
+ }
3703
+ this.options = options;
3704
+ this._state = RUNNING;
3705
+ }
3706
+ /**
3707
+ * Returns the bound address, the address family name, and port of the server
3708
+ * as reported by the operating system if listening on an IP socket.
3709
+ * If the server is listening on a pipe or UNIX domain socket, the name is
3710
+ * returned as a string.
3711
+ *
3712
+ * @return {(Object|String|null)} The address of the server
3713
+ * @public
3714
+ */
3715
+ address() {
3716
+ if (this.options.noServer) {
3717
+ throw new Error('The server is operating in "noServer" mode');
3718
+ }
3719
+ if (!this._server)
3720
+ return null;
3721
+ return this._server.address();
3722
+ }
3723
+ /**
3724
+ * Stop the server from accepting new connections and emit the `'close'` event
3725
+ * when all existing connections are closed.
3726
+ *
3727
+ * @param {Function} [cb] A one-time listener for the `'close'` event
3728
+ * @public
3729
+ */
3730
+ close(cb) {
3731
+ if (this._state === CLOSED) {
3732
+ if (cb) {
3733
+ this.once("close", () => {
3734
+ cb(new Error("The server is not running"));
3735
+ });
3736
+ }
3737
+ process.nextTick(emitClose, this);
3738
+ return;
3739
+ }
3740
+ if (cb)
3741
+ this.once("close", cb);
3742
+ if (this._state === CLOSING)
3743
+ return;
3744
+ this._state = CLOSING;
3745
+ if (this.options.noServer || this.options.server) {
3746
+ if (this._server) {
3747
+ this._removeListeners();
3748
+ this._removeListeners = this._server = null;
3749
+ }
3750
+ if (this.clients) {
3751
+ if (!this.clients.size) {
3752
+ process.nextTick(emitClose, this);
3753
+ } else {
3754
+ this._shouldEmitClose = true;
3755
+ }
3756
+ } else {
3757
+ process.nextTick(emitClose, this);
3758
+ }
3759
+ } else {
3760
+ const server = this._server;
3761
+ this._removeListeners();
3762
+ this._removeListeners = this._server = null;
3763
+ server.close(() => {
3764
+ emitClose(this);
3765
+ });
3766
+ }
3767
+ }
3768
+ /**
3769
+ * See if a given request should be handled by this server instance.
3770
+ *
3771
+ * @param {http.IncomingMessage} req Request object to inspect
3772
+ * @return {Boolean} `true` if the request is valid, else `false`
3773
+ * @public
3774
+ */
3775
+ shouldHandle(req) {
3776
+ if (this.options.path) {
3777
+ const index = req.url.indexOf("?");
3778
+ const pathname = index !== -1 ? req.url.slice(0, index) : req.url;
3779
+ if (pathname !== this.options.path)
3780
+ return false;
3781
+ }
3782
+ return true;
3783
+ }
3784
+ /**
3785
+ * Handle a HTTP Upgrade request.
3786
+ *
3787
+ * @param {http.IncomingMessage} req The request object
3788
+ * @param {Duplex} socket The network socket between the server and client
3789
+ * @param {Buffer} head The first packet of the upgraded stream
3790
+ * @param {Function} cb Callback
3791
+ * @public
3792
+ */
3793
+ handleUpgrade(req, socket, head, cb) {
3794
+ socket.on("error", socketOnError);
3795
+ const key = req.headers["sec-websocket-key"];
3796
+ const upgrade = req.headers.upgrade;
3797
+ const version = +req.headers["sec-websocket-version"];
3798
+ if (req.method !== "GET") {
3799
+ const message = "Invalid HTTP method";
3800
+ abortHandshakeOrEmitwsClientError(this, req, socket, 405, message);
3801
+ return;
3802
+ }
3803
+ if (upgrade === void 0 || upgrade.toLowerCase() !== "websocket") {
3804
+ const message = "Invalid Upgrade header";
3805
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3806
+ return;
3807
+ }
3808
+ if (key === void 0 || !keyRegex.test(key)) {
3809
+ const message = "Missing or invalid Sec-WebSocket-Key header";
3810
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3811
+ return;
3812
+ }
3813
+ if (version !== 13 && version !== 8) {
3814
+ const message = "Missing or invalid Sec-WebSocket-Version header";
3815
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message, {
3816
+ "Sec-WebSocket-Version": "13, 8"
3817
+ });
3818
+ return;
3819
+ }
3820
+ if (!this.shouldHandle(req)) {
3821
+ abortHandshake(socket, 400);
3822
+ return;
3823
+ }
3824
+ const secWebSocketProtocol = req.headers["sec-websocket-protocol"];
3825
+ let protocols = /* @__PURE__ */ new Set();
3826
+ if (secWebSocketProtocol !== void 0) {
3827
+ try {
3828
+ protocols = subprotocol.parse(secWebSocketProtocol);
3829
+ } catch (err) {
3830
+ const message = "Invalid Sec-WebSocket-Protocol header";
3831
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3832
+ return;
3833
+ }
3834
+ }
3835
+ const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
3836
+ const extensions = {};
3837
+ if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
3838
+ const perMessageDeflate = new PerMessageDeflate(
3839
+ this.options.perMessageDeflate,
3840
+ true,
3841
+ this.options.maxPayload
3842
+ );
3843
+ try {
3844
+ const offers = extension.parse(secWebSocketExtensions);
3845
+ if (offers[PerMessageDeflate.extensionName]) {
3846
+ perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
3847
+ extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3848
+ }
3849
+ } catch (err) {
3850
+ const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
3851
+ abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
3852
+ return;
3853
+ }
3854
+ }
3855
+ if (this.options.verifyClient) {
3856
+ const info = {
3857
+ origin: req.headers[`${version === 8 ? "sec-websocket-origin" : "origin"}`],
3858
+ secure: !!(req.socket.authorized || req.socket.encrypted),
3859
+ req
3860
+ };
3861
+ if (this.options.verifyClient.length === 2) {
3862
+ this.options.verifyClient(info, (verified, code, message, headers) => {
3863
+ if (!verified) {
3864
+ return abortHandshake(socket, code || 401, message, headers);
3865
+ }
3866
+ this.completeUpgrade(
3867
+ extensions,
3868
+ key,
3869
+ protocols,
3870
+ req,
3871
+ socket,
3872
+ head,
3873
+ cb
3874
+ );
3875
+ });
3876
+ return;
3877
+ }
3878
+ if (!this.options.verifyClient(info))
3879
+ return abortHandshake(socket, 401);
3880
+ }
3881
+ this.completeUpgrade(extensions, key, protocols, req, socket, head, cb);
3882
+ }
3883
+ /**
3884
+ * Upgrade the connection to WebSocket.
3885
+ *
3886
+ * @param {Object} extensions The accepted extensions
3887
+ * @param {String} key The value of the `Sec-WebSocket-Key` header
3888
+ * @param {Set} protocols The subprotocols
3889
+ * @param {http.IncomingMessage} req The request object
3890
+ * @param {Duplex} socket The network socket between the server and client
3891
+ * @param {Buffer} head The first packet of the upgraded stream
3892
+ * @param {Function} cb Callback
3893
+ * @throws {Error} If called more than once with the same socket
3894
+ * @private
3895
+ */
3896
+ completeUpgrade(extensions, key, protocols, req, socket, head, cb) {
3897
+ if (!socket.readable || !socket.writable)
3898
+ return socket.destroy();
3899
+ if (socket[kWebSocket]) {
3900
+ throw new Error(
3901
+ "server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration"
3902
+ );
3903
+ }
3904
+ if (this._state > RUNNING)
3905
+ return abortHandshake(socket, 503);
3906
+ const digest = createHash("sha1").update(key + GUID).digest("base64");
3907
+ const headers = [
3908
+ "HTTP/1.1 101 Switching Protocols",
3909
+ "Upgrade: websocket",
3910
+ "Connection: Upgrade",
3911
+ `Sec-WebSocket-Accept: ${digest}`
3912
+ ];
3913
+ const ws = new this.options.WebSocket(null, void 0, this.options);
3914
+ if (protocols.size) {
3915
+ const protocol = this.options.handleProtocols ? this.options.handleProtocols(protocols, req) : protocols.values().next().value;
3916
+ if (protocol) {
3917
+ headers.push(`Sec-WebSocket-Protocol: ${protocol}`);
3918
+ ws._protocol = protocol;
3919
+ }
3920
+ }
3921
+ if (extensions[PerMessageDeflate.extensionName]) {
3922
+ const params = extensions[PerMessageDeflate.extensionName].params;
3923
+ const value = extension.format({
3924
+ [PerMessageDeflate.extensionName]: [params]
3925
+ });
3926
+ headers.push(`Sec-WebSocket-Extensions: ${value}`);
3927
+ ws._extensions = extensions;
3928
+ }
3929
+ this.emit("headers", headers, req);
3930
+ socket.write(headers.concat("\r\n").join("\r\n"));
3931
+ socket.removeListener("error", socketOnError);
3932
+ ws.setSocket(socket, head, {
3933
+ allowSynchronousEvents: this.options.allowSynchronousEvents,
3934
+ maxPayload: this.options.maxPayload,
3935
+ skipUTF8Validation: this.options.skipUTF8Validation
3936
+ });
3937
+ if (this.clients) {
3938
+ this.clients.add(ws);
3939
+ ws.on("close", () => {
3940
+ this.clients.delete(ws);
3941
+ if (this._shouldEmitClose && !this.clients.size) {
3942
+ process.nextTick(emitClose, this);
3943
+ }
3944
+ });
3945
+ }
3946
+ cb(ws, req);
3947
+ }
3948
+ };
3949
+ module.exports = WebSocketServer2;
3950
+ function addListeners(server, map) {
3951
+ for (const event of Object.keys(map))
3952
+ server.on(event, map[event]);
3953
+ return function removeListeners() {
3954
+ for (const event of Object.keys(map)) {
3955
+ server.removeListener(event, map[event]);
3956
+ }
3957
+ };
3958
+ }
3959
+ function emitClose(server) {
3960
+ server._state = CLOSED;
3961
+ server.emit("close");
3962
+ }
3963
+ function socketOnError() {
3964
+ this.destroy();
3965
+ }
3966
+ function abortHandshake(socket, code, message, headers) {
3967
+ message = message || http.STATUS_CODES[code];
3968
+ headers = {
3969
+ Connection: "close",
3970
+ "Content-Type": "text/html",
3971
+ "Content-Length": Buffer.byteLength(message),
3972
+ ...headers
3973
+ };
3974
+ socket.once("finish", socket.destroy);
3975
+ socket.end(
3976
+ `HTTP/1.1 ${code} ${http.STATUS_CODES[code]}\r
3977
+ ` + Object.keys(headers).map((h) => `${h}: ${headers[h]}`).join("\r\n") + "\r\n\r\n" + message
3978
+ );
3979
+ }
3980
+ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message, headers) {
3981
+ if (server.listenerCount("wsClientError")) {
3982
+ const err = new Error(message);
3983
+ Error.captureStackTrace(err, abortHandshakeOrEmitwsClientError);
3984
+ server.emit("wsClientError", err, socket, req);
3985
+ } else {
3986
+ abortHandshake(socket, code, message, headers);
3987
+ }
3988
+ }
3989
+ }
3990
+ });
3991
+
3992
+ // ../../node_modules/.pnpm/ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10/node_modules/ws/wrapper.mjs
3993
+ var wrapper_exports = {};
3994
+ __export(wrapper_exports, {
3995
+ Receiver: () => import_receiver.default,
3996
+ Sender: () => import_sender.default,
3997
+ WebSocket: () => import_websocket.default,
3998
+ WebSocketServer: () => import_websocket_server.default,
3999
+ createWebSocketStream: () => import_stream.default,
4000
+ default: () => wrapper_default
4001
+ });
4002
+ var import_stream = __toESM(require_stream(), 1);
4003
+ var import_receiver = __toESM(require_receiver(), 1);
4004
+ var import_sender = __toESM(require_sender(), 1);
4005
+ var import_websocket = __toESM(require_websocket(), 1);
4006
+ var import_websocket_server = __toESM(require_websocket_server(), 1);
4007
+ var wrapper_default = import_websocket.default;
4008
+
4009
+ // ../../node_modules/.pnpm/isows@1.0.7_ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/isows/_esm/utils.js
4010
+ function getNativeWebSocket() {
4011
+ if (typeof WebSocket !== "undefined")
4012
+ return WebSocket;
4013
+ if (typeof global.WebSocket !== "undefined")
4014
+ return global.WebSocket;
4015
+ if (typeof window.WebSocket !== "undefined")
4016
+ return window.WebSocket;
4017
+ if (typeof self.WebSocket !== "undefined")
4018
+ return self.WebSocket;
4019
+ throw new Error("`WebSocket` is not supported in this environment");
4020
+ }
4021
+
4022
+ // ../../node_modules/.pnpm/isows@1.0.7_ws@8.18.3_bufferutil@4.0.8_utf-8-validate@5.0.10_/node_modules/isows/_esm/index.js
4023
+ var WebSocket3 = (() => {
4024
+ try {
4025
+ return getNativeWebSocket();
4026
+ } catch {
4027
+ if (import_websocket.default)
4028
+ return import_websocket.default;
4029
+ return wrapper_exports;
4030
+ }
4031
+ })();
4032
+ export {
4033
+ WebSocket3 as WebSocket
4034
+ };
4035
+ //# sourceMappingURL=_esm-TZ4WSCGM.js.map