@tuwaio/satellite-evm 0.0.3

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.
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 FOP Tkach Oleksandr
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # Satellite Connect EVM
2
+
3
+ [![NPM Version](https://img.shields.io/npm/v/@tuwaio/satellite-evm.svg)](https://www.npmjs.com/package/@tuwaio/satellite-evm)
4
+ [![License](https://img.shields.io/npm/l/@tuwaio/satellite-evm.svg)](./LICENSE)
5
+ [![Build Status](https://img.shields.io/github/actions/workflow/status/TuwaIO/satellite-evm/release.yml?branch=main)](https://github.com/TuwaIO/satellite-evm/actions)
6
+
7
+ EVM-specific implementation for the Satellite ecosystem, providing comprehensive utilities and adapters for interacting with EVM wallets and chains.
8
+
9
+ ---
10
+
11
+ ## 🏛️ What is `@tuwaio/satellite-evm`?
12
+
13
+ `@tuwaio/satellite-evm` is the EVM implementation of the Satellite ecosystem's wallet connection system. It provides specialized adapters and utilities for interacting with EVM-compatible wallets and chains like MetaMask, WalletConnect, and others.
14
+
15
+ Built on top of `@tuwaio/satellite-core`, this package integrates seamlessly with modern Web3 libraries like `viem` and `@wagmi/core`.
16
+
17
+ ---
18
+
19
+ ## ✨ Key Features
20
+
21
+ - **EVM Wallet Support:** Native support for popular EVM wallets
22
+ - **Chain Management:** Built-in utilities for handling multiple EVM chains
23
+ - **Type Safety:** Full TypeScript support with proper type definitions
24
+ - **Wagmi Integration:** Seamless integration with @wagmi/core utilities
25
+ - **Modern Architecture:** Built on Viem for optimal performance
26
+
27
+ ---
28
+
29
+ ## 💾 Installation
30
+
31
+ ### Requirements
32
+ - Node.js 20+
33
+ - TypeScript 5.9+
34
+
35
+ ```bash
36
+ # Using pnpm (recommended)
37
+ pnpm add @tuwaio/satellite-evm @tuwaio/satellite-core viem @wagmi/core @wallet-standard/ui immer zustand @wagmi/connectors @tuwaio/orbit-core @tuwaio/orbit-evm
38
+
39
+ # Using npm
40
+ npm install @tuwaio/satellite-evm @tuwaio/satellite-core viem @wagmi/core @wallet-standard/ui immer zustand @wagmi/connectors @tuwaio/orbit-core @tuwaio/orbit-evm
41
+
42
+ # Using yarn
43
+ yarn add @tuwaio/satellite-evm @tuwaio/satellite-core viem @wagmi/core @wallet-standard/ui immer zustand @wagmi/connectors @tuwaio/orbit-core @tuwaio/orbit-evm
44
+ ```
45
+ ---
46
+
47
+ ## 🚀 Quick Start
48
+
49
+ ### Basic Configuration
50
+ ```typescript
51
+ import { createWagmiConfig } from '@tuwaio/satellite-evm';
52
+ import { mainnet, sepolia } from 'viem/chains';
53
+
54
+ const config = createWagmiConfig({
55
+ appName: 'Your App Name',
56
+ projectId: 'your-wallet-project-id',
57
+ chains: [mainnet, sepolia],
58
+ });
59
+ ```
60
+ ---
61
+
62
+ ### Core Components
63
+
64
+ 1. **Adapters**
65
+ - Wallet-specific implementations
66
+ - Chain management utilities
67
+ - Connection state handlers
68
+
69
+ 2. **Connectors**
70
+ - Chain configuration
71
+ - Network management
72
+ - Provider utilities
73
+
74
+ 3. **Utils**
75
+ - Create wagmi config helper with connectors
76
+
77
+ ---
78
+
79
+ ## 🌐 Supported Wallets
80
+
81
+ - MetaMask
82
+ - WalletConnect v2
83
+ - Coinbase Wallet
84
+ - And other EVM-compatible wallets
85
+
86
+ ---
87
+
88
+ ## 🔗 Chain Support
89
+
90
+ Built-in support for major EVM networks:
91
+ - Ethereum Mainnet
92
+ - Sepolia Testnet
93
+ - Polygon
94
+ - Arbitrum
95
+ - Optimism
96
+ - And other EVM-compatible networks
97
+
98
+ ---
99
+
100
+ ## 🤝 Contributing & Support
101
+
102
+ Contributions are welcome! Please read our main **[Contribution Guidelines](https://github.com/TuwaIO/workflows/blob/main/CONTRIBUTING.md)**.
103
+
104
+ If you find this library useful, please consider supporting its development. Every contribution helps!
105
+
106
+ [**➡️ View Support Options**](https://github.com/TuwaIO/workflows/blob/main/Donation.md)
107
+
108
+ ## 📄 License
109
+
110
+ This project is licensed under the **Apache-2.0 License** - see the [LICENSE](./LICENSE) file for details.
111
+
112
+ ## 👥 Contributors
113
+
114
+ - **Oleksandr Tkach** - [GitHub](https://github.com/Argeare5)
@@ -0,0 +1,10 @@
1
+ import {b,a,c,d}from'./chunk-6R4Y2ZVK.mjs';var T=b((li,it)=>{var rt=["nodebuffer","arraybuffer","fragments"],st=typeof Blob<"u";st&&rt.push("blob");it.exports={BINARY_TYPES:rt,EMPTY_BUFFER:Buffer.alloc(0),GUID:"258EAFA5-E914-47DA-95CA-C5AB0DC85B11",hasBlob:st,kForOnEventAttribute:Symbol("kIsForOnEventAttribute"),kListener:Symbol("kListener"),kStatusCode:Symbol("status-code"),kWebSocket:Symbol("websocket"),NOOP:()=>{}};});var St=b((ci,xt)=>{var ft=a("fs"),C=a("path"),lt=a("os"),ct=typeof __webpack_require__=="function"?__non_webpack_require__:a,Ir=process.config&&process.config.variables||{},Dr=!!process.env.PREBUILDS_ONLY,nt=process.versions.modules,ve=Ar()?"electron":Mr()?"node-webkit":"node",Ee=process.env.npm_config_arch||lt.arch(),be=process.env.npm_config_platform||lt.platform(),ht=process.env.LIBC||(qr(be)?"musl":"glibc"),we=process.env.ARM_VERSION||(Ee==="arm64"?"8":Ir.arm_version)||"",ut=(process.versions.uv||"").split(".")[0];xt.exports=k;function k(t){return ct(k.resolve(t))}k.resolve=k.path=function(t){t=C.resolve(t||".");try{var e=ct(C.join(t,"package.json")).name.toUpperCase().replace(/-/g,"_");process.env[e+"_PREBUILD"]&&(t=process.env[e+"_PREBUILD"]);}catch{}if(!Dr){var r=ot(C.join(t,"build/Release"),at);if(r)return r;var s=ot(C.join(t,"build/Debug"),at);if(s)return s}var i=f(t);if(i)return i;var n=f(C.dirname(process.execPath));if(n)return n;var o=["platform="+be,"arch="+Ee,"runtime="+ve,"abi="+nt,"uv="+ut,we?"armv="+we:"","libc="+ht,"node="+process.versions.node,process.versions.electron?"electron="+process.versions.electron:"",typeof __webpack_require__=="function"?"webpack=true":""].filter(Boolean).join(" ");throw new Error("No native build was found for "+o+`
2
+ loaded from: `+t+`
3
+ `);function f(l){var a=ke(C.join(l,"prebuilds")).map(dt),c=a.filter(_t(be,Ee)).sort(pt)[0];if(c){var h=C.join(l,"prebuilds",c.name),d=ke(h).map(mt),y=d.filter(yt(ve,nt)),p=y.sort(gt(ve))[0];if(p)return C.join(h,p.file)}}};function ke(t){try{return ft.readdirSync(t)}catch{return []}}function ot(t,e){var r=ke(t).filter(e);return r[0]&&C.join(t,r[0])}function at(t){return /\.node$/.test(t)}function dt(t){var e=t.split("-");if(e.length===2){var r=e[0],s=e[1].split("+");if(r&&s.length&&s.every(Boolean))return {name:t,platform:r,architectures:s}}}function _t(t,e){return function(r){return r==null||r.platform!==t?false:r.architectures.includes(e)}}function pt(t,e){return t.architectures.length-e.architectures.length}function mt(t){var e=t.split("."),r=e.pop(),s={file:t,specificity:0};if(r==="node"){for(var i=0;i<e.length;i++){var n=e[i];if(n==="node"||n==="electron"||n==="node-webkit")s.runtime=n;else if(n==="napi")s.napi=true;else if(n.slice(0,3)==="abi")s.abi=n.slice(3);else if(n.slice(0,2)==="uv")s.uv=n.slice(2);else if(n.slice(0,4)==="armv")s.armv=n.slice(4);else if(n==="glibc"||n==="musl")s.libc=n;else continue;s.specificity++;}return s}}function yt(t,e){return function(r){return !(r==null||r.runtime&&r.runtime!==t&&!Wr(r)||r.abi&&r.abi!==e&&!r.napi||r.uv&&r.uv!==ut||r.armv&&r.armv!==we||r.libc&&r.libc!==ht)}}function Wr(t){return t.runtime==="node"&&t.napi}function gt(t){return function(e,r){return e.runtime!==r.runtime?e.runtime===t?-1:1:e.abi!==r.abi?e.abi?-1:1:e.specificity!==r.specificity?e.specificity>r.specificity?-1:1:0}}function Mr(){return !!(process.versions&&process.versions.nw)}function Ar(){return process.versions&&process.versions.electron||process.env.ELECTRON_RUN_AS_NODE?true:typeof window<"u"&&window.process&&window.process.type==="renderer"}function qr(t){return t==="linux"&&ft.existsSync("/etc/alpine-release")}k.parseTags=mt;k.matchTags=yt;k.compareTags=gt;k.parseTuple=dt;k.matchTuple=_t;k.compareTuples=pt;});var Ce=b((ui,Te)=>{var Oe=typeof __webpack_require__=="function"?__non_webpack_require__:a;typeof Oe.addon=="function"?Te.exports=Oe.addon.bind(Oe):Te.exports=St();});var Et=b((_i,vt)=>{var Fr=(t,e,r,s,i)=>{for(var n=0;n<i;n++)r[s+n]=t[n]^e[n&3];},jr=(t,e)=>{let r=t.length;for(var s=0;s<r;s++)t[s]^=e[s&3];};vt.exports={mask:Fr,unmask:jr};});var bt=b((pi,Ne)=>{try{Ne.exports=Ce()(__dirname);}catch{Ne.exports=Et();}});var Q=b((mi,oe)=>{var{EMPTY_BUFFER:Gr}=T(),Le=Buffer[Symbol.species];function $r(t,e){if(t.length===0)return Gr;if(t.length===1)return t[0];let r=Buffer.allocUnsafe(e),s=0;for(let i=0;i<t.length;i++){let n=t[i];r.set(n,s),s+=n.length;}return s<e?new Le(r.buffer,r.byteOffset,s):r}function wt(t,e,r,s,i){for(let n=0;n<i;n++)r[s+n]=t[n]^e[n&3];}function kt(t,e){for(let r=0;r<t.length;r++)t[r]^=e[r&3];}function Vr(t){return t.length===t.buffer.byteLength?t.buffer:t.buffer.slice(t.byteOffset,t.byteOffset+t.length)}function Pe(t){if(Pe.readOnly=true,Buffer.isBuffer(t))return t;let e;return t instanceof ArrayBuffer?e=new Le(t):ArrayBuffer.isView(t)?e=new Le(t.buffer,t.byteOffset,t.byteLength):(e=Buffer.from(t),Pe.readOnly=false),e}oe.exports={concat:$r,mask:wt,toArrayBuffer:Vr,toBuffer:Pe,unmask:kt};if(!process.env.WS_NO_BUFFER_UTIL)try{let t=bt();oe.exports.mask=function(e,r,s,i,n){n<48?wt(e,r,s,i,n):t.mask(e,r,s,i,n);},oe.exports.unmask=function(e,r){e.length<32?kt(e,r):t.unmask(e,r);};}catch{}});var Ct=b((yi,Tt)=>{var Ot=Symbol("kDone"),Be=Symbol("kRun"),Re=class{constructor(e){this[Ot]=()=>{this.pending--,this[Be]();},this.concurrency=e||1/0,this.jobs=[],this.pending=0;}add(e){this.jobs.push(e),this[Be]();}[Be](){if(this.pending!==this.concurrency&&this.jobs.length){let e=this.jobs.shift();this.pending++,e(this[Ot]);}}};Tt.exports=Re;});var ee=b((gi,Bt)=>{var J=a("zlib"),Nt=Q(),zr=Ct(),{kStatusCode:Lt}=T(),Hr=Buffer[Symbol.species],Yr=Buffer.from([0,0,255,255]),fe=Symbol("permessage-deflate"),N=Symbol("total-length"),F=Symbol("callback"),B=Symbol("buffers"),j=Symbol("error"),ae,Ue=class{constructor(e,r,s){if(this._maxPayload=s|0,this._options=e||{},this._threshold=this._options.threshold!==void 0?this._options.threshold:1024,this._isServer=!!r,this._deflate=null,this._inflate=null,this.params=null,!ae){let i=this._options.concurrencyLimit!==void 0?this._options.concurrencyLimit:10;ae=new zr(i);}}static get extensionName(){return "permessage-deflate"}offer(){let e={};return this._options.serverNoContextTakeover&&(e.server_no_context_takeover=true),this._options.clientNoContextTakeover&&(e.client_no_context_takeover=true),this._options.serverMaxWindowBits&&(e.server_max_window_bits=this._options.serverMaxWindowBits),this._options.clientMaxWindowBits?e.client_max_window_bits=this._options.clientMaxWindowBits:this._options.clientMaxWindowBits==null&&(e.client_max_window_bits=true),e}accept(e){return e=this.normalizeParams(e),this.params=this._isServer?this.acceptAsServer(e):this.acceptAsClient(e),this.params}cleanup(){if(this._inflate&&(this._inflate.close(),this._inflate=null),this._deflate){let e=this._deflate[F];this._deflate.close(),this._deflate=null,e&&e(new Error("The deflate stream was closed while data was being processed"));}}acceptAsServer(e){let r=this._options,s=e.find(i=>!(r.serverNoContextTakeover===false&&i.server_no_context_takeover||i.server_max_window_bits&&(r.serverMaxWindowBits===false||typeof r.serverMaxWindowBits=="number"&&r.serverMaxWindowBits>i.server_max_window_bits)||typeof r.clientMaxWindowBits=="number"&&!i.client_max_window_bits));if(!s)throw new Error("None of the extension offers can be accepted");return r.serverNoContextTakeover&&(s.server_no_context_takeover=true),r.clientNoContextTakeover&&(s.client_no_context_takeover=true),typeof r.serverMaxWindowBits=="number"&&(s.server_max_window_bits=r.serverMaxWindowBits),typeof r.clientMaxWindowBits=="number"?s.client_max_window_bits=r.clientMaxWindowBits:(s.client_max_window_bits===true||r.clientMaxWindowBits===false)&&delete s.client_max_window_bits,s}acceptAsClient(e){let r=e[0];if(this._options.clientNoContextTakeover===false&&r.client_no_context_takeover)throw new Error('Unexpected parameter "client_no_context_takeover"');if(!r.client_max_window_bits)typeof this._options.clientMaxWindowBits=="number"&&(r.client_max_window_bits=this._options.clientMaxWindowBits);else if(this._options.clientMaxWindowBits===false||typeof this._options.clientMaxWindowBits=="number"&&r.client_max_window_bits>this._options.clientMaxWindowBits)throw new Error('Unexpected or invalid parameter "client_max_window_bits"');return r}normalizeParams(e){return e.forEach(r=>{Object.keys(r).forEach(s=>{let i=r[s];if(i.length>1)throw new Error(`Parameter "${s}" must have only a single value`);if(i=i[0],s==="client_max_window_bits"){if(i!==true){let n=+i;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${s}": ${i}`);i=n;}else if(!this._isServer)throw new TypeError(`Invalid value for parameter "${s}": ${i}`)}else if(s==="server_max_window_bits"){let n=+i;if(!Number.isInteger(n)||n<8||n>15)throw new TypeError(`Invalid value for parameter "${s}": ${i}`);i=n;}else if(s==="client_no_context_takeover"||s==="server_no_context_takeover"){if(i!==true)throw new TypeError(`Invalid value for parameter "${s}": ${i}`)}else throw new Error(`Unknown parameter "${s}"`);r[s]=i;});}),e}decompress(e,r,s){ae.add(i=>{this._decompress(e,r,(n,o)=>{i(),s(n,o);});});}compress(e,r,s){ae.add(i=>{this._compress(e,r,(n,o)=>{i(),s(n,o);});});}_decompress(e,r,s){let i=this._isServer?"client":"server";if(!this._inflate){let n=`${i}_max_window_bits`,o=typeof this.params[n]!="number"?J.Z_DEFAULT_WINDOWBITS:this.params[n];this._inflate=J.createInflateRaw({...this._options.zlibInflateOptions,windowBits:o}),this._inflate[fe]=this,this._inflate[N]=0,this._inflate[B]=[],this._inflate.on("error",Xr),this._inflate.on("data",Pt);}this._inflate[F]=s,this._inflate.write(e),r&&this._inflate.write(Yr),this._inflate.flush(()=>{let n=this._inflate[j];if(n){this._inflate.close(),this._inflate=null,s(n);return}let o=Nt.concat(this._inflate[B],this._inflate[N]);this._inflate._readableState.endEmitted?(this._inflate.close(),this._inflate=null):(this._inflate[N]=0,this._inflate[B]=[],r&&this.params[`${i}_no_context_takeover`]&&this._inflate.reset()),s(null,o);});}_compress(e,r,s){let i=this._isServer?"server":"client";if(!this._deflate){let n=`${i}_max_window_bits`,o=typeof this.params[n]!="number"?J.Z_DEFAULT_WINDOWBITS:this.params[n];this._deflate=J.createDeflateRaw({...this._options.zlibDeflateOptions,windowBits:o}),this._deflate[N]=0,this._deflate[B]=[],this._deflate.on("data",Kr);}this._deflate[F]=s,this._deflate.write(e),this._deflate.flush(J.Z_SYNC_FLUSH,()=>{if(!this._deflate)return;let n=Nt.concat(this._deflate[B],this._deflate[N]);r&&(n=new Hr(n.buffer,n.byteOffset,n.length-4)),this._deflate[F]=null,this._deflate[N]=0,this._deflate[B]=[],r&&this.params[`${i}_no_context_takeover`]&&this._deflate.reset(),s(null,n);});}};Bt.exports=Ue;function Kr(t){this[B].push(t),this[N]+=t.length;}function Pt(t){if(this[N]+=t.length,this[fe]._maxPayload<1||this[N]<=this[fe]._maxPayload){this[B].push(t);return}this[j]=new RangeError("Max payload size exceeded"),this[j].code="WS_ERR_UNSUPPORTED_MESSAGE_LENGTH",this[j][Lt]=1009,this.removeListener("data",Pt),this.reset();}function Xr(t){if(this[fe]._inflate=null,this[j]){this[F](this[j]);return}t[Lt]=1007,this[F](t);}});var Ut=b((xi,Rt)=>{function Zr(t){let e=t.length,r=0;for(;r<e;)if((t[r]&128)===0)r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return false;r+=2;}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return false;r+=3;}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return false;r+=4;}else return false;return true}Rt.exports=Zr;});var It=b((Si,Ie)=>{try{Ie.exports=Ce()(__dirname);}catch{Ie.exports=Ut();}});var G=b((vi,le)=>{var{isUtf8:Dt}=a("buffer"),{hasBlob:Qr}=T(),Jr=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,0];function es(t){return t>=1e3&&t<=1014&&t!==1004&&t!==1005&&t!==1006||t>=3e3&&t<=4999}function De(t){let e=t.length,r=0;for(;r<e;)if((t[r]&128)===0)r++;else if((t[r]&224)===192){if(r+1===e||(t[r+1]&192)!==128||(t[r]&254)===192)return false;r+=2;}else if((t[r]&240)===224){if(r+2>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||t[r]===224&&(t[r+1]&224)===128||t[r]===237&&(t[r+1]&224)===160)return false;r+=3;}else if((t[r]&248)===240){if(r+3>=e||(t[r+1]&192)!==128||(t[r+2]&192)!==128||(t[r+3]&192)!==128||t[r]===240&&(t[r+1]&240)===128||t[r]===244&&t[r+1]>143||t[r]>244)return false;r+=4;}else return false;return true}function ts(t){return Qr&&typeof t=="object"&&typeof t.arrayBuffer=="function"&&typeof t.type=="string"&&typeof t.stream=="function"&&(t[Symbol.toStringTag]==="Blob"||t[Symbol.toStringTag]==="File")}le.exports={isBlob:ts,isValidStatusCode:es,isValidUTF8:De,tokenChars:Jr};if(Dt)le.exports.isValidUTF8=function(t){return t.length<24?De(t):Dt(t)};else if(!process.env.WS_NO_UTF_8_VALIDATE)try{let t=It();le.exports.isValidUTF8=function(e){return e.length<32?De(e):t(e)};}catch{}});var Fe=b((Ei,Gt)=>{var{Writable:rs}=a("stream"),Wt=ee(),{BINARY_TYPES:ss,EMPTY_BUFFER:Mt,kStatusCode:is,kWebSocket:ns}=T(),{concat:We,toArrayBuffer:os,unmask:as}=Q(),{isValidStatusCode:fs,isValidUTF8:At}=G(),ce=Buffer[Symbol.species],E=0,qt=1,Ft=2,jt=3,Me=4,Ae=5,he=6,qe=class extends rs{constructor(e={}){super(),this._allowSynchronousEvents=e.allowSynchronousEvents!==void 0?e.allowSynchronousEvents:true,this._binaryType=e.binaryType||ss[0],this._extensions=e.extensions||{},this._isServer=!!e.isServer,this._maxPayload=e.maxPayload|0,this._skipUTF8Validation=!!e.skipUTF8Validation,this[ns]=void 0,this._bufferedBytes=0,this._buffers=[],this._compressed=false,this._payloadLength=0,this._mask=void 0,this._fragmented=0,this._masked=false,this._fin=false,this._opcode=0,this._totalPayloadLength=0,this._messageLength=0,this._fragments=[],this._errored=false,this._loop=false,this._state=E;}_write(e,r,s){if(this._opcode===8&&this._state==E)return s();this._bufferedBytes+=e.length,this._buffers.push(e),this.startLoop(s);}consume(e){if(this._bufferedBytes-=e,e===this._buffers[0].length)return this._buffers.shift();if(e<this._buffers[0].length){let s=this._buffers[0];return this._buffers[0]=new ce(s.buffer,s.byteOffset+e,s.length-e),new ce(s.buffer,s.byteOffset,e)}let r=Buffer.allocUnsafe(e);do{let s=this._buffers[0],i=r.length-e;e>=s.length?r.set(this._buffers.shift(),i):(r.set(new Uint8Array(s.buffer,s.byteOffset,e),i),this._buffers[0]=new ce(s.buffer,s.byteOffset+e,s.length-e)),e-=s.length;}while(e>0);return r}startLoop(e){this._loop=true;do switch(this._state){case E:this.getInfo(e);break;case qt:this.getPayloadLength16(e);break;case Ft:this.getPayloadLength64(e);break;case jt:this.getMask();break;case Me:this.getData(e);break;case Ae:case he:this._loop=false;return}while(this._loop);this._errored||e();}getInfo(e){if(this._bufferedBytes<2){this._loop=false;return}let r=this.consume(2);if((r[0]&48)!==0){let i=this.createError(RangeError,"RSV2 and RSV3 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_2_3");e(i);return}let s=(r[0]&64)===64;if(s&&!this._extensions[Wt.extensionName]){let i=this.createError(RangeError,"RSV1 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(this._fin=(r[0]&128)===128,this._opcode=r[0]&15,this._payloadLength=r[1]&127,this._opcode===0){if(s){let i=this.createError(RangeError,"RSV1 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(!this._fragmented){let i=this.createError(RangeError,"invalid opcode 0",true,1002,"WS_ERR_INVALID_OPCODE");e(i);return}this._opcode=this._fragmented;}else if(this._opcode===1||this._opcode===2){if(this._fragmented){let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,true,1002,"WS_ERR_INVALID_OPCODE");e(i);return}this._compressed=s;}else if(this._opcode>7&&this._opcode<11){if(!this._fin){let i=this.createError(RangeError,"FIN must be set",true,1002,"WS_ERR_EXPECTED_FIN");e(i);return}if(s){let i=this.createError(RangeError,"RSV1 must be clear",true,1002,"WS_ERR_UNEXPECTED_RSV_1");e(i);return}if(this._payloadLength>125||this._opcode===8&&this._payloadLength===1){let i=this.createError(RangeError,`invalid payload length ${this._payloadLength}`,true,1002,"WS_ERR_INVALID_CONTROL_PAYLOAD_LENGTH");e(i);return}}else {let i=this.createError(RangeError,`invalid opcode ${this._opcode}`,true,1002,"WS_ERR_INVALID_OPCODE");e(i);return}if(!this._fin&&!this._fragmented&&(this._fragmented=this._opcode),this._masked=(r[1]&128)===128,this._isServer){if(!this._masked){let i=this.createError(RangeError,"MASK must be set",true,1002,"WS_ERR_EXPECTED_MASK");e(i);return}}else if(this._masked){let i=this.createError(RangeError,"MASK must be clear",true,1002,"WS_ERR_UNEXPECTED_MASK");e(i);return}this._payloadLength===126?this._state=qt:this._payloadLength===127?this._state=Ft:this.haveLength(e);}getPayloadLength16(e){if(this._bufferedBytes<2){this._loop=false;return}this._payloadLength=this.consume(2).readUInt16BE(0),this.haveLength(e);}getPayloadLength64(e){if(this._bufferedBytes<8){this._loop=false;return}let r=this.consume(8),s=r.readUInt32BE(0);if(s>Math.pow(2,21)-1){let i=this.createError(RangeError,"Unsupported WebSocket frame: payload length > 2^53 - 1",false,1009,"WS_ERR_UNSUPPORTED_DATA_PAYLOAD_LENGTH");e(i);return}this._payloadLength=s*Math.pow(2,32)+r.readUInt32BE(4),this.haveLength(e);}haveLength(e){if(this._payloadLength&&this._opcode<8&&(this._totalPayloadLength+=this._payloadLength,this._totalPayloadLength>this._maxPayload&&this._maxPayload>0)){let r=this.createError(RangeError,"Max payload size exceeded",false,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");e(r);return}this._masked?this._state=jt:this._state=Me;}getMask(){if(this._bufferedBytes<4){this._loop=false;return}this._mask=this.consume(4),this._state=Me;}getData(e){let r=Mt;if(this._payloadLength){if(this._bufferedBytes<this._payloadLength){this._loop=false;return}r=this.consume(this._payloadLength),this._masked&&(this._mask[0]|this._mask[1]|this._mask[2]|this._mask[3])!==0&&as(r,this._mask);}if(this._opcode>7){this.controlMessage(r,e);return}if(this._compressed){this._state=Ae,this.decompress(r,e);return}r.length&&(this._messageLength=this._totalPayloadLength,this._fragments.push(r)),this.dataMessage(e);}decompress(e,r){this._extensions[Wt.extensionName].decompress(e,this._fin,(i,n)=>{if(i)return r(i);if(n.length){if(this._messageLength+=n.length,this._messageLength>this._maxPayload&&this._maxPayload>0){let o=this.createError(RangeError,"Max payload size exceeded",false,1009,"WS_ERR_UNSUPPORTED_MESSAGE_LENGTH");r(o);return}this._fragments.push(n);}this.dataMessage(r),this._state===E&&this.startLoop(r);});}dataMessage(e){if(!this._fin){this._state=E;return}let r=this._messageLength,s=this._fragments;if(this._totalPayloadLength=0,this._messageLength=0,this._fragmented=0,this._fragments=[],this._opcode===2){let i;this._binaryType==="nodebuffer"?i=We(s,r):this._binaryType==="arraybuffer"?i=os(We(s,r)):this._binaryType==="blob"?i=new Blob(s):i=s,this._allowSynchronousEvents?(this.emit("message",i,true),this._state=E):(this._state=he,setImmediate(()=>{this.emit("message",i,true),this._state=E,this.startLoop(e);}));}else {let i=We(s,r);if(!this._skipUTF8Validation&&!At(i)){let n=this.createError(Error,"invalid UTF-8 sequence",true,1007,"WS_ERR_INVALID_UTF8");e(n);return}this._state===Ae||this._allowSynchronousEvents?(this.emit("message",i,false),this._state=E):(this._state=he,setImmediate(()=>{this.emit("message",i,false),this._state=E,this.startLoop(e);}));}}controlMessage(e,r){if(this._opcode===8){if(e.length===0)this._loop=false,this.emit("conclude",1005,Mt),this.end();else {let s=e.readUInt16BE(0);if(!fs(s)){let n=this.createError(RangeError,`invalid status code ${s}`,true,1002,"WS_ERR_INVALID_CLOSE_CODE");r(n);return}let i=new ce(e.buffer,e.byteOffset+2,e.length-2);if(!this._skipUTF8Validation&&!At(i)){let n=this.createError(Error,"invalid UTF-8 sequence",true,1007,"WS_ERR_INVALID_UTF8");r(n);return}this._loop=false,this.emit("conclude",s,i),this.end();}this._state=E;return}this._allowSynchronousEvents?(this.emit(this._opcode===9?"ping":"pong",e),this._state=E):(this._state=he,setImmediate(()=>{this.emit(this._opcode===9?"ping":"pong",e),this._state=E,this.startLoop(r);}));}createError(e,r,s,i,n){this._loop=false,this._errored=true;let o=new e(s?`Invalid WebSocket frame: ${r}`:r);return Error.captureStackTrace(o,this.createError),o.code=n,o[is]=i,o}};Gt.exports=qe;});var $e=b((wi,zt)=>{var{Duplex:bi}=a("stream"),{randomFillSync:ls}=a("crypto"),$t=ee(),{EMPTY_BUFFER:cs,kWebSocket:hs,NOOP:us}=T(),{isBlob:$,isValidStatusCode:ds}=G(),{mask:Vt,toBuffer:U}=Q(),b=Symbol("kByteLength"),_s=Buffer.alloc(4),ue=8*1024,I,V=ue,w=0,ps=1,ms=2,je=class t{constructor(e,r,s){this._extensions=r||{},s&&(this._generateMask=s,this._maskBuffer=Buffer.alloc(4)),this._socket=e,this._firstFragment=true,this._compress=false,this._bufferedBytes=0,this._queue=[],this._state=w,this.onerror=us,this[hs]=void 0;}static frame(e,r){let s,i=false,n=2,o=false;r.mask&&(s=r.maskBuffer||_s,r.generateMask?r.generateMask(s):(V===ue&&(I===void 0&&(I=Buffer.alloc(ue)),ls(I,0,ue),V=0),s[0]=I[V++],s[1]=I[V++],s[2]=I[V++],s[3]=I[V++]),o=(s[0]|s[1]|s[2]|s[3])===0,n=6);let f;typeof e=="string"?(!r.mask||o)&&r[b]!==void 0?f=r[b]:(e=Buffer.from(e),f=e.length):(f=e.length,i=r.mask&&r.readOnly&&!o);let l=f;f>=65536?(n+=8,l=127):f>125&&(n+=2,l=126);let a=Buffer.allocUnsafe(i?f+n:n);return a[0]=r.fin?r.opcode|128:r.opcode,r.rsv1&&(a[0]|=64),a[1]=l,l===126?a.writeUInt16BE(f,2):l===127&&(a[2]=a[3]=0,a.writeUIntBE(f,4,6)),r.mask?(a[1]|=128,a[n-4]=s[0],a[n-3]=s[1],a[n-2]=s[2],a[n-1]=s[3],o?[a,e]:i?(Vt(e,s,a,n,f),[a]):(Vt(e,s,e,0,f),[a,e])):[a,e]}close(e,r,s,i){let n;if(e===void 0)n=cs;else {if(typeof e!="number"||!ds(e))throw new TypeError("First argument must be a valid error code number");if(r===void 0||!r.length)n=Buffer.allocUnsafe(2),n.writeUInt16BE(e,0);else {let f=Buffer.byteLength(r);if(f>123)throw new RangeError("The message must not be greater than 123 bytes");n=Buffer.allocUnsafe(2+f),n.writeUInt16BE(e,0),typeof r=="string"?n.write(r,2):n.set(r,2);}}let o={[b]:n.length,fin:true,generateMask:this._generateMask,mask:s,maskBuffer:this._maskBuffer,opcode:8,readOnly:false,rsv1:false};this._state!==w?this.enqueue([this.dispatch,n,false,o,i]):this.sendFrame(t.frame(n,o),i);}ping(e,r,s){let i,n;if(typeof e=="string"?(i=Buffer.byteLength(e),n=false):$(e)?(i=e.size,n=false):(e=U(e),i=e.length,n=U.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:i,fin:true,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:9,readOnly:n,rsv1:false};$(e)?this._state!==w?this.enqueue([this.getBlobData,e,false,o,s]):this.getBlobData(e,false,o,s):this._state!==w?this.enqueue([this.dispatch,e,false,o,s]):this.sendFrame(t.frame(e,o),s);}pong(e,r,s){let i,n;if(typeof e=="string"?(i=Buffer.byteLength(e),n=false):$(e)?(i=e.size,n=false):(e=U(e),i=e.length,n=U.readOnly),i>125)throw new RangeError("The data size must not be greater than 125 bytes");let o={[b]:i,fin:true,generateMask:this._generateMask,mask:r,maskBuffer:this._maskBuffer,opcode:10,readOnly:n,rsv1:false};$(e)?this._state!==w?this.enqueue([this.getBlobData,e,false,o,s]):this.getBlobData(e,false,o,s):this._state!==w?this.enqueue([this.dispatch,e,false,o,s]):this.sendFrame(t.frame(e,o),s);}send(e,r,s){let i=this._extensions[$t.extensionName],n=r.binary?2:1,o=r.compress,f,l;typeof e=="string"?(f=Buffer.byteLength(e),l=false):$(e)?(f=e.size,l=false):(e=U(e),f=e.length,l=U.readOnly),this._firstFragment?(this._firstFragment=false,o&&i&&i.params[i._isServer?"server_no_context_takeover":"client_no_context_takeover"]&&(o=f>=i._threshold),this._compress=o):(o=false,n=0),r.fin&&(this._firstFragment=true);let a={[b]:f,fin:r.fin,generateMask:this._generateMask,mask:r.mask,maskBuffer:this._maskBuffer,opcode:n,readOnly:l,rsv1:o};$(e)?this._state!==w?this.enqueue([this.getBlobData,e,this._compress,a,s]):this.getBlobData(e,this._compress,a,s):this._state!==w?this.enqueue([this.dispatch,e,this._compress,a,s]):this.dispatch(e,this._compress,a,s);}getBlobData(e,r,s,i){this._bufferedBytes+=s[b],this._state=ms,e.arrayBuffer().then(n=>{if(this._socket.destroyed){let f=new Error("The socket was closed while the blob was being read");process.nextTick(Ge,this,f,i);return}this._bufferedBytes-=s[b];let o=U(n);r?this.dispatch(o,r,s,i):(this._state=w,this.sendFrame(t.frame(o,s),i),this.dequeue());}).catch(n=>{process.nextTick(ys,this,n,i);});}dispatch(e,r,s,i){if(!r){this.sendFrame(t.frame(e,s),i);return}let n=this._extensions[$t.extensionName];this._bufferedBytes+=s[b],this._state=ps,n.compress(e,s.fin,(o,f)=>{if(this._socket.destroyed){let l=new Error("The socket was closed while data was being compressed");Ge(this,l,i);return}this._bufferedBytes-=s[b],this._state=w,s.readOnly=false,this.sendFrame(t.frame(f,s),i),this.dequeue();});}dequeue(){for(;this._state===w&&this._queue.length;){let e=this._queue.shift();this._bufferedBytes-=e[3][b],Reflect.apply(e[0],this,e.slice(1));}}enqueue(e){this._bufferedBytes+=e[3][b],this._queue.push(e);}sendFrame(e,r){e.length===2?(this._socket.cork(),this._socket.write(e[0]),this._socket.write(e[1],r),this._socket.uncork()):this._socket.write(e[0],r);}};zt.exports=je;function Ge(t,e,r){typeof r=="function"&&r(e);for(let s=0;s<t._queue.length;s++){let i=t._queue[s],n=i[i.length-1];typeof n=="function"&&n(e);}}function ys(t,e,r){Ge(t,e,r),t.onerror(e);}});var tr=b((ki,er)=>{var{kForOnEventAttribute:te,kListener:Ve}=T(),Ht=Symbol("kCode"),Yt=Symbol("kData"),Kt=Symbol("kError"),Xt=Symbol("kMessage"),Zt=Symbol("kReason"),z=Symbol("kTarget"),Qt=Symbol("kType"),Jt=Symbol("kWasClean"),L=class{constructor(e){this[z]=null,this[Qt]=e;}get target(){return this[z]}get type(){return this[Qt]}};Object.defineProperty(L.prototype,"target",{enumerable:true});Object.defineProperty(L.prototype,"type",{enumerable:true});var D=class extends L{constructor(e,r={}){super(e),this[Ht]=r.code===void 0?0:r.code,this[Zt]=r.reason===void 0?"":r.reason,this[Jt]=r.wasClean===void 0?false:r.wasClean;}get code(){return this[Ht]}get reason(){return this[Zt]}get wasClean(){return this[Jt]}};Object.defineProperty(D.prototype,"code",{enumerable:true});Object.defineProperty(D.prototype,"reason",{enumerable:true});Object.defineProperty(D.prototype,"wasClean",{enumerable:true});var H=class extends L{constructor(e,r={}){super(e),this[Kt]=r.error===void 0?null:r.error,this[Xt]=r.message===void 0?"":r.message;}get error(){return this[Kt]}get message(){return this[Xt]}};Object.defineProperty(H.prototype,"error",{enumerable:true});Object.defineProperty(H.prototype,"message",{enumerable:true});var re=class extends L{constructor(e,r={}){super(e),this[Yt]=r.data===void 0?null:r.data;}get data(){return this[Yt]}};Object.defineProperty(re.prototype,"data",{enumerable:true});var gs={addEventListener(t,e,r={}){for(let i of this.listeners(t))if(!r[te]&&i[Ve]===e&&!i[te])return;let s;if(t==="message")s=function(n,o){let f=new re("message",{data:o?n:n.toString()});f[z]=this,de(e,this,f);};else if(t==="close")s=function(n,o){let f=new D("close",{code:n,reason:o.toString(),wasClean:this._closeFrameReceived&&this._closeFrameSent});f[z]=this,de(e,this,f);};else if(t==="error")s=function(n){let o=new H("error",{error:n,message:n.message});o[z]=this,de(e,this,o);};else if(t==="open")s=function(){let n=new L("open");n[z]=this,de(e,this,n);};else return;s[te]=!!r[te],s[Ve]=e,r.once?this.once(t,s):this.on(t,s);},removeEventListener(t,e){for(let r of this.listeners(t))if(r[Ve]===e&&!r[te]){this.removeListener(t,r);break}}};er.exports={CloseEvent:D,ErrorEvent:H,Event:L,EventTarget:gs,MessageEvent:re};function de(t,e,r){typeof t=="object"&&t.handleEvent?t.handleEvent.call(t,r):t.call(e,r);}});var ze=b((Oi,rr)=>{var{tokenChars:se}=G();function O(t,e,r){t[e]===void 0?t[e]=[r]:t[e].push(r);}function xs(t){let e=Object.create(null),r=Object.create(null),s=false,i=false,n=false,o,f,l=-1,a=-1,c=-1,h=0;for(;h<t.length;h++)if(a=t.charCodeAt(h),o===void 0)if(c===-1&&se[a]===1)l===-1&&(l=h);else if(h!==0&&(a===32||a===9))c===-1&&l!==-1&&(c=h);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${h}`);c===-1&&(c=h);let y=t.slice(l,c);a===44?(O(e,y,r),r=Object.create(null)):o=y,l=c=-1;}else throw new SyntaxError(`Unexpected character at index ${h}`);else if(f===void 0)if(c===-1&&se[a]===1)l===-1&&(l=h);else if(a===32||a===9)c===-1&&l!==-1&&(c=h);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${h}`);c===-1&&(c=h),O(r,t.slice(l,c),true),a===44&&(O(e,o,r),r=Object.create(null),o=void 0),l=c=-1;}else if(a===61&&l!==-1&&c===-1)f=t.slice(l,h),l=c=-1;else throw new SyntaxError(`Unexpected character at index ${h}`);else if(i){if(se[a]!==1)throw new SyntaxError(`Unexpected character at index ${h}`);l===-1?l=h:s||(s=true),i=false;}else if(n)if(se[a]===1)l===-1&&(l=h);else if(a===34&&l!==-1)n=false,c=h;else if(a===92)i=true;else throw new SyntaxError(`Unexpected character at index ${h}`);else if(a===34&&t.charCodeAt(h-1)===61)n=true;else if(c===-1&&se[a]===1)l===-1&&(l=h);else if(l!==-1&&(a===32||a===9))c===-1&&(c=h);else if(a===59||a===44){if(l===-1)throw new SyntaxError(`Unexpected character at index ${h}`);c===-1&&(c=h);let y=t.slice(l,c);s&&(y=y.replace(/\\/g,""),s=false),O(r,f,y),a===44&&(O(e,o,r),r=Object.create(null),o=void 0),f=void 0,l=c=-1;}else throw new SyntaxError(`Unexpected character at index ${h}`);if(l===-1||n||a===32||a===9)throw new SyntaxError("Unexpected end of input");c===-1&&(c=h);let d=t.slice(l,c);return o===void 0?O(e,d,r):(f===void 0?O(r,d,true):s?O(r,f,d.replace(/\\/g,"")):O(r,f,d),O(e,o,r)),e}function Ss(t){return Object.keys(t).map(e=>{let r=t[e];return Array.isArray(r)||(r=[r]),r.map(s=>[e].concat(Object.keys(s).map(i=>{let n=s[i];return Array.isArray(n)||(n=[n]),n.map(o=>o===true?i:`${i}=${o}`).join("; ")})).join("; ")).join(", ")}).join(", ")}rr.exports={format:Ss,parse:xs};});var ye=b((Ni,_r)=>{var vs=a("events"),Es=a("https"),bs=a("http"),nr=a("net"),ws=a("tls"),{randomBytes:ks,createHash:Os}=a("crypto"),{Duplex:Ti,Readable:Ci}=a("stream"),{URL:He}=a("url"),R=ee(),Ts=Fe(),Cs=$e(),{isBlob:Ns}=G(),{BINARY_TYPES:sr,EMPTY_BUFFER:_e,GUID:Ls,kForOnEventAttribute:Ye,kListener:Ps,kStatusCode:Bs,kWebSocket:x,NOOP:or}=T(),{EventTarget:{addEventListener:Rs,removeEventListener:Us}}=tr(),{format:Is,parse:Ds}=ze(),{toBuffer:Ws}=Q(),Ms=30*1e3,ar=Symbol("kAborted"),Ke=[8,13],P=["CONNECTING","OPEN","CLOSING","CLOSED"],As=/^[!#$%&'*+\-.0-9A-Z^_`|a-z~]+$/,m=class t extends vs{constructor(e,r,s){super(),this._binaryType=sr[0],this._closeCode=1006,this._closeFrameReceived=false,this._closeFrameSent=false,this._closeMessage=_e,this._closeTimer=null,this._errorEmitted=false,this._extensions={},this._paused=false,this._protocol="",this._readyState=t.CONNECTING,this._receiver=null,this._sender=null,this._socket=null,e!==null?(this._bufferedAmount=0,this._isServer=false,this._redirects=0,r===void 0?r=[]:Array.isArray(r)||(typeof r=="object"&&r!==null?(s=r,r=[]):r=[r]),fr(this,e,r,s)):(this._autoPong=s.autoPong,this._isServer=true);}get binaryType(){return this._binaryType}set binaryType(e){sr.includes(e)&&(this._binaryType=e,this._receiver&&(this._receiver._binaryType=e));}get bufferedAmount(){return this._socket?this._socket._writableState.length+this._sender._bufferedBytes:this._bufferedAmount}get extensions(){return Object.keys(this._extensions).join()}get isPaused(){return this._paused}get onclose(){return null}get onerror(){return null}get onopen(){return null}get onmessage(){return null}get protocol(){return this._protocol}get readyState(){return this._readyState}get url(){return this._url}setSocket(e,r,s){let i=new Ts({allowSynchronousEvents:s.allowSynchronousEvents,binaryType:this.binaryType,extensions:this._extensions,isServer:this._isServer,maxPayload:s.maxPayload,skipUTF8Validation:s.skipUTF8Validation}),n=new Cs(e,this._extensions,s.generateMask);this._receiver=i,this._sender=n,this._socket=e,i[x]=this,n[x]=this,e[x]=this,i.on("conclude",js),i.on("drain",Gs),i.on("error",$s),i.on("message",Vs),i.on("ping",zs),i.on("pong",Hs),n.onerror=Ys,e.setTimeout&&e.setTimeout(0),e.setNoDelay&&e.setNoDelay(),r.length>0&&e.unshift(r),e.on("close",hr),e.on("data",me),e.on("end",ur),e.on("error",dr),this._readyState=t.OPEN,this.emit("open");}emitClose(){if(!this._socket){this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);return}this._extensions[R.extensionName]&&this._extensions[R.extensionName].cleanup(),this._receiver.removeAllListeners(),this._readyState=t.CLOSED,this.emit("close",this._closeCode,this._closeMessage);}close(e,r){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){v(this,this._req,"WebSocket was closed before the connection was established");return}if(this.readyState===t.CLOSING){this._closeFrameSent&&(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end();return}this._readyState=t.CLOSING,this._sender.close(e,r,!this._isServer,s=>{s||(this._closeFrameSent=true,(this._closeFrameReceived||this._receiver._writableState.errorEmitted)&&this._socket.end());}),cr(this);}}pause(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=true,this._socket.pause());}ping(e,r,s){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(s=e,e=r=void 0):typeof r=="function"&&(s=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Xe(this,e,s);return}r===void 0&&(r=!this._isServer),this._sender.ping(e||_e,r,s);}pong(e,r,s){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof e=="function"?(s=e,e=r=void 0):typeof r=="function"&&(s=r,r=void 0),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Xe(this,e,s);return}r===void 0&&(r=!this._isServer),this._sender.pong(e||_e,r,s);}resume(){this.readyState===t.CONNECTING||this.readyState===t.CLOSED||(this._paused=false,this._receiver._writableState.needDrain||this._socket.resume());}send(e,r,s){if(this.readyState===t.CONNECTING)throw new Error("WebSocket is not open: readyState 0 (CONNECTING)");if(typeof r=="function"&&(s=r,r={}),typeof e=="number"&&(e=e.toString()),this.readyState!==t.OPEN){Xe(this,e,s);return}let i={binary:typeof e!="string",mask:!this._isServer,compress:true,fin:true,...r};this._extensions[R.extensionName]||(i.compress=false),this._sender.send(e||_e,i,s);}terminate(){if(this.readyState!==t.CLOSED){if(this.readyState===t.CONNECTING){v(this,this._req,"WebSocket was closed before the connection was established");return}this._socket&&(this._readyState=t.CLOSING,this._socket.destroy());}}};Object.defineProperty(m,"CONNECTING",{enumerable:true,value:P.indexOf("CONNECTING")});Object.defineProperty(m.prototype,"CONNECTING",{enumerable:true,value:P.indexOf("CONNECTING")});Object.defineProperty(m,"OPEN",{enumerable:true,value:P.indexOf("OPEN")});Object.defineProperty(m.prototype,"OPEN",{enumerable:true,value:P.indexOf("OPEN")});Object.defineProperty(m,"CLOSING",{enumerable:true,value:P.indexOf("CLOSING")});Object.defineProperty(m.prototype,"CLOSING",{enumerable:true,value:P.indexOf("CLOSING")});Object.defineProperty(m,"CLOSED",{enumerable:true,value:P.indexOf("CLOSED")});Object.defineProperty(m.prototype,"CLOSED",{enumerable:true,value:P.indexOf("CLOSED")});["binaryType","bufferedAmount","extensions","isPaused","protocol","readyState","url"].forEach(t=>{Object.defineProperty(m.prototype,t,{enumerable:true});});["open","error","close","message"].forEach(t=>{Object.defineProperty(m.prototype,`on${t}`,{enumerable:true,get(){for(let e of this.listeners(t))if(e[Ye])return e[Ps];return null},set(e){for(let r of this.listeners(t))if(r[Ye]){this.removeListener(t,r);break}typeof e=="function"&&this.addEventListener(t,e,{[Ye]:true});}});});m.prototype.addEventListener=Rs;m.prototype.removeEventListener=Us;_r.exports=m;function fr(t,e,r,s){let i={allowSynchronousEvents:true,autoPong:true,protocolVersion:Ke[1],maxPayload:104857600,skipUTF8Validation:false,perMessageDeflate:true,followRedirects:false,maxRedirects:10,...s,socketPath:void 0,hostname:void 0,protocol:void 0,timeout:void 0,method:"GET",host:void 0,path:void 0,port:void 0};if(t._autoPong=i.autoPong,!Ke.includes(i.protocolVersion))throw new RangeError(`Unsupported protocol version: ${i.protocolVersion} (supported versions: ${Ke.join(", ")})`);let n;if(e instanceof He)n=e;else try{n=new He(e);}catch{throw new SyntaxError(`Invalid URL: ${e}`)}n.protocol==="http:"?n.protocol="ws:":n.protocol==="https:"&&(n.protocol="wss:"),t._url=n.href;let o=n.protocol==="wss:",f=n.protocol==="ws+unix:",l;if(n.protocol!=="ws:"&&!o&&!f?l=`The URL's protocol must be one of "ws:", "wss:", "http:", "https:", or "ws+unix:"`:f&&!n.pathname?l="The URL's pathname is empty":n.hash&&(l="The URL contains a fragment identifier"),l){let u=new SyntaxError(l);if(t._redirects===0)throw u;pe(t,u);return}let a=o?443:80,c=ks(16).toString("base64"),h=o?Es.request:bs.request,d=new Set,y;if(i.createConnection=i.createConnection||(o?Fs:qs),i.defaultPort=i.defaultPort||a,i.port=n.port||a,i.host=n.hostname.startsWith("[")?n.hostname.slice(1,-1):n.hostname,i.headers={...i.headers,"Sec-WebSocket-Version":i.protocolVersion,"Sec-WebSocket-Key":c,Connection:"Upgrade",Upgrade:"websocket"},i.path=n.pathname+n.search,i.timeout=i.handshakeTimeout,i.perMessageDeflate&&(y=new R(i.perMessageDeflate!==true?i.perMessageDeflate:{},false,i.maxPayload),i.headers["Sec-WebSocket-Extensions"]=Is({[R.extensionName]:y.offer()})),r.length){for(let u of r){if(typeof u!="string"||!As.test(u)||d.has(u))throw new SyntaxError("An invalid or duplicated subprotocol was specified");d.add(u);}i.headers["Sec-WebSocket-Protocol"]=r.join(",");}if(i.origin&&(i.protocolVersion<13?i.headers["Sec-WebSocket-Origin"]=i.origin:i.headers.Origin=i.origin),(n.username||n.password)&&(i.auth=`${n.username}:${n.password}`),f){let u=i.path.split(":");i.socketPath=u[0],i.path=u[1];}let p;if(i.followRedirects){if(t._redirects===0){t._originalIpc=f,t._originalSecure=o,t._originalHostOrSocketPath=f?i.socketPath:n.host;let u=s&&s.headers;if(s={...s,headers:{}},u)for(let[S,A]of Object.entries(u))s.headers[S.toLowerCase()]=A;}else if(t.listenerCount("redirect")===0){let u=f?t._originalIpc?i.socketPath===t._originalHostOrSocketPath:false:t._originalIpc?false:n.host===t._originalHostOrSocketPath;(!u||t._originalSecure&&!o)&&(delete i.headers.authorization,delete i.headers.cookie,u||delete i.headers.host,i.auth=void 0);}i.auth&&!s.headers.authorization&&(s.headers.authorization="Basic "+Buffer.from(i.auth).toString("base64")),p=t._req=h(i),t._redirects&&t.emit("redirect",t.url,p);}else p=t._req=h(i);i.timeout&&p.on("timeout",()=>{v(t,p,"Opening handshake has timed out");}),p.on("error",u=>{p===null||p[ar]||(p=t._req=null,pe(t,u));}),p.on("response",u=>{let S=u.headers.location,A=u.statusCode;if(S&&i.followRedirects&&A>=300&&A<400){if(++t._redirects>i.maxRedirects){v(t,p,"Maximum redirects exceeded");return}p.abort();let K;try{K=new He(S,e);}catch{let q=new SyntaxError(`Invalid URL: ${S}`);pe(t,q);return}fr(t,K,r,s);}else t.emit("unexpected-response",p,u)||v(t,p,`Unexpected server response: ${u.statusCode}`);}),p.on("upgrade",(u,S,A)=>{if(t.emit("upgrade",u),t.readyState!==m.CONNECTING)return;p=t._req=null;let K=u.headers.upgrade;if(K===void 0||K.toLowerCase()!=="websocket"){v(t,S,"Invalid Upgrade header");return}let Je=Os("sha1").update(c+Ls).digest("base64");if(u.headers["sec-websocket-accept"]!==Je){v(t,S,"Invalid Sec-WebSocket-Accept header");return}let q=u.headers["sec-websocket-protocol"],X;if(q!==void 0?d.size?d.has(q)||(X="Server sent an invalid subprotocol"):X="Server sent a subprotocol but none was requested":d.size&&(X="Server sent no subprotocol"),X){v(t,S,X);return}q&&(t._protocol=q);let et=u.headers["sec-websocket-extensions"];if(et!==void 0){if(!y){v(t,S,"Server sent a Sec-WebSocket-Extensions header but no extension was requested");return}let xe;try{xe=Ds(et);}catch{v(t,S,"Invalid Sec-WebSocket-Extensions header");return}let tt=Object.keys(xe);if(tt.length!==1||tt[0]!==R.extensionName){v(t,S,"Server indicated an extension that was not requested");return}try{y.accept(xe[R.extensionName]);}catch{v(t,S,"Invalid Sec-WebSocket-Extensions header");return}t._extensions[R.extensionName]=y;}t.setSocket(S,A,{allowSynchronousEvents:i.allowSynchronousEvents,generateMask:i.generateMask,maxPayload:i.maxPayload,skipUTF8Validation:i.skipUTF8Validation});}),i.finishRequest?i.finishRequest(p,t):p.end();}function pe(t,e){t._readyState=m.CLOSING,t._errorEmitted=true,t.emit("error",e),t.emitClose();}function qs(t){return t.path=t.socketPath,nr.connect(t)}function Fs(t){return t.path=void 0,!t.servername&&t.servername!==""&&(t.servername=nr.isIP(t.host)?"":t.host),ws.connect(t)}function v(t,e,r){t._readyState=m.CLOSING;let s=new Error(r);Error.captureStackTrace(s,v),e.setHeader?(e[ar]=true,e.abort(),e.socket&&!e.socket.destroyed&&e.socket.destroy(),process.nextTick(pe,t,s)):(e.destroy(s),e.once("error",t.emit.bind(t,"error")),e.once("close",t.emitClose.bind(t)));}function Xe(t,e,r){if(e){let s=Ns(e)?e.size:Ws(e).length;t._socket?t._sender._bufferedBytes+=s:t._bufferedAmount+=s;}if(r){let s=new Error(`WebSocket is not open: readyState ${t.readyState} (${P[t.readyState]})`);process.nextTick(r,s);}}function js(t,e){let r=this[x];r._closeFrameReceived=true,r._closeMessage=e,r._closeCode=t,r._socket[x]!==void 0&&(r._socket.removeListener("data",me),process.nextTick(lr,r._socket),t===1005?r.close():r.close(t,e));}function Gs(){let t=this[x];t.isPaused||t._socket.resume();}function $s(t){let e=this[x];e._socket[x]!==void 0&&(e._socket.removeListener("data",me),process.nextTick(lr,e._socket),e.close(t[Bs])),e._errorEmitted||(e._errorEmitted=true,e.emit("error",t));}function ir(){this[x].emitClose();}function Vs(t,e){this[x].emit("message",t,e);}function zs(t){let e=this[x];e._autoPong&&e.pong(t,!this._isServer,or),e.emit("ping",t);}function Hs(t){this[x].emit("pong",t);}function lr(t){t.resume();}function Ys(t){let e=this[x];e.readyState!==m.CLOSED&&(e.readyState===m.OPEN&&(e._readyState=m.CLOSING,cr(e)),this._socket.end(),e._errorEmitted||(e._errorEmitted=true,e.emit("error",t)));}function cr(t){t._closeTimer=setTimeout(t._socket.destroy.bind(t._socket),Ms);}function hr(){let t=this[x];this.removeListener("close",hr),this.removeListener("data",me),this.removeListener("end",ur),t._readyState=m.CLOSING;let e;!this._readableState.endEmitted&&!t._closeFrameReceived&&!t._receiver._writableState.errorEmitted&&(e=t._socket.read())!==null&&t._receiver.write(e),t._receiver.end(),this[x]=void 0,clearTimeout(t._closeTimer),t._receiver._writableState.finished||t._receiver._writableState.errorEmitted?t.emitClose():(t._receiver.on("error",ir),t._receiver.on("finish",ir));}function me(t){this[x]._receiver.write(t)||this.pause();}function ur(){let t=this[x];t._readyState=m.CLOSING,t._receiver.end(),this.end();}function dr(){let t=this[x];this.removeListener("error",dr),this.on("error",or),t&&(t._readyState=m.CLOSING,this.destroy());}});var gr=b((Pi,yr)=>{ye();var {Duplex:Ks}=a("stream");function pr(t){t.emit("close");}function Xs(){!this.destroyed&&this._writableState.finished&&this.destroy();}function mr(t){this.removeListener("error",mr),this.destroy(),this.listenerCount("error")===0&&this.emit("error",t);}function Zs(t,e){let r=true,s=new Ks({...e,autoDestroy:false,emitClose:false,objectMode:false,writableObjectMode:false});return t.on("message",function(n,o){let f=!o&&s._readableState.objectMode?n.toString():n;s.push(f)||t.pause();}),t.once("error",function(n){s.destroyed||(r=false,s.destroy(n));}),t.once("close",function(){s.destroyed||s.push(null);}),s._destroy=function(i,n){if(t.readyState===t.CLOSED){n(i),process.nextTick(pr,s);return}let o=false;t.once("error",function(l){o=true,n(l);}),t.once("close",function(){o||n(i),process.nextTick(pr,s);}),r&&t.terminate();},s._final=function(i){if(t.readyState===t.CONNECTING){t.once("open",function(){s._final(i);});return}t._socket!==null&&(t._socket._writableState.finished?(i(),s._readableState.endEmitted&&s.destroy()):(t._socket.once("finish",function(){i();}),t.close()));},s._read=function(){t.isPaused&&t.resume();},s._write=function(i,n,o){if(t.readyState===t.CONNECTING){t.once("open",function(){s._write(i,n,o);});return}t.send(i,o);},s.on("end",Xs),s.on("error",mr),s}yr.exports=Zs;});var Sr=b((Bi,xr)=>{var{tokenChars:Qs}=G();function Js(t){let e=new Set,r=-1,s=-1,i=0;for(i;i<t.length;i++){let o=t.charCodeAt(i);if(s===-1&&Qs[o]===1)r===-1&&(r=i);else if(i!==0&&(o===32||o===9))s===-1&&r!==-1&&(s=i);else if(o===44){if(r===-1)throw new SyntaxError(`Unexpected character at index ${i}`);s===-1&&(s=i);let f=t.slice(r,s);if(e.has(f))throw new SyntaxError(`The "${f}" subprotocol is duplicated`);e.add(f),r=s=-1;}else throw new SyntaxError(`Unexpected character at index ${i}`)}if(r===-1||s!==-1)throw new SyntaxError("Unexpected end of input");let n=t.slice(r,i);if(e.has(n))throw new SyntaxError(`The "${n}" subprotocol is duplicated`);return e.add(n),e}xr.exports={parse:Js};});var Tr=b((Ui,Or)=>{var ei=a("events"),ge=a("http"),{Duplex:Ri}=a("stream"),{createHash:ti}=a("crypto"),vr=ze(),W=ee(),ri=Sr(),si=ye(),{GUID:ii,kWebSocket:ni}=T(),oi=/^[+/0-9A-Za-z]{22}==$/,Er=0,br=1,kr=2,Ze=class extends ei{constructor(e,r){if(super(),e={allowSynchronousEvents:true,autoPong:true,maxPayload:100*1024*1024,skipUTF8Validation:false,perMessageDeflate:false,handleProtocols:null,clientTracking:true,verifyClient:null,noServer:false,backlog:null,server:null,host:null,path:null,port:null,WebSocket:si,...e},e.port==null&&!e.server&&!e.noServer||e.port!=null&&(e.server||e.noServer)||e.server&&e.noServer)throw new TypeError('One and only one of the "port", "server", or "noServer" options must be specified');if(e.port!=null?(this._server=ge.createServer((s,i)=>{let n=ge.STATUS_CODES[426];i.writeHead(426,{"Content-Length":n.length,"Content-Type":"text/plain"}),i.end(n);}),this._server.listen(e.port,e.host,e.backlog,r)):e.server&&(this._server=e.server),this._server){let s=this.emit.bind(this,"connection");this._removeListeners=ai(this._server,{listening:this.emit.bind(this,"listening"),error:this.emit.bind(this,"error"),upgrade:(i,n,o)=>{this.handleUpgrade(i,n,o,s);}});}e.perMessageDeflate===true&&(e.perMessageDeflate={}),e.clientTracking&&(this.clients=new Set,this._shouldEmitClose=false),this.options=e,this._state=Er;}address(){if(this.options.noServer)throw new Error('The server is operating in "noServer" mode');return this._server?this._server.address():null}close(e){if(this._state===kr){e&&this.once("close",()=>{e(new Error("The server is not running"));}),process.nextTick(ie,this);return}if(e&&this.once("close",e),this._state!==br)if(this._state=br,this.options.noServer||this.options.server)this._server&&(this._removeListeners(),this._removeListeners=this._server=null),this.clients?this.clients.size?this._shouldEmitClose=true:process.nextTick(ie,this):process.nextTick(ie,this);else {let r=this._server;this._removeListeners(),this._removeListeners=this._server=null,r.close(()=>{ie(this);});}}shouldHandle(e){if(this.options.path){let r=e.url.indexOf("?");if((r!==-1?e.url.slice(0,r):e.url)!==this.options.path)return false}return true}handleUpgrade(e,r,s,i){r.on("error",wr);let n=e.headers["sec-websocket-key"],o=e.headers.upgrade,f=+e.headers["sec-websocket-version"];if(e.method!=="GET"){M(this,e,r,405,"Invalid HTTP method");return}if(o===void 0||o.toLowerCase()!=="websocket"){M(this,e,r,400,"Invalid Upgrade header");return}if(n===void 0||!oi.test(n)){M(this,e,r,400,"Missing or invalid Sec-WebSocket-Key header");return}if(f!==13&&f!==8){M(this,e,r,400,"Missing or invalid Sec-WebSocket-Version header",{"Sec-WebSocket-Version":"13, 8"});return}if(!this.shouldHandle(e)){ne(r,400);return}let l=e.headers["sec-websocket-protocol"],a=new Set;if(l!==void 0)try{a=ri.parse(l);}catch{M(this,e,r,400,"Invalid Sec-WebSocket-Protocol header");return}let c=e.headers["sec-websocket-extensions"],h={};if(this.options.perMessageDeflate&&c!==void 0){let d=new W(this.options.perMessageDeflate,true,this.options.maxPayload);try{let y=vr.parse(c);y[W.extensionName]&&(d.accept(y[W.extensionName]),h[W.extensionName]=d);}catch{M(this,e,r,400,"Invalid or unacceptable Sec-WebSocket-Extensions header");return}}if(this.options.verifyClient){let d={origin:e.headers[`${f===8?"sec-websocket-origin":"origin"}`],secure:!!(e.socket.authorized||e.socket.encrypted),req:e};if(this.options.verifyClient.length===2){this.options.verifyClient(d,(y,p,u,S)=>{if(!y)return ne(r,p||401,u,S);this.completeUpgrade(h,n,a,e,r,s,i);});return}if(!this.options.verifyClient(d))return ne(r,401)}this.completeUpgrade(h,n,a,e,r,s,i);}completeUpgrade(e,r,s,i,n,o,f){if(!n.readable||!n.writable)return n.destroy();if(n[ni])throw new Error("server.handleUpgrade() was called more than once with the same socket, possibly due to a misconfiguration");if(this._state>Er)return ne(n,503);let a=["HTTP/1.1 101 Switching Protocols","Upgrade: websocket","Connection: Upgrade",`Sec-WebSocket-Accept: ${ti("sha1").update(r+ii).digest("base64")}`],c=new this.options.WebSocket(null,void 0,this.options);if(s.size){let h=this.options.handleProtocols?this.options.handleProtocols(s,i):s.values().next().value;h&&(a.push(`Sec-WebSocket-Protocol: ${h}`),c._protocol=h);}if(e[W.extensionName]){let h=e[W.extensionName].params,d=vr.format({[W.extensionName]:[h]});a.push(`Sec-WebSocket-Extensions: ${d}`),c._extensions=e;}this.emit("headers",a,i),n.write(a.concat(`\r
4
+ `).join(`\r
5
+ `)),n.removeListener("error",wr),c.setSocket(n,o,{allowSynchronousEvents:this.options.allowSynchronousEvents,maxPayload:this.options.maxPayload,skipUTF8Validation:this.options.skipUTF8Validation}),this.clients&&(this.clients.add(c),c.on("close",()=>{this.clients.delete(c),this._shouldEmitClose&&!this.clients.size&&process.nextTick(ie,this);})),f(c,i);}};Or.exports=Ze;function ai(t,e){for(let r of Object.keys(e))t.on(r,e[r]);return function(){for(let s of Object.keys(e))t.removeListener(s,e[s]);}}function ie(t){t._state=kr,t.emit("close");}function wr(){this.destroy();}function ne(t,e,r,s){r=r||ge.STATUS_CODES[e],s={Connection:"close","Content-Type":"text/html","Content-Length":Buffer.byteLength(r),...s},t.once("finish",t.destroy),t.end(`HTTP/1.1 ${e} ${ge.STATUS_CODES[e]}\r
6
+ `+Object.keys(s).map(i=>`${i}: ${s[i]}`).join(`\r
7
+ `)+`\r
8
+ \r
9
+ `+r);}function M(t,e,r,s,i,n){if(t.listenerCount("wsClientError")){let o=new Error(i);Error.captureStackTrace(o,M),t.emit("wsClientError",o,r,e);}else ne(r,s,i,n);}});var Qe={};c(Qe,{Receiver:()=>Nr.default,Sender:()=>Lr.default,WebSocket:()=>Y.default,WebSocketServer:()=>Pr.default,createWebSocketStream:()=>Cr.default,default:()=>fi});var Cr=d(gr(),1),Nr=d(Fe(),1),Lr=d($e(),1),Y=d(ye(),1),Pr=d(Tr(),1);var fi=Y.default;function Br(){if(typeof WebSocket<"u")return WebSocket;if(typeof global.WebSocket<"u")return global.WebSocket;if(typeof window.WebSocket<"u")return window.WebSocket;if(typeof self.WebSocket<"u")return self.WebSocket;throw new Error("`WebSocket` is not supported in this environment")}var Wi=(()=>{try{return Br()}catch{return Y.default?Y.default:Qe}})();export{Wi as WebSocket};//# sourceMappingURL=_esm-4WQYADT7.mjs.map
10
+ //# sourceMappingURL=_esm-4WQYADT7.mjs.map