@lendasat/lendaswap-sdk-pure 0.2.42 → 0.2.43

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