@lendasat/lendaswap-sdk-pure 0.2.42 → 0.2.44

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