sonic-ws 1.3.2 → 2.0.0-fix
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 +56 -196
- package/README.md +88 -17
- package/bundled/bundle.js +6 -0
- package/bundled/bundle.wasm +0 -0
- package/dist/{index.d.ts → ts/index.d.ts} +9 -2
- package/dist/{index.js → ts/index.js} +10 -11
- package/dist/ts/native/wrapper.d.ts +64 -0
- package/dist/ts/native/wrapper.js +7 -0
- package/dist/ts/version.d.ts +16 -0
- package/dist/ts/version.js +7 -0
- package/dist/{ws → ts/ws}/Connection.d.ts +8 -2
- package/dist/{ws → ts/ws}/Connection.js +3 -2
- package/dist/{ws → ts/ws}/PacketProcessor.d.ts +8 -2
- package/dist/{ws → ts/ws}/PacketProcessor.js +4 -3
- package/dist/{ws → ts/ws}/client/core/ClientCore.d.ts +8 -2
- package/dist/ts/ws/client/core/ClientCore.js +7 -0
- package/dist/{ws → ts/ws}/client/node/ClientNode.d.ts +8 -2
- package/dist/ts/ws/client/node/ClientNode.js +7 -0
- package/dist/ts/ws/debug/DebugServer.d.ts +17 -0
- package/dist/ts/ws/debug/DebugServer.js +7 -0
- package/dist/{ws → ts/ws}/packets/PacketType.d.ts +9 -3
- package/dist/{ws → ts/ws}/packets/PacketType.js +3 -2
- package/dist/{ws → ts/ws}/packets/Packets.d.ts +8 -5
- package/dist/ts/ws/packets/Packets.js +7 -0
- package/dist/{ws → ts/ws}/server/SonicWSConnection.d.ts +8 -2
- package/dist/ts/ws/server/SonicWSConnection.js +7 -0
- package/dist/{ws → ts/ws}/server/SonicWSServer.d.ts +12 -3
- package/dist/ts/ws/server/SonicWSServer.js +7 -0
- package/dist/{ws → ts/ws}/util/BufferUtil.d.ts +8 -2
- package/dist/{ws → ts/ws}/util/BufferUtil.js +3 -2
- package/dist/ts/ws/util/StringUtil.d.ts +13 -0
- package/dist/ts/ws/util/StringUtil.js +7 -0
- package/dist/{ws → ts/ws}/util/enums/EnumHandler.d.ts +8 -2
- package/dist/{ws → ts/ws}/util/enums/EnumHandler.js +3 -2
- package/dist/ts/ws/util/enums/EnumType.d.ts +12 -0
- package/dist/{ws → ts/ws}/util/enums/EnumType.js +4 -3
- package/dist/ts/ws/util/packets/BatchHelper.d.ts +11 -0
- package/dist/ts/ws/util/packets/BatchHelper.js +7 -0
- package/dist/ts/ws/util/packets/CompressionUtil.d.ts +18 -0
- package/dist/ts/ws/util/packets/CompressionUtil.js +7 -0
- package/dist/ts/ws/util/packets/HashUtil.d.ts +12 -0
- package/dist/{ws → ts/ws}/util/packets/HashUtil.js +3 -2
- package/dist/ts/ws/util/packets/JSONUtil.d.ts +12 -0
- package/dist/ts/ws/util/packets/JSONUtil.js +7 -0
- package/dist/ts/ws/util/packets/PacketHolder.d.ts +11 -0
- package/dist/{ws → ts/ws}/util/packets/PacketHolder.js +4 -3
- package/dist/{ws → ts/ws}/util/packets/PacketUtils.d.ts +8 -2
- package/dist/ts/ws/util/packets/PacketUtils.js +7 -0
- package/dist/ts/ws/util/packets/RateHandler.d.ts +11 -0
- package/dist/{ws → ts/ws}/util/packets/RateHandler.js +3 -2
- package/package.json +14 -10
- package/dist/version.d.ts +0 -10
- package/dist/version.js +0 -6
- package/dist/ws/client/core/ClientCore.js +0 -6
- package/dist/ws/client/node/ClientNode.js +0 -6
- package/dist/ws/debug/DebugServer.d.ts +0 -11
- package/dist/ws/debug/DebugServer.js +0 -6
- package/dist/ws/packets/PacketProcessors.d.ts +0 -17
- package/dist/ws/packets/PacketProcessors.js +0 -6
- package/dist/ws/packets/Packets.js +0 -6
- package/dist/ws/server/SonicWSConnection.js +0 -6
- package/dist/ws/server/SonicWSServer.js +0 -6
- package/dist/ws/util/StringUtil.d.ts +0 -9
- package/dist/ws/util/StringUtil.js +0 -6
- package/dist/ws/util/enums/EnumType.d.ts +0 -6
- package/dist/ws/util/packets/BatchHelper.d.ts +0 -5
- package/dist/ws/util/packets/BatchHelper.js +0 -6
- package/dist/ws/util/packets/CompressionUtil.d.ts +0 -39
- package/dist/ws/util/packets/CompressionUtil.js +0 -6
- package/dist/ws/util/packets/HashUtil.d.ts +0 -6
- package/dist/ws/util/packets/JSONUtil.d.ts +0 -6
- package/dist/ws/util/packets/JSONUtil.js +0 -6
- package/dist/ws/util/packets/PacketHolder.d.ts +0 -5
- package/dist/ws/util/packets/PacketUtils.js +0 -6
- package/dist/ws/util/packets/RateHandler.d.ts +0 -5
package/LICENSE
CHANGED
|
@@ -1,196 +1,56 @@
|
|
|
1
|
-
Copyright 2026 Lily (liwybloc)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
58
|
-
of this License, Derivative Works shall not include works that remain
|
|
59
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
60
|
-
the Work and Derivative Works thereof.
|
|
61
|
-
|
|
62
|
-
"Contribution" shall mean any work of authorship, including
|
|
63
|
-
the original version of the Work and any modifications or additions
|
|
64
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
65
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
66
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
67
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
68
|
-
means any form of electronic, verbal, or written communication sent
|
|
69
|
-
to the Licensor or its representatives, including but not limited to
|
|
70
|
-
communication on electronic mailing lists, source code control systems,
|
|
71
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
72
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
73
|
-
excluding communication that is conspicuously marked or otherwise
|
|
74
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
75
|
-
|
|
76
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
77
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
78
|
-
subsequently incorporated within the Work.
|
|
79
|
-
|
|
80
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
81
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
82
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
83
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
84
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
85
|
-
Work and such Derivative Works in Source or Object form.
|
|
86
|
-
|
|
87
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
88
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
89
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
90
|
-
(except as stated in this section) patent license to make, have made,
|
|
91
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
92
|
-
where such license applies only to those patent claims licensable
|
|
93
|
-
by such Contributor that are necessarily infringed by their
|
|
94
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
95
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
96
|
-
institute patent litigation against any entity (including a
|
|
97
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
98
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
99
|
-
or contributory patent infringement, then any patent licenses
|
|
100
|
-
granted to You under this License for that Work shall terminate
|
|
101
|
-
as of the date such litigation is filed.
|
|
102
|
-
|
|
103
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
104
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
105
|
-
modifications, and in Source or Object form, provided that You
|
|
106
|
-
meet the following conditions:
|
|
107
|
-
|
|
108
|
-
(a) You must give any other recipients of the Work or
|
|
109
|
-
Derivative Works a copy of this License; and
|
|
110
|
-
|
|
111
|
-
(b) You must cause any modified files to carry prominent notices
|
|
112
|
-
stating that You changed the files; and
|
|
113
|
-
|
|
114
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
115
|
-
that You distribute, all copyright, patent, trademark, and
|
|
116
|
-
attribution notices from the Source form of the Work,
|
|
117
|
-
excluding those notices that do not pertain to any part of
|
|
118
|
-
the Derivative Works; and
|
|
119
|
-
|
|
120
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
121
|
-
distribution, then any Derivative Works that You distribute must
|
|
122
|
-
include a readable copy of the attribution notices contained
|
|
123
|
-
within such NOTICE file, excluding those notices that do not
|
|
124
|
-
pertain to any part of the Derivative Works, in at least one
|
|
125
|
-
of the following places: within a NOTICE text file distributed
|
|
126
|
-
as part of the Derivative Works; within the Source form or
|
|
127
|
-
documentation, if provided along with the Derivative Works; or,
|
|
128
|
-
within a display generated by the Derivative Works, if and
|
|
129
|
-
wherever such third-party notices normally appear. The contents
|
|
130
|
-
of the NOTICE file are for informational purposes only and
|
|
131
|
-
do not modify the License. You may add Your own attribution
|
|
132
|
-
notices within Derivative Works that You distribute, alongside
|
|
133
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
134
|
-
that such additional attribution notices cannot be construed
|
|
135
|
-
as modifying the License.
|
|
136
|
-
|
|
137
|
-
You may add Your own copyright statement to Your modifications and
|
|
138
|
-
may provide additional or different license terms and conditions
|
|
139
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
140
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
141
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
142
|
-
the conditions stated in this License.
|
|
143
|
-
|
|
144
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
145
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
146
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
147
|
-
this License, without any additional terms or conditions.
|
|
148
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
149
|
-
the terms of any separate license agreement you may have executed
|
|
150
|
-
with Licensor regarding such Contributions.
|
|
151
|
-
|
|
152
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
153
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
154
|
-
except as required for reasonable and customary use in describing the
|
|
155
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
156
|
-
|
|
157
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
158
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
159
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
160
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
161
|
-
implied, including, without limitation, any warranties or conditions
|
|
162
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
163
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
164
|
-
appropriateness of using or redistributing the Work and assume any
|
|
165
|
-
risks associated with Your exercise of permissions under this License.
|
|
166
|
-
|
|
167
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
168
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
169
|
-
unless required by applicable law (such as deliberate and grossly
|
|
170
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
171
|
-
liable to You for damages, including any direct, indirect, special,
|
|
172
|
-
incidental, or consequential damages of any character arising as a
|
|
173
|
-
result of this License or out of the use or inability to use the
|
|
174
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
175
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
176
|
-
other commercial damages or losses), even if such Contributor
|
|
177
|
-
has been advised of the possibility of such damages.
|
|
178
|
-
|
|
179
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
180
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
181
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
182
|
-
or other liability obligations and/or rights consistent with this
|
|
183
|
-
License. However, in accepting such obligations, You may act only
|
|
184
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
185
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
186
|
-
defend, and hold each Contributor harmless for any liability
|
|
187
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
188
|
-
of your accepting any such warranty or additional liability.
|
|
189
|
-
|
|
190
|
-
END OF TERMS AND CONDITIONS
|
|
191
|
-
|
|
192
|
-
Unless required by applicable law or agreed to in writing, software
|
|
193
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
194
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
195
|
-
See the License for the specific language governing permissions and
|
|
196
|
-
limitations under the License.
|
|
1
|
+
Copyright (c) 2026 Lily (liwybloc)
|
|
2
|
+
|
|
3
|
+
Personal Non-Commercial License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to use,
|
|
7
|
+
copy, and modify the Software solely for personal, non-commercial purposes,
|
|
8
|
+
subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
1. Permitted Use
|
|
11
|
+
|
|
12
|
+
The Software may be used, copied, and modified for personal, non-commercial
|
|
13
|
+
purposes only.
|
|
14
|
+
|
|
15
|
+
2. Restrictions
|
|
16
|
+
|
|
17
|
+
You may not, without prior written permission from the copyright holder:
|
|
18
|
+
|
|
19
|
+
- Use the Software, in whole or in part, for any commercial purpose
|
|
20
|
+
- Sell, sublicense, rent, lease, publish, host, or otherwise distribute the
|
|
21
|
+
Software or copies of the Software
|
|
22
|
+
- Provide the Software as part of a paid service, paid product, commercial
|
|
23
|
+
product, or commercial offering
|
|
24
|
+
- Distribute modified versions of the Software
|
|
25
|
+
- Remove or alter any copyright, license, or attribution notices
|
|
26
|
+
|
|
27
|
+
3. Contributions
|
|
28
|
+
|
|
29
|
+
You may create modifications and submit them to the original project
|
|
30
|
+
(for example, via pull requests). By submitting a contribution, you grant
|
|
31
|
+
the copyright holder a non-exclusive, worldwide, royalty-free, perpetual,
|
|
32
|
+
irrevocable license to use, copy, modify, merge, publish, distribute,
|
|
33
|
+
sublicense, and otherwise incorporate your contribution into the Software.
|
|
34
|
+
|
|
35
|
+
4. Commercial Licensing
|
|
36
|
+
|
|
37
|
+
A separate commercial license is required for any commercial use of the
|
|
38
|
+
Software. To obtain a commercial license, contact: yinuwu12@gmail.com
|
|
39
|
+
|
|
40
|
+
5. Ownership
|
|
41
|
+
|
|
42
|
+
The Software is licensed, not sold. All rights not expressly granted are
|
|
43
|
+
reserved by the copyright holder.
|
|
44
|
+
|
|
45
|
+
6. Disclaimer of Warranty
|
|
46
|
+
|
|
47
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
48
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
49
|
+
FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
|
|
50
|
+
|
|
51
|
+
7. Limitation of Liability
|
|
52
|
+
|
|
53
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
54
|
+
DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT, OR
|
|
55
|
+
OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
56
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
# sonic-ws
|
|
2
2
|
|
|
3
|
-
###
|
|
4
|
-
|
|
5
|
-
-
|
|
6
|
-
|
|
7
|
-
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
3
|
+
### The socket library that handle correctness, security, and performance for you
|
|
4
|
+
|
|
5
|
+
SonicWS is a schema-driven WebSocket library for multiple languages. It uses a shared Rust packet codec, to provide compact binary packets, validation before listener execution, batching, compression, built-in rate limiting, and more.
|
|
6
|
+
|
|
7
|
+
It is designed for real-time applications such as games, dashboards, collaborative tools, and distributed systems where packet correctness, bandwidth efficiency, and predictable socket lifecycle behavior matter.
|
|
8
|
+
|
|
9
|
+
## Why SonicWS?
|
|
10
|
+
|
|
11
|
+
- Define exactly which packets each side may send.
|
|
12
|
+
- Reject invalid packets before user callbacks run.
|
|
13
|
+
- Use compact numeric packet IDs instead of repeated string keys.
|
|
14
|
+
- Share the same packet codec across Node and browser clients.
|
|
15
|
+
- Batch, validate, compress, and rate-limit packets with minimal boilerplate.
|
|
16
|
+
- Code is much more readable than every other socket library*
|
|
14
17
|
|
|
15
18
|
<details>
|
|
16
19
|
<summary>DETAILED INFO</summary>
|
|
17
20
|
|
|
18
21
|
SonicWS is an ultra-lightweight, high-performance WebSocket library focused on maximum bandwidth efficiency, speed, and security.
|
|
19
22
|
|
|
23
|
+
The packet codec is written in Rust and shared by every runtime. Node can use the native N-API addon (with a WASM fallback), while browsers use the same core compiled to WebAssembly. This keeps packet encoding, decoding, validation, batching, and compression consistent between the server and client.
|
|
24
|
+
|
|
20
25
|
Compression:
|
|
21
26
|
- Lossless compression up to 70% or more (for example, 38kb -> 14kb)
|
|
22
27
|
- Optimized bandwidth for many different types to fit special constraints
|
|
23
|
-
- Automatic helpers to flatten typed nested arrays for maximum wire efficiency (for example, [[1,false,"text"],[4,true,"other"]] to [[1,4],[false,true],["text,"other"]])
|
|
28
|
+
- Automatic helpers to flatten typed nested arrays for maximum wire efficiency (for example, [[1,false,"text"],[4,true,"other"]] to [[1,4],[false,true],["text","other"]])
|
|
24
29
|
- Uses raw binary bytes to transmit data as efficiently as possible while still using high level readable code
|
|
25
30
|
- Built-in ability to use compression libraries
|
|
26
31
|
|
|
@@ -28,7 +33,7 @@ Developer Friendly:
|
|
|
28
33
|
- Predefined data types of various sized integers, single and double precision floating point numbers, strings, enums, etc. and RAW to allow for developers to do anything they want
|
|
29
34
|
- Keys are automatically indexed before transfer, improving readability and efficiency (for example, send("pixel") and send("p") use the same bandwidth)
|
|
30
35
|
- Data is validated and supports custom validation, ensuring only valid, safe, and untampered packets ever call your listeners
|
|
31
|
-
- Edge cases are heavily tested
|
|
36
|
+
- Edge cases are heavily tested across large data ranges; strings support code points up to the max of 0x10FFFF
|
|
32
37
|
- Debug tools to view all packets
|
|
33
38
|
|
|
34
39
|
Security:
|
|
@@ -53,12 +58,34 @@ Developer Experience:
|
|
|
53
58
|
- Many data types to maximize speed, clarity, bandwidth, and security
|
|
54
59
|
- Debug tools for socket ids, byte size, data logging, etc. for troubleshooting
|
|
55
60
|
- Very minimal learning curve, easy to work in
|
|
56
|
-
- JSDoc
|
|
61
|
+
- JSDoc for understanding; immensely intuitive (personally, I took a break for half a year and came back and snapped right back in)
|
|
57
62
|
- Almost every case has a pre-made wire optimization and boilerplate removal.
|
|
58
63
|
|
|
59
64
|
Whether you're making a real-time game, a dashboard, a distributed system, or anything else, SonicWS gets you safe, structured packets; fast.
|
|
65
|
+
|
|
66
|
+
\* = More readable than code I've seen written for socket.io and other libraries
|
|
60
67
|
</details>
|
|
61
68
|
|
|
69
|
+
## HOW IT WORKS
|
|
70
|
+
|
|
71
|
+
You define the packets each side is allowed to send. SonicWS exchanges that schema during the connection handshake, assigns compact numeric packet IDs, and validates incoming data before calling your listeners.
|
|
72
|
+
|
|
73
|
+
The TypeScript layer handles connections, packet definitions, middleware, and the public API. The Rust core handles the wire format:
|
|
74
|
+
|
|
75
|
+
- Primitive and object packet encoding/decoding
|
|
76
|
+
- Packet validation and range checks
|
|
77
|
+
- Enum, string, boolean, varint, delta, float, and hex codecs
|
|
78
|
+
- Object framing, batching, and raw DEFLATE compression
|
|
79
|
+
- TypeScript-side JSON conversion transported through reserved wire type 16 as raw bytes
|
|
80
|
+
|
|
81
|
+
The same Rust implementation is exposed through N-API for native Node use and through WASM for browsers and the portable Node fallback. Protocol behavior therefore does not depend on which runtime is connected.
|
|
82
|
+
|
|
83
|
+
## INSTALLATION
|
|
84
|
+
|
|
85
|
+
```sh
|
|
86
|
+
npm install sonic-ws
|
|
87
|
+
```
|
|
88
|
+
|
|
62
89
|
## SAMPLES
|
|
63
90
|
|
|
64
91
|
### Node (Client & Server)
|
|
@@ -68,9 +95,23 @@ import { SonicWS, SonicWSServer, CreatePacket, PacketType } from "sonic-ws";
|
|
|
68
95
|
|
|
69
96
|
Browser (Client):
|
|
70
97
|
```html
|
|
71
|
-
<script src="
|
|
98
|
+
<script src="/SonicWS/bundle.js"></script>
|
|
99
|
+
<script>
|
|
100
|
+
async function connect() {
|
|
101
|
+
await SonicWS.initialize();
|
|
102
|
+
const ws = new SonicWS(`ws://${location.host}`);
|
|
103
|
+
// Register listeners and send packets here.
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
connect();
|
|
107
|
+
</script>
|
|
72
108
|
```
|
|
73
|
-
|
|
109
|
+
|
|
110
|
+
`SonicWSServer` serves this browser bundle and its WASM module automatically at
|
|
111
|
+
`/SonicWS/bundle.js` and `/SonicWS/bundle.wasm`. Set
|
|
112
|
+
`sonicServerSettings.serveBrowserClient` to `false` to disable these routes.
|
|
113
|
+
|
|
114
|
+
The WASM core must finish initializing before constructing a browser client. Node initializes its codec automatically.
|
|
74
115
|
|
|
75
116
|
### Simple Example: Clicker Server
|
|
76
117
|
|
|
@@ -97,7 +138,7 @@ wss.on_connect(ws => {
|
|
|
97
138
|
|
|
98
139
|
ws.on("token", token => {
|
|
99
140
|
if(!isValidToken(token)) // No listeners will ever trigger after this, unlike base websocket
|
|
100
|
-
return
|
|
141
|
+
return ws.close();
|
|
101
142
|
})
|
|
102
143
|
|
|
103
144
|
// auto validation, no boilerplate. always passed the token check
|
|
@@ -113,6 +154,7 @@ wss.on_ready(() => console.log("Server ready!"));
|
|
|
113
154
|
|
|
114
155
|
#### Client
|
|
115
156
|
```js
|
|
157
|
+
await SonicWS.initialize();
|
|
116
158
|
const ws = new SonicWS("ws://localhost:1234");
|
|
117
159
|
|
|
118
160
|
ws.on_ready(() => console.log("Connected to server"));
|
|
@@ -127,6 +169,35 @@ button.addEventListener("click", () => {
|
|
|
127
169
|
|
|
128
170
|
```
|
|
129
171
|
|
|
172
|
+
## BUILDING AND TESTING
|
|
173
|
+
|
|
174
|
+
Building requires Node.js, Rust with the `wasm32-unknown-unknown` target, and `wasm-pack`.
|
|
175
|
+
|
|
176
|
+
```sh
|
|
177
|
+
npm run build # TypeScript, Node WASM, browser WASM, and browser bundle
|
|
178
|
+
npm run build_node # Node distribution and WASM fallback
|
|
179
|
+
npm run build_web # Browser bundle and WASM
|
|
180
|
+
npm run test_node # Node end-to-end packet tests
|
|
181
|
+
npm run test_web # Headless browser/WASM end-to-end tests
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
The Rust crate lives in `src/core`, and the TypeScript API lives in `src/ts`. Generated JavaScript is written to `dist/ts`; browser artifacts are written to `bundled/bundle.js` and `bundled/bundle.wasm`.
|
|
185
|
+
|
|
130
186
|
## KNOWN ISSUES
|
|
131
187
|
|
|
188
|
+
- `KEY_EFFECTIVE` is reserved but still a work in progress.
|
|
189
|
+
- Native `.node` addons are platform-specific. WASM is used as the portable fallback, while prebuilt native binaries will need separate builds for each supported operating system and architecture.
|
|
190
|
+
|
|
132
191
|
## PLANNED FEATURES
|
|
192
|
+
- Better encoding for the first packet that sends packet information
|
|
193
|
+
- Publish the Rust core as a standalone, documented crate
|
|
194
|
+
- Add first-class Python and Go bindings
|
|
195
|
+
- Provide prebuilt N-API binaries for the main Node platforms
|
|
196
|
+
|
|
197
|
+
## LICENSE
|
|
198
|
+
This project is source-available.
|
|
199
|
+
|
|
200
|
+
You are free to use, modify, and contribute for personal,
|
|
201
|
+
non-commercial purposes.
|
|
202
|
+
|
|
203
|
+
Commercial use requires a separate license. Please contact me regarding information on this.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) 2026 Lily (liwybloc)
|
|
3
|
+
* License-Identifier: LicenseRef-Lily-Personal-NonCommercial-2026
|
|
4
|
+
* See LICENSE for personal, non-commercial license terms.
|
|
5
|
+
*/
|
|
6
|
+
(()=>{"use strict";var __webpack_modules__={14(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.EnumPackage=t.TYPE_CONVERSION_MAP=void 0;const a=n(113),r=n(864),s={string:0,number:1,boolean:2,undefined:3,object:4};function i(e){const t=typeof e;if(!(t in s)&&null!=e)throw new Error(`Cannot serialize type "${t}" in an enum!`);return s[t]}t.TYPE_CONVERSION_MAP={0:e=>e,1:e=>parseFloat(e),2:e=>"true"==e,3:()=>{},4:()=>null};t.EnumPackage=class{tag;values;constructor(e,t){this.tag=e,this.values=t,this.wrap=this.wrap.bind(this)}serialize(){const e=(0,a.processCharCodes)(this.tag);return[this.tag.length,...e,this.values.length,...this.values.map(e=>[String(e).length,i(e),...(0,a.processCharCodes)(String(e))]).flat()]}wrap(e){return(0,r.WrapEnum)(this.tag,e)}}},26(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.decompressBools=t.compressBools=t.EMPTY_UINT8=t.MAX_UVARINT=t.MAX_BYTE=void 0,t.convertVarInt=function(e){if(!Number.isSafeInteger(e)||e<0||e>t.MAX_UVARINT)throw new Error(`Variable Ints must be within range 0 and ${t.MAX_UVARINT}: ${e}`);const n=[];do{let t=e%128;(e=Math.floor(e/128))>0&&(t|=128),n.push(t)}while(e>0);return n},t.readVarInt=function(e,t){let n=0,a=1;for(let r=0;r<8;r++){if(t>=e.length)throw new Error("Truncated variable integer");const r=e[t++];if(n+=(127&r)*a,!(128&r))return[t,n];a*=128}throw new Error("Variable integer is too long")},t.MAX_BYTE=255,t.MAX_UVARINT=128**7-1,t.EMPTY_UINT8=new Uint8Array([]);t.compressBools=e=>e.reduce((e,t,n)=>e|Number(t)<<7-n,0);t.decompressBools=e=>Array.from({length:8},(t,n)=>!!(e&1<<7-n))},113(e,t){function n(e){return String.fromCodePoint(...e)}Object.defineProperty(t,"__esModule",{value:!0}),t.processCharCodes=function(e){return Array.from(e,e=>e.codePointAt(0))},t.convertCharCodes=n,t.as8String=function(e){return n(Array.from(e))}},197(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.MiddlewareHolder=void 0;t.MiddlewareHolder=class{middlewares=[];addMiddleware(e){this.middlewares.push(e);const t=e;try{"function"==typeof t.init&&t.init(this)}catch(e){console.warn("Middleware init threw an error:",e)}}async callMiddleware(e,...t){let n=!1;for(const a of this.middlewares){const r=a[e];if(r)try{await r(...t)&&(n=!0)}catch(t){console.warn(`Middleware ${String(e)} threw an error:`,t)}}return n}}},241(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.DebugClient=void 0;t.DebugClient=class{host;constructor(e){this.host=e;const t=document.createElement("sonicws");t.innerHTML="<style>sws-h3{margin:0;color:#fff;font-size:16px;font-weight:600}#sonicws-container{display:flex;flex-direction:column;position:absolute;top:50px;left:50px;width:75vw;min-width:33vw;min-height:25vh;max-height:75vh;max-width:75vw;font-family:Arial,sans-serif;background-color:#2c2c2c;border-radius:10px;box-shadow:0 8px 20px rgba(0,0,0,.4);overflow:hidden;user-select:none;transition:box-shadow .2s ease;z-index:2147483647}#sonicws-container:hover{box-shadow:0 12px 28px rgba(0,0,0,.6)}#sonicws-header{display:flex;justify-content:space-between;align-items:center;cursor:move;background:linear-gradient(90deg,#4a90e2,#357ab7);padding:10px 12px;border-top-left-radius:10px;border-top-right-radius:10px}#sonicws-toggle{font-size:18px;font-weight:700;cursor:pointer;color:#fff;user-select:none}#sonicws-body{flex:1;display:flex;padding:12px;color:#e0e0e0;font-size:14px;min-height:0}#sonicws-stats{display:flex;flex-direction:column;min-width:140px}#sonicws-stats sws-p{margin:4px 0}#sonicws-packets{min-height:0;display:flex;flex-direction:column;flex:1;margin-left:10px;background-color:#1e1e1e;padding:8px;border-radius:8px;overflow-y:scroll}sws-div.packet{background-color:#2a2a2a;border-radius:6px;padding:3px 5px;margin-bottom:2px;cursor:pointer;transition:background .2s ease,transform .1s ease;display:flex;flex-direction:column}sws-div.packet:hover{background-color:#3a3a3a;transform:translateY(-1px)}sws-div.packet-header{display:flex;align-items:flex-start;flex-wrap:wrap;font-size:11px;white-space:normal;word-break:break-word}sws-span.packet-arrow{font-weight:700;margin-right:6px}sws-div.packet-details{margin-top:6px;font-size:10px;color:#aaa;display:none;flex-direction:column}sws-div.packet.expanded sws-div.packet-details{display:flex}#sonicws-resizer{width:12px;height:12px;background:#666;position:absolute;right:0;bottom:0;cursor:se-resize;border-bottom-right-radius:10px;transition:background .2s ease}#sonicws-resizer:hover{background:#888}#sonicws-container.minimized{width:auto!important;height:auto!important;min-width:unset;min-height:unset}#sonicws-container.minimized #sonicws-body,#sonicws-container.minimized #sonicws-resizer{display:none}#sonicws-container.minimized #sonicws-header{padding:8px 12px}#sonicws-container.minimized #sonicws-title{font-size:14px}</style><sws-div id=sonicws-container><sws-div id=sonicws-header><sws-h3 id=sonicws-title>SonicWS Debug Menu</sws-h3><sws-span id=sonicws-toggle>−</sws-span></sws-div><sws-div id=sonicws-body><sws-div id=sonicws-stats><sws-p>Status:<sws-span id=sonicws-status>Connecting</sws-span></sws-p><sws-p>Sent Packets:<sws-span id=sonicws-sent>0</sws-span></sws-p><sws-p>Received Packets:<sws-span id=sonicws-received>0</sws-span></sws-p><sws-p>Total Bytes Sent:<sws-span id=sonicws-sentbytes>0</sws-span></sws-p><sws-p>Total Bytes Received:<sws-span id=sonicws-receivedbytes>0</sws-span></sws-p><sws-p>Total Bytes Saved:<sws-span id=sonicws-savedbytes>0</sws-span></sws-p></sws-div><sws-div id=sonicws-packets></sws-div></sws-div><sws-div id=sonicws-resizer></sws-div></sws-div>",document.body?(document.body.appendChild(t),this._loadDebugScript()):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(t),this._loadDebugScript()})}_evalInScope(e){const t=this.host;return new Function("send","WrapEnum","DeWrapEnum","FlattenData","UnFlattenData",`"use strict"; return (${e});`)(t.send.bind(t),t.WrapEnum.bind(t),t.DeWrapEnum.bind(t),t.FlattenData.bind(t),t.UnFlattenData.bind(t))}_loadDebugScript(){const e={},t={},n=this.host;this.host.addMiddleware(new class{onReceive_pre(e,n){t[e]??=[],t[e].push([n,performance.now()])}onReceive_post(e,a){const[r,s]=t[e].shift();T("received",`${e} (0x${n.serverPackets.getKey(e).toString(16).toUpperCase()})`,r,JSON.stringify(a),performance.now()-s)}onSend_pre(t,n){e[t]??=[],e[t].push([n,performance.now()])}onSend_post(t,a){const[r,s]=e[t].shift();T("sent",`${t} (0x${n.clientPackets.getKey(t).toString(16).toUpperCase()})`,a,JSON.stringify(r),performance.now()-s)}onStatusChange(e){S(e)}});const a=e=>document.getElementById(e),r=a("sonicws-container"),s=a("sonicws-header"),i=a("sonicws-resizer"),o=a("sonicws-status"),c=a("sonicws-packets"),d=a("sonicws-sent"),l=a("sonicws-received"),u=a("sonicws-sentbytes"),h=a("sonicws-receivedbytes"),p=a("sonicws-savedbytes"),f=document.getElementById("sonicws-toggle"),w=document.getElementById("sonicws-title");let _=!1;const y=document.createElement("input");y.type="text",y.placeholder='send("tag", 5)',y.style.marginTop="8px",y.style.width="100%",y.style.boxSizing="border-box";const m=document.createElement("button");function g(){const e=r.getBoundingClientRect(),t=window.innerWidth-e.width,n=window.innerHeight-e.height,a=Math.min(Math.max(0,e.left),Math.max(0,t)),s=Math.min(Math.max(0,e.top),Math.max(0,n));r.style.left=a+"px",r.style.top=s+"px"}m.innerText="Run",m.style.marginTop="4px",m.style.width="100%",a("sonicws-stats").appendChild(y),a("sonicws-stats").appendChild(m),m.addEventListener("click",()=>{try{this._evalInScope(y.value)}catch(e){console.error(e)}}),f.addEventListener("click",e=>{e.stopPropagation(),_=!_,_?(r.classList.add("minimized"),w.innerText="SWS",f.innerText="+",r.style.width="",r.style.height=""):(r.classList.remove("minimized"),w.innerText="SonicWS Debug Menu",f.innerText="−"),g()});const b={sentPackets:0,receivedPackets:0,totalBytesSent:0,totalBytesReceived:0,totalBytesSaved:0},v=new Proxy(b,{get(e,t){switch(t){case"sonicws-sent":return b.sentPackets;case"sonicws-received":return b.receivedPackets;case"sonicws-sentbytes":return b.totalBytesSent;case"sonicws-receivedbytes":return b.totalBytesReceived;case"sonicws-savedbytes":return b.totalBytesSaved;default:return}},set(e,t,n){switch(t){case"sonicws-sent":return b.sentPackets=n,d.innerText=n.toLocaleString(),!0;case"sonicws-received":return b.receivedPackets=n,l.innerText=n.toLocaleString(),!0;case"sonicws-sentbytes":{b.totalBytesSent=n;const{amt:e,unit:t}=k(n);return u.innerText=e+t,!0}case"sonicws-receivedbytes":{b.totalBytesReceived=n;const{amt:e,unit:t}=k(n);return h.innerText=e+t,!0}case"sonicws-savedbytes":{b.totalBytesSaved=n;const{amt:e,unit:t}=k(n);return p.innerText=e+t,!0}default:return!1}}}),k=e=>{if(!Number.isFinite(e)||e<0)return{amt:0,unit:"B"};const t=["B","KB","MB","GB","TB"];let n=e,a=0;for(;n>=1024&&a<t.length-1;)n/=1024,a++;return{amt:0==a?n.toString():n.toFixed(2),unit:t[a]}};function S(e){switch(e){case WebSocket.CLOSED:o.innerText="Closed",o.style.color="#f00";break;case WebSocket.CLOSING:o.innerText="Closing",o.style.color="#fa0";break;case WebSocket.OPEN:o.innerText="Open",o.style.color="#0f0";break;case WebSocket.CONNECTING:o.innerText="Connecting",o.style.color="#ff0";break;default:o.innerText="Unknown",o.style.color="#777"}}S(WebSocket.CONNECTING);const E=new TextEncoder;function T(e,t,n,a,r){const s=new Date,i=n.length+("sent"==e?1:0),o=E.encode(a).length-i+1,d=document.createElement("sws-div");d.classList.add("packet");const l=document.createElement("sws-div");l.classList.add("packet-header");const u=document.createElement("sws-span");u.classList.add("packet-arrow"),u.innerText="sent"===e?"⬆":"⬇",u.style.color="sent"===e?"#0f0":"#f00";const h=document.createElement("sws-span");h.innerText=t+": "+a,l.appendChild(u),l.appendChild(h);const p=document.createElement("sws-div");p.classList.add("packet-details"),p.innerHTML=`\n <sws-p> Raw Bytes: ${i}b (saved ~${o}b)</sws-p>\n <sws-p> Processed At: ${s.toISOString()} </sws-p>\n <sws-p> Processing Time: <sws-span class="processing-time" > ${r.toFixed(1)} </sws-span> ms</sws-p>\n `,d.appendChild(l),d.appendChild(p),c.append(d),l.addEventListener("click",()=>d.classList.toggle("expanded")),"sent"===e?(v["sonicws-sent"]++,v["sonicws-sentbytes"]+=i):(v["sonicws-received"]++,v["sonicws-receivedbytes"]+=i),v["sonicws-savedbytes"]+=o}let N=!1,P=0,A=0,O=0,x=0,M=!1,C=0,I=0,B=0,R=0;s.addEventListener("mousedown",e=>{N=!0,P=e.clientX,A=e.clientY;const t=r.getBoundingClientRect();O=t.left,x=t.top,e.preventDefault()}),i.addEventListener("mousedown",e=>{M=!0,C=e.clientX,I=e.clientY;const t=r.getBoundingClientRect();B=t.width,R=t.height,e.preventDefault()}),document.addEventListener("mousemove",e=>{N&&(r.style.left=O+e.clientX-P+"px",r.style.top=x+e.clientY-A+"px",g()),M&&!_&&(r.style.width=B+e.clientX-C+"px",r.style.height=R+e.clientY-I+"px",g())}),document.addEventListener("mouseup",()=>{N=!1,M=!1}),g(),window.addEventListener("resize",g)}}},284(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.BatchHelper=void 0;const a=n(818),r=n(795);t.BatchHelper=class{batchInfo={};batchTimeouts={};batchedData={};conn;registerSendPackets(e,t){this.conn=t,e.getTags().forEach(t=>{const n=e.getPacket(t);if(0==n.dataBatching)return;const a=e.getKey(t);this.initiateBatch(a,n.dataBatching,n.gzipCompression)})}initiateBatch(e,t,n){this.batchedData[e]=[],this.batchInfo[e]=[t,n]}startBatch(e){const[t,n]=this.batchInfo[e];this.batchTimeouts[e]=this.conn.setInterval(()=>{if(0==this.batchedData[e].length)return;const t=(0,r.encodeNativeBatch)(this.batchedData[e],n);this.conn.raw_send((0,a.toPacketBuffer)(e,t)),this.batchedData[e]=[],delete this.batchTimeouts[e]},t)}batchPacket(e,t){this.batchedData[e].push(t),this.batchTimeouts[e]||this.startBatch(e)}static async unravelBatch(e,t,n){let a;try{a=(0,r.decodeNativeBatch)(t,e.gzipCompression,e.maxBatchSize)}catch(e){return"Invalid batch: "+e}const s=[];for(const t of a){const a=await e.listen(t,n);if("string"==typeof a)return"Batched packet: "+a;s.push([a[0],!e.dontSpread])}return s}}},302(e,t,n){function a(e,t,n,a){const r=ee.decodeBatch(e,t,n,q(a)?Number.MAX_SAFE_INTEGER:a>>>0);if(r[2])throw J(r[1]);return J(r[0])}function r(e,t){const n=ee.decodeBooleans(e,t);if(n[2])throw J(n[1]);return J(n[0])}function s(e,t){const n=ee.decodeFloats(e,t);if(n[2])throw J(n[1]);return J(n[0])}function i(e){let t,n;try{const s=ee.decodeHex(e);var a=s[0],r=s[1];if(s[3])throw a=0,r=0,J(s[2]);return t=a,n=r,H(a,r)}finally{ee.__wbindgen_free(t,n,1)}}function o(e){const t=ee.decodeRaw(e);if(t[2])throw J(t[1]);return J(t[0])}function c(e,t){const n=ee.decodeSigned(e,t);if(n[2])throw J(n[1]);return J(n[0])}function d(e,t){const n=ee.decodeStrings(e,t);if(n[2])throw J(n[1]);return J(n[0])}function l(e,t){const n=ee.decodeUnsigned(e,t);if(n[2])throw J(n[1]);return J(n[0])}function u(e){const t=ee.deflateRaw(e);if(t[2])throw J(t[1]);return J(t[0])}function h(e,t){const n=ee.encodeBatch(e,t);if(n[2])throw J(n[1]);return J(n[0])}function p(e){const t=ee.encodeBooleans(e);if(t[2])throw J(t[1]);return J(t[0])}function f(e,t){const n=ee.encodeFloats(e,t);if(n[2])throw J(n[1]);return J(n[0])}function w(e){const t=Y(e,ee.__wbindgen_malloc,ee.__wbindgen_realloc),n=te,a=ee.encodeHex(t,n);if(a[2])throw J(a[1]);return J(a[0])}function _(e){const t=ee.encodeRaw(e);if(t[2])throw J(t[1]);return J(t[0])}function y(e,t){const n=ee.encodeSigned(e,t);if(n[2])throw J(n[1]);return J(n[0])}function m(e,t){const n=ee.encodeStrings(e,t);if(n[2])throw J(n[1]);return J(n[0])}function g(e,t){const n=ee.encodeUnsigned(e,t);if(n[2])throw J(n[1]);return J(n[0])}function b(e){const t=ee.frameObject(e);if(t[2])throw J(t[1]);return J(t[0])}function v(e,t){const n=ee.inflateRaw(e,q(t)?Number.MAX_SAFE_INTEGER:t>>>0);if(n[2])throw J(n[1]);return J(n[0])}function k(e,t){const n=ee.unframeObject(e,t);if(n[2])throw J(n[1]);return J(n[0])}function S(e,t,n,a,r,s,i){const o=ee.validateEncoded(e,t,n,a,r,s,q(i)?Number.MAX_SAFE_INTEGER:i>>>0);if(o[1])throw J(o[0])}function E(e,t,n,a){const r=ee.validateEnum(e,t,n,a);if(r[1])throw J(r[0])}function T(e,t,n,a,r){const s=ee.validateObject(e,t,n,a,r);if(s[1])throw J(s[0])}function N(e){const t="boolean"==typeof e?e:void 0;return q(t)?16777215:t?1:0}function P(e,t){const n="number"==typeof t?t:void 0;W().setFloat64(e+8,q(n)?0:n,!0),W().setInt32(e+0,!q(n),!0)}function A(e,t){const n="string"==typeof t?t:void 0;var a=q(n)?0:Y(n,ee.__wbindgen_malloc,ee.__wbindgen_realloc),r=te;W().setInt32(e+4,r,!0),W().setInt32(e+0,a,!0)}function O(e,t){throw new Error(H(e,t))}function x(e,t){return e[t>>>0]}function M(e){return e.length}function C(e){return e.length}function I(){return new Array}function B(e){return new Uint8Array(e)}function R(e,t){return new Uint8Array(z(e,t))}function U(e,t,n){Uint8Array.prototype.set.call(z(e,t),n)}function L(e,t){return e.push(t)}function D(e){return e}function j(e,t){return H(e,t)}function F(){const e=ee.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}function z(e,t){return e>>>=0,K().subarray(e/1,e/1+t)}n.d(t,{$:()=>_,B4:()=>h,BV:()=>R,Dq:()=>o,EF:()=>i,EW:()=>B,F6:()=>O,JV:()=>P,NR:()=>D,Pt:()=>M,Q5:()=>T,Sg:()=>C,Tb:()=>L,Ts:()=>y,U_:()=>j,XC:()=>m,_s:()=>f,at:()=>u,bL:()=>F,cv:()=>k,gV:()=>I,hD:()=>S,i1:()=>E,i4:()=>s,iT:()=>p,iX:()=>r,jN:()=>a,lI:()=>ne,mU:()=>w,mk:()=>l,nt:()=>b,oF:()=>A,pe:()=>U,qO:()=>g,sL:()=>N,ss:()=>x,tD:()=>c,wS:()=>v,zC:()=>d});let V=null;function W(){return(null===V||!0===V.buffer.detached||void 0===V.buffer.detached&&V.buffer!==ee.memory.buffer)&&(V=new DataView(ee.memory.buffer)),V}function H(e,t){return function(e,t){Q+=t,Q>=X&&(G=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),G.decode(),Q=t);return G.decode(K().subarray(e,e+t))}(e>>>0,t)}let $=null;function K(){return null!==$&&0!==$.byteLength||($=new Uint8Array(ee.memory.buffer)),$}function q(e){return null==e}function Y(e,t,n){if(void 0===n){const n=Z.encode(e),a=t(n.length,1)>>>0;return K().subarray(a,a+n.length).set(n),te=n.length,a}let a=e.length,r=t(a,1)>>>0;const s=K();let i=0;for(;i<a;i++){const t=e.charCodeAt(i);if(t>127)break;s[r+i]=t}if(i!==a){0!==i&&(e=e.slice(i)),r=n(r,a,a=i+3*e.length,1)>>>0;const t=K().subarray(r+i,r+a);i+=Z.encodeInto(e,t).written,r=n(r,a,i,1)>>>0}return te=i,r}function J(e){const t=ee.__wbindgen_externrefs.get(e);return ee.__externref_table_dealloc(e),t}let G=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});G.decode();const X=2146435072;let Q=0;const Z=new TextEncoder;"encodeInto"in Z||(Z.encodeInto=function(e,t){const n=Z.encode(e);return t.set(n),{read:e.length,written:n.length}});let ee,te=0;function ne(e){ee=e}},319(e,t){var n;Object.defineProperty(t,"__esModule",{value:!0}),t.PacketType=void 0,function(e){e[e.NONE=0]="NONE",e[e.RAW=1]="RAW",e[e.STRINGS_ASCII=2]="STRINGS_ASCII",e[e.STRINGS_UTF16=3]="STRINGS_UTF16",e[e.STRINGS=2]="STRINGS",e[e.ENUMS=4]="ENUMS",e[e.BYTES=5]="BYTES",e[e.UBYTES=6]="UBYTES",e[e.SHORTS=7]="SHORTS",e[e.USHORTS=8]="USHORTS",e[e.VARINT=9]="VARINT",e[e.UVARINT=10]="UVARINT",e[e.DELTAS=11]="DELTAS",e[e.FLOATS=12]="FLOATS",e[e.DOUBLES=13]="DOUBLES",e[e.BOOLEANS=14]="BOOLEANS",e[e.KEY_EFFECTIVE=15]="KEY_EFFECTIVE",e[e.JSON=16]="JSON",e[e.HEX=17]="HEX"}(n||(t.PacketType=n={}))},322(e,t,n){n.a(e,async(e,a)=>{try{n.r(t),n.d(t,{decodeBatch:()=>s.jN,decodeBooleans:()=>s.iX,decodeFloats:()=>s.i4,decodeHex:()=>s.EF,decodeRaw:()=>s.Dq,decodeSigned:()=>s.tD,decodeStrings:()=>s.zC,decodeUnsigned:()=>s.mk,deflateRaw:()=>s.at,encodeBatch:()=>s.B4,encodeBooleans:()=>s.iT,encodeFloats:()=>s._s,encodeHex:()=>s.mU,encodeRaw:()=>s.$,encodeSigned:()=>s.Ts,encodeStrings:()=>s.XC,encodeUnsigned:()=>s.qO,frameObject:()=>s.nt,inflateRaw:()=>s.wS,unframeObject:()=>s.cv,validateEncoded:()=>s.hD,validateEnum:()=>s.i1,validateObject:()=>s.Q5});var r=n(575),s=n(302),i=e([r]);r=(i.then?(await i)():i)[0],(0,s.lI)(r),r.__wbindgen_start(),a()}catch(e){a(e)}})},402(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.PacketSchema=t.Packet=void 0;const a=n(864),r=n(14),s=n(26),i=n(917),o=n(319),c=n(113),d=n(795),l=n(980);class u{defaultEnabled;tag;maxSize;minSize;type;enumData;dataMax;dataMin;dataBatching;maxBatchSize;dontSpread;autoFlatten;rateLimit;async;rereference;gzipCompression;object;client;processReceive;processSend;validate;customValidator;lastReceived={};lastSent={};constructor(e,t,n,a,r){if(this.tag=e,this.defaultEnabled=a,this.client=r,this.async=t.async,this.enumData=t.enumData,this.rateLimit=t.rateLimit,this.dontSpread=t.dontSpread,this.autoFlatten=t.autoFlatten,this.rereference=t.rereference,this.dataBatching=t.dataBatching,this.maxBatchSize=r?1/0:t.maxBatchSize,this.gzipCompression=t.gzipCompression,this.object=t.object,this.type=t.type,this.dataMax=t.dataMax,this.dataMin=t.dataMin,t.testObject(this)){this.maxSize=this.minSize=this.type.length;for(let e=0;e<this.type.length;e++)this.type[e]==o.PacketType.NONE&&(this.dataMax[e]=this.dataMin[e]=0);const e={types:this.type,dataMins:this.dataMin,dataMaxes:this.dataMax,enumData:this.enumData};this.processReceive=t=>(0,d.decodeNativeObject)(e,t).map((e,t)=>this.type[t]===o.PacketType.JSON?(0,l.decompressJSON)(e):e),this.processSend=async t=>{let n=0;const a=t.map((e,t)=>{if(this.type[t]===o.PacketType.JSON)return(0,l.compressJSON)(e);if(this.type[t]!==o.PacketType.ENUMS)return e;const a=this.enumData[n++];return(Array.isArray(e)?e:[e]).map(e=>{if(!Number.isInteger(e)||e<0||e>=a.values.length)throw new Error(`Invalid wrapped enum index: ${e}`);return a.values[e]})});return(0,d.encodeNativeObject)(e,a)},this.validate=async t=>{(0,d.validateNativeObject)(e,t);return(0,d.decodeNativeObject)(e,t).forEach((e,t)=>{if(this.type[t]!==o.PacketType.JSON)return;const n=(0,l.decompressJSON)(e),a=Array.isArray(n)?n.length:1;if(a<this.dataMin[t]||a>this.dataMax[t])throw new Error("JSON value count is outside schema limits")}),[t,!0]}}else{{this.maxSize=this.dataMax,this.minSize=this.dataMin,this.type==o.PacketType.NONE&&(this.dataMax=this.dataMin=0);const e=this.enumData[0];this.processReceive=t=>this.type===o.PacketType.JSON?(0,l.decompressJSON)(t):(0,d.decodeNative)(this.type,t,this.dataMax,e),this.processSend=async t=>{let n;if(this.type===o.PacketType.JSON)n=(0,l.compressJSON)(t);else if(this.type===o.PacketType.ENUMS)n=Uint8Array.from(t);else{const a=this.type===o.PacketType.RAW&&1===t.length&&t[0]instanceof Uint8Array?t[0]:t;n=(0,d.encodeNative)(this.type,a,e)}return this.gzipCompression&&0===this.dataBatching?(0,d.deflateNative)(n):n},this.validate=async t=>{const n=this.gzipCompression&&0===this.dataBatching?(0,d.inflateNative)(t):t;if(this.type===o.PacketType.JSON){const e=(0,l.decompressJSON)(n),t=Array.isArray(e)?e.length:1;if(t<this.dataMin||t>this.dataMax)throw new Error("JSON value count is outside schema limits")}else(0,d.validateNative)(this.type,n,this.dataMin,this.dataMax,{enumData:e});return[n,!0]}}}this.customValidator=n}async listen(e,t){try{const[n,a]=await this.validate(e);if(!this.client&&!1===a)return"Invalid packet";const r=this.processReceive(n,a),s=this.autoFlatten?(0,i.UnFlattenData)(r):r;if(null!=this.customValidator)if(this.dontSpread){if(!this.customValidator(t,s))return"Didn't pass custom validator"}else if(!this.customValidator(t,...s))return"Didn't pass custom validator";return[s,!this.dontSpread]}catch(e){return console.error("There was an error processing the packet! This is probably my fault... report at https://github.com/liwybloc/sonic-ws",e),"Error: "+e}}serialize(){const e=[this.tag.length,...(0,c.processCharCodes)(this.tag),(0,s.compressBools)([this.dontSpread,this.async,this.object,this.autoFlatten,this.gzipCompression,this.rereference]),this.dataBatching,this.enumData.length,...this.enumData.map(e=>e.serialize()).flat()];return this.object?[...e,this.maxSize,...this.dataMax.map(s.convertVarInt).flat(),...this.dataMin.map(s.convertVarInt).flat(),...this.type]:[...e,...(0,s.convertVarInt)(this.dataMax),...(0,s.convertVarInt)(this.dataMin),this.type]}static readVarInts(e,t,n){const a=[];for(let r=0;r<n;r++){const[n,r]=(0,s.readVarInt)(e,t);t=n,a.push(r)}return[a,t]}static deserialize(e,t,n){const i=t,d=e[t++],l=(0,c.as8String)(e.slice(t,t+=d)),[h,f,w,_,y,m]=(0,s.decompressBools)(e[t++]),g=e[t++],b=e[t++],v=[];for(let n=0;n<b;n++){const n=e[t++],s=(0,c.as8String)(e.slice(t,t+=n)),i=e[t++],o=[];for(let n=0;n<i;n++){const n=e[t++],a=e[t++],s=(0,c.as8String)(e.slice(t,t+=n));o.push(r.TYPE_CONVERSION_MAP[a](s))}v.push((0,a.DefineEnum)(s,o))}if(w){const a=e[t++],[r,s]=this.readVarInts(e,t,a);t=s;const[c,d]=this.readVarInts(e,t,a);t=d;const w=Array.from(e.slice(t,t+=a));let m=0;const b=w.map(e=>e==o.PacketType.ENUMS?v[m++]:e),k=new p(!0,b,f,c,r,-1,h,_,!1,g,-1,y);return[new u(l,k,null,!1,n),t-i]}const[k,S]=(0,s.readVarInt)(e,t);t=k;const[E,T]=(0,s.readVarInt)(e,t);t=E;const N=e[t++],P=N==o.PacketType.ENUMS?v[0]:N,A=new p(!1,P,f,T,S,-1,h,!1,m,g,-1,y);return[new u(l,A,null,!1,n),t-i]}static deserializeAll(e,t){const n=[];let a=0;for(;a<e.length;){const[r,s]=this.deserialize(e,a,t);n.push(r),a+=s}return n}}t.Packet=u;const h=(e,t)=>e instanceof r.EnumPackage?(t.push(e),o.PacketType.ENUMS):e;class p{type;enumData=[];dataMax;dataMin;dataBatching;maxBatchSize;rateLimit;dontSpread=!1;autoFlatten=!1;async=!1;rereference=!1;gzipCompression=!1;object;constructor(e,t,n,a,r,s,i,o,c,d,l,u){this.object=e,this.async=n,this.dataMin=a,this.dataMax=r,this.rateLimit=s,this.dontSpread=i,this.autoFlatten=o,this.rereference=c,this.dataBatching=d,this.maxBatchSize=l,this.gzipCompression=u,this.type=e?t.map(e=>h(e,this.enumData)):h(t,this.enumData)}testObject(e){return this.object}}t.PacketSchema=p},549(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.CloseCodes=t.Connection=void 0,t.getClosureCause=function(e){if(e>=4e3)return i[e]??"UNKNOWN";switch(e){case 1e3:return"NORMAL_CLOSURE";case 1001:return"GOING_AWAY";case 1002:return"PROTOCOL_ERROR";case 1003:return"UNSUPPORTED_DATA";case 1006:return"ABNORMAL_CLOSURE";default:return"UNKNOWN"}};const a=n(197),r=n(284);class s extends a.MiddlewareHolder{listeners;name;closed=!1;socket;_timers={};batcher;_on;_off;id;constructor(e,t,n,a,s){super(),this.id=t,this.listeners={},this.name=n,this.socket=e,this.batcher=new r.BatchHelper,this._on=a,this._off=s,this._on("close",()=>{this.callMiddleware("onStatusChange",WebSocket.CLOSED),this.closed=!0;for(const[e,t,n]of Object.values(this._timers))this.clearTimeout(e),n&&t(!0)}),this._on("open",()=>this.callMiddleware("onStatusChange",WebSocket.OPEN))}setTimeout(e,t,n=!1){const a=setTimeout(()=>{e(),this.clearTimeout(a)},t);return this._timers[a]=[a,e,n],a}setInterval(e,t,n=!1){const a=setInterval(e,t);return this._timers[a]=[a,e,n],a}clearTimeout(e){clearTimeout(e),delete this._timers[e]}clearInterval(e){this.clearTimeout(e)}raw_send(e){this.socket.send(e)}raw_onmessage(e){this._on("message",e)}close(e=1e3,t){this.closed=!0,this.socket.close(e,t?.toString())}isClosed(){return this.closed||this.socket.readyState==WebSocket.CLOSED}async setName(e){await this.callMiddleware("onNameChange",e)||(this.name=e)}getName(){return this.name}}var i;t.Connection=s,function(e){e[e.RATELIMIT=4e3]="RATELIMIT",e[e.SMALL=4001]="SMALL",e[e.INVALID_KEY=4002]="INVALID_KEY",e[e.INVALID_PACKET=4003]="INVALID_PACKET",e[e.INVALID_DATA=4004]="INVALID_DATA",e[e.REPEATED_HANDSHAKE=4005]="REPEATED_HANDSHAKE",e[e.DISABLED_PACKET=4006]="DISABLED_PACKET",e[e.MIDDLEWARE=4007]="MIDDLEWARE",e[e.MANUAL_SHUTDOWN=4008]="MANUAL_SHUTDOWN"}(i||(t.CloseCodes=i={}))},575(e,t,n){var a=n(302);e.exports=n.v(t,e.id,"a6f0905881362e81621d",{"./sonic_ws_core_bg.js":{__wbg_get_unchecked_6e0ad6d2a41b06f6:a.ss,__wbg_length_370319915dc99107:a.Sg,__wbg_push_d2ae3af0c1217ae6:a.Tb,__wbg_new_32b398fb48b6d94a:a.gV,__wbg_new_cd45aabdf6073e84:a.EW,__wbg_length_1f0964f4a5e2c6d8:a.Pt,__wbg_prototypesetcall_4770620bbe4688a0:a.pe,__wbg_new_from_slice_77cdfb7977362f3c:a.BV,__wbg___wbindgen_string_get_b0ca35b86a603356:a.oF,__wbg___wbindgen_number_get_394265ed1e1b84ee:a.JV,__wbg___wbindgen_throw_344f42d3211c4765:a.F6,__wbg___wbindgen_boolean_get_fa956cfa2d1bd751:a.sL,__wbindgen_init_externref_table:a.bL,__wbindgen_cast_0000000000000001:a.NR,__wbindgen_cast_0000000000000002:a.U_}})},576(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.PacketHolder=void 0;t.PacketHolder=class{key;keys;tags;packetMap;packets;constructor(e){this.key=1,this.keys={},this.tags={},this.packetMap={},e&&this.holdPackets(e)}createKey(e){this.keys[e]=this.key,this.tags[this.key]=e,this.key++}holdPackets(e){this.packets=e;for(const t of e)this.createKey(t.tag),this.packetMap[t.tag]=t}getKey(e){if(!(e in this.keys))throw new Error(`Not a valid tag: ${e}`);return this.keys[e]}getTag(e){if(e in this.tags)return this.tags[e]}getPacket(e){if(!(e in this.packetMap))throw new Error("Unknown packet tag: "+e);return this.packetMap[e]}hasKey(e){return e in this.tags}hasTag(e){return e in this.keys}getKeys(){return this.keys}getTagMap(){return this.tags}getTags(){return Object.values(this.tags)}getPackets(){return this.packets}serialize(){return this.packets.map(e=>e.serialize()).flat()}}},718(e,t){Object.defineProperty(t,"__esModule",{value:!0}),t.setHashFunc=function(e){i=e?r:s},t.hashValue=function(e){return i(e)};const n=1099511628211n,a=(1n<<64n)-1n,r=e=>{let t=14695981039346656037n;const r=e=>{if(null===e)return t^=0n,void(t=t*n&a);const s=typeof e;if("number"===s)return t^=BigInt(Math.trunc(e)),void(t=t*n&a);if("string"!==s){if("boolean"===s)return t^=e?1n:0n,void(t=t*n&a);if(Array.isArray(e))for(let t=0;t<e.length;t++)r(e[t]);else if("object"===s){const s=Object.keys(e).sort();for(let i=0;i<s.length;i++){const o=s[i];for(let e=0;e<o.length;e++)t^=BigInt(o.charCodeAt(e)),t=t*n&a;r(e[o])}}}else for(let r=0;r<e.length;r++)t^=BigInt(e.charCodeAt(r)),t=t*n&a};return r(e),t},s=e=>{let t=2166136261;const n=e=>{if(null===e)return void(t^=0);const a=typeof e;if("number"===a)return t^=0|e,void(t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24));if("string"!==a)if("boolean"!==a){if(Array.isArray(e))for(let t=0;t<e.length;t++)n(e[t]);else if("object"===a){const a=Object.keys(e).sort();for(let r=0;r<a.length;r++){const s=a[r];for(let e=0;e<s.length;e++)t^=s.charCodeAt(e),t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24);n(e[s])}}}else t^=e?1:0;else for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t+=(t<<1)+(t<<4)+(t<<7)+(t<<8)+(t<<24)};return n(e),t>>>0};let i=r},765(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.SonicWSCore=void 0;const a=n(576),r=n(26),s=n(795),i=n(917),o=n(766),c=n(402),d=n(284),l=n(818),u=n(549),h=n(113);class p extends u.Connection{preListen;clientPackets=new a.PacketHolder;serverPackets=new a.PacketHolder;pastKeys=!1;readyListeners=[];bufferHandler;_timers={};asyncData={};asyncMap={};constructor(e,t,n,a){super(e,-1,"LocalSocket",n,a),this.socket=e,this.preListen={},this.invalidPacket=this.invalidPacket.bind(this),this.serverKeyHandler=this.serverKeyHandler.bind(this),this.messageHandler=this.messageHandler.bind(this),this._on("message",this.serverKeyHandler),this._on("close",()=>{this.callMiddleware("onStatusChange",WebSocket.CLOSED);for(const[e,t,n]of Object.values(this._timers))this.clearTimeout(e),n&&t(!0);for(const e of this.clientPackets.getPackets())delete e.lastSent[0];for(const e of this.serverPackets.getPackets())delete e.lastReceived[0]}),this.bufferHandler=t}reading=!1;readQueue=[];async serverKeyHandler(e){if(this.reading)return this.readQueue.push(e);this.reading=!0;const t=await this.bufferHandler(e);if(t.length<3||(0,h.as8String)(t.slice(0,3))!=o.SERVER_SUFFIX)throw this.close(1e3),new Error("The server requested is not a Sonic WS server.");const n=t[3];if(n!=o.VERSION)throw this.close(1e3),new Error(`Version mismatch: ${n>o.VERSION?"client":"server"} is outdated (server: ${n}, client: ${o.VERSION})`);const a=(0,s.inflateNative)(t.subarray(4,t.length)),[i,d]=(0,r.readVarInt)(a,0);this.id=d;const[l,u]=(0,r.readVarInt)(a,i),p=a.subarray(l,l+u);this.clientPackets.holdPackets(c.Packet.deserializeAll(p,!0));const f=a.subarray(l+u,a.length);this.serverPackets.holdPackets(c.Packet.deserializeAll(f,!0)),this.batcher.registerSendPackets(this.clientPackets,this);for(const e of this.serverPackets.getPackets()){const t=this.serverPackets.getKey(e.tag);this.asyncMap[t]=e.async,e.async&&(this.asyncData[t]=[!1,[]])}Object.keys(this.preListen).forEach(e=>this.preListen[e].forEach(t=>{if(!this.serverPackets.hasTag(e))return console.error(new Error(`The server does not send the packet with tag "${e}"!`));this.listen(e,t)})),this.preListen=null,this.pastKeys=!0,this.readyListeners.forEach(e=>e()),this.readyListeners=null,this._off("message",this.serverKeyHandler),this._on("message",this.messageHandler),this.readQueue.forEach(e=>this.messageHandler(e)),this.readQueue=[]}invalidPacket(e){throw console.error(e),new Error("An error occured with data from the server!! This is probably my fault.. make an issue at https://github.com/liwybloc/sonic-ws")}listenLock=!1;packetQueue=[];async listenPacket(e,t,n,a,r){const s=this.listeners[t];if(!s)return console.warn("Warn: No listener for packet "+t);await this.enqueuePacket(e,s,n,a,r),await this.callMiddleware("onReceive_post",t,"string"==typeof e?[e]:e[0])}isAsync(e){return this.asyncMap[e]}async enqueuePacket(e,t,n,a,r){await(0,i.listenPacket)(e,t,this.invalidPacket),await this.triggerNextPacket(n,a,r)}async triggerNextPacket(e,t,n){t?n[0]=!1:this.listenLock=!1,e.length>0&&this.dataHandler(e.shift())}async dataHandler(e){const t=e[0],n=e.slice(1),a=this.isAsync(t);let r,s,i;if(a?(i=this.asyncData[t],r=i[0],s=i[1]):(r=this.listenLock,s=this.packetQueue),r)return void s.push(e);a?i[0]=!0:this.listenLock=!0;const o=this.serverPackets.getTag(t),c=this.serverPackets.getPacket(o);if(await this.callMiddleware("onReceive_pre",c.tag,e,e.length))return;if(c.rereference&&0==n.length)return void 0===c.lastReceived[0]?this.invalidPacket("No previous value to rereference"):void this.listenPacket(c.lastReceived[0],o,s,a,i);if(0==c.dataBatching){const e=c.lastReceived[0]=await c.listen(n,null);return void this.listenPacket(e,o,s,a,i)}const l=await d.BatchHelper.unravelBatch(c,n,null);if("string"==typeof l)return this.invalidPacket(l);l.forEach(e=>this.listenPacket(e,o,s,a,i))}async messageHandler(e){const t=await this.bufferHandler(e);t.length<1||await this.dataHandler(t)}listen(e,t){this.serverPackets.hasTag(e)?(this.listeners[e]??=[]).push(t):console.log("Tag is not available on server: "+e)}raw_onsend(e){this.listeners.send.push(e)}sendQueue=[!1,[],void 0];async send(e,...t){if(await this.callMiddleware("onSend_pre",e,t,Date.now(),performance.now()))return;const[n,a,r]=await(0,i.processPacket)(this.clientPackets,e,t,this.sendQueue,0);0==r.dataBatching?this.raw_send((0,l.toPacketBuffer)(n,a)):this.batcher.batchPacket(n,a),await this.callMiddleware("onSend_post",e,a,a.length)}on_ready(e){this.pastKeys?e():this.readyListeners.push(e)}on_close(e){this._on("close",e)}on(e,t){if(this.socket.readyState!==WebSocket.OPEN)return this.preListen[e]||(this.preListen[e]=[]),void this.preListen[e].push(t);this.listen(e,t)}}t.SonicWSCore=p},766(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.SERVER_SUFFIX_NUMS=t.SERVER_SUFFIX=t.VERSION=void 0;const a=n(113);t.VERSION=22,t.SERVER_SUFFIX="SWS",t.SERVER_SUFFIX_NUMS=(0,a.processCharCodes)(t.SERVER_SUFFIX)},795(__unused_webpack_module,exports,__webpack_require__){var __webpack_dirname__="/";Object.defineProperty(exports,"__esModule",{value:!0}),exports.setNativeCore=setNativeCore,exports.initializeWasmCore=initializeWasmCore,exports.loadNativeCore=loadNativeCore,exports.encodeNative=encodeNative,exports.decodeNative=decodeNative,exports.validateNative=validateNative,exports.encodeNativeObject=encodeNativeObject,exports.decodeNativeObject=decodeNativeObject,exports.validateNativeObject=validateNativeObject,exports.encodeNativeBatch=encodeNativeBatch,exports.decodeNativeBatch=decodeNativeBatch,exports.deflateNative=deflateNative,exports.inflateNative=inflateNative;const PacketType_1=__webpack_require__(319);let loadedCore;function buffer(e){return"undefined"!=typeof Buffer?Buffer.from(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e.buffer,e.byteOffset,e.byteLength)}function values(e){return Array.isArray(e)?[...e]:[e]}function assertNativeCore(e){const t=["encodeSigned","decodeSigned","encodeUnsigned","decodeUnsigned","encodeFloats","decodeFloats","encodeStrings","decodeStrings","encodeBooleans","decodeBooleans","encodeRaw","decodeRaw","encodeHex","decodeHex","frameObject","unframeObject","encodeBatch","decodeBatch","deflateRaw","inflateRaw","validateEncoded","validateEnum","validateObject"].filter(t=>"function"!=typeof e[t]);if(t.length>0)throw new Error(`Invalid SonicWS native addon; missing: ${t.join(", ")}`)}function setNativeCore(e){assertNativeCore(e),loadedCore=e}async function initializeWasmCore(){const wasm="undefined"==typeof window?eval("require")("./wasm/node/sonic_ws_core.js"):await Promise.resolve().then(__webpack_require__.bind(__webpack_require__,322));return setNativeCore(wasm),loadedCore}function loadNativeCore(addonPath){if(loadedCore&&!addonPath)return loadedCore;const candidates=addonPath?[addonPath]:["undefined"!=typeof process?process.env.SONIC_WS_CORE_PATH:void 0,`${__webpack_dirname__}/sonic_ws_core.node`,`${__webpack_dirname__}/../../../native/sonic_ws_core.node`].filter(e=>Boolean(e)),failures=[],nodeRequire="undefined"==typeof window?eval("require"):void 0;for(const e of candidates)try{const t=nodeRequire(e);return assertNativeCore(t),addonPath||(loadedCore=t),t}catch(t){failures.push(`${e}: ${t instanceof Error?t.message:String(t)}`)}if("undefined"==typeof window)try{const e=nodeRequire("./wasm/node/sonic_ws_core.js");return assertNativeCore(e),loadedCore=e,e}catch(e){failures.push(`Node WASM fallback: ${e instanceof Error?e.message:String(e)}`)}throw new Error(`SonicWS codec is not initialized. In Node, set SONIC_WS_CORE_PATH; in browsers, await initializeWasmCore().\n${failures.join("\n")}`)}function enumIndex(e,t){const n=e.values.findIndex(e=>e===t||"number"==typeof e&&"number"==typeof t&&Number.isNaN(e)&&Number.isNaN(t));if(n<0)throw new Error(`Value ${String(t)} does not exist in enum ${e.tag}`);return n}function encodeNative(e,t,n,a=loadNativeCore()){switch(e){case PacketType_1.PacketType.NONE:if(null!=t&&(!Array.isArray(t)||0!==t.length))throw new TypeError("NONE only accepts null, undefined, or an empty array");return new Uint8Array(0);case PacketType_1.PacketType.RAW:case PacketType_1.PacketType.JSON:if(!(t instanceof Uint8Array||Array.isArray(t)))throw new TypeError((e===PacketType_1.PacketType.JSON?"JSON wire data":"RAW")+" requires a Uint8Array or number array");return a.encodeRaw(t instanceof Uint8Array?buffer(t):Uint8Array.from(t));case PacketType_1.PacketType.BYTES:case PacketType_1.PacketType.SHORTS:case PacketType_1.PacketType.VARINT:case PacketType_1.PacketType.DELTAS:return a.encodeSigned(e,values(t));case PacketType_1.PacketType.UBYTES:case PacketType_1.PacketType.USHORTS:case PacketType_1.PacketType.UVARINT:return a.encodeUnsigned(e,values(t));case PacketType_1.PacketType.FLOATS:case PacketType_1.PacketType.DOUBLES:return a.encodeFloats(e,values(t));case PacketType_1.PacketType.STRINGS_ASCII:case PacketType_1.PacketType.STRINGS_UTF16:return a.encodeStrings(e,values(t));case PacketType_1.PacketType.BOOLEANS:return a.encodeBooleans(values(t));case PacketType_1.PacketType.HEX:{const e=Array.isArray(t)?t[0]:t;if("string"!=typeof e)throw new TypeError("HEX requires one string");return a.encodeHex(e)}case PacketType_1.PacketType.ENUMS:if(!n)throw new Error("ENUMS requires an EnumPackage");return Uint8Array.from(values(t).map(e=>enumIndex(n,e)));case PacketType_1.PacketType.KEY_EFFECTIVE:throw new Error("KEY_EFFECTIVE is not implemented");default:throw new Error(`Unknown packet type: ${e}`)}}function decodeNative(e,t,n=4294967295,a,r=loadNativeCore()){const s=buffer(t);switch(e){case PacketType_1.PacketType.NONE:if(0!==t.byteLength)throw new Error("NONE packet contains data");return;case PacketType_1.PacketType.RAW:case PacketType_1.PacketType.JSON:return r.decodeRaw(s);case PacketType_1.PacketType.BYTES:case PacketType_1.PacketType.SHORTS:case PacketType_1.PacketType.VARINT:case PacketType_1.PacketType.DELTAS:return r.decodeSigned(e,s);case PacketType_1.PacketType.UBYTES:case PacketType_1.PacketType.USHORTS:case PacketType_1.PacketType.UVARINT:return r.decodeUnsigned(e,s);case PacketType_1.PacketType.FLOATS:case PacketType_1.PacketType.DOUBLES:return r.decodeFloats(e,s);case PacketType_1.PacketType.STRINGS_ASCII:case PacketType_1.PacketType.STRINGS_UTF16:return r.decodeStrings(e,s);case PacketType_1.PacketType.BOOLEANS:return r.decodeBooleans(s,n);case PacketType_1.PacketType.HEX:return r.decodeHex(s);case PacketType_1.PacketType.ENUMS:if(!a)throw new Error("ENUMS requires an EnumPackage");return[...t].map(e=>{if(e>=a.values.length)throw new Error(`Enum index ${e} is out of range`);return a.values[e]});case PacketType_1.PacketType.KEY_EFFECTIVE:throw new Error("KEY_EFFECTIVE is not implemented");default:throw new Error(`Unknown packet type: ${e}`)}}function validateNative(e,t,n,a,r={},s=loadNativeCore()){if(e!==PacketType_1.PacketType.ENUMS)s.validateEncoded(e,buffer(t),n,a,r.compressed??!1,r.batched??!1,r.maxBatchSize);else{if(!r.enumData)throw new Error("ENUMS requires an EnumPackage");s.validateEnum(buffer(t),r.enumData.values.length,n,a)}}function encodeNativeObject(e,t,n=loadNativeCore()){if(t.length!==e.types.length)throw new Error("Object field count does not match schema");let a=0;const r=e.types.map((r,s)=>encodeNative(r,t[s],r===PacketType_1.PacketType.ENUMS?e.enumData?.[a++]:void 0,n));return n.frameObject(r)}function decodeNativeObject(e,t,n=loadNativeCore()){const a=n.unframeObject(buffer(t),e.types.length);let r=0;return a.map((t,a)=>decodeNative(e.types[a],t,e.dataMaxes[a],e.types[a]===PacketType_1.PacketType.ENUMS?e.enumData?.[r++]:void 0,n))}function validateNativeObject(e,t,n=loadNativeCore()){n.validateObject(buffer(t),[...e.types],[...e.dataMins],[...e.dataMaxes],(e.enumData??[]).map(e=>e.values.length))}function encodeNativeBatch(e,t,n=loadNativeCore()){return n.encodeBatch(e.map(buffer),t)}function decodeNativeBatch(e,t,n=0,a,r=loadNativeCore()){const s=Number.isFinite(n)&&n>0?n:0;return r.decodeBatch(buffer(e),t,s,a)}function deflateNative(e,t=loadNativeCore()){return t.deflateRaw(buffer(e))}function inflateNative(e,t,n=loadNativeCore()){return n.inflateRaw(buffer(e),t)}},818(e,t){function n(e,t){const n=[];for(let a=0;a<e.length;a+=t){const r=e.slice(a,a+t);n.push(r)}return n}Object.defineProperty(t,"__esModule",{value:!0}),t.splitArray=n,t.toPacketBuffer=function(e,t){const n=new Uint8Array(1+t.length);return n[0]=e,n.set(t,1),n},t.splitBuffer=function(e,t){return n(Array.from(e),t)},t.stringifyBuffer=function(e){return`<Buffer ${Array.from(e).map(e=>e.toString(16).padStart(2,"0")).join(" ")}>`}},864(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.SET_PACKAGES=t.ENUM_KEY_TO_TAG=t.ENUM_TAG_TO_KEY=t.MAX_ENUM_SIZE=void 0,t.DefineEnum=function(e,n){const a=t.SET_PACKAGES[e];if(a){if(a.values.find((e,t)=>n[t]!=e))throw new Error(`Pre-existing enum package of tag '${e}' is set and different!`);return a}if(n.length>t.MAX_ENUM_SIZE)throw new Error(`An enum can only hold ${t.MAX_ENUM_SIZE} possible values.`);return t.ENUM_TAG_TO_KEY[e]=Object.fromEntries(n.map((e,t)=>[e,t])),t.ENUM_KEY_TO_TAG[e]=Object.fromEntries(n.map((e,t)=>[t,e])),t.SET_PACKAGES[e]=new r.EnumPackage(e,n)},t.WrapEnum=function(e,n){if(!(n in t.ENUM_TAG_TO_KEY[e]))throw new Error(`Value "${n}" does not exist in enum "${e}"`);return t.ENUM_TAG_TO_KEY[e][n]},t.DeWrapEnum=function(e,n){return t.ENUM_KEY_TO_TAG[e][n]};const a=n(26),r=n(14);t.MAX_ENUM_SIZE=a.MAX_BYTE,t.ENUM_TAG_TO_KEY={},t.ENUM_KEY_TO_TAG={},t.SET_PACKAGES={}},917(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.processPacket=c,t.listenPacket=async function(e,t,n){if("string"==typeof e)return n(e);const[a,r]=e;try{if(r&&Array.isArray(a))for(const e of t)await e(...a);else for(const e of t)await e(a)}catch(e){console.error(e),n(e)}},t.CreatePacket=p,t.CreateObjPacket=function(e){let{tag:t,types:n=[],dataMaxes:s,dataMins:i,noDataRange:o=!1,dontSpread:c=!1,autoFlatten:p=!1,validator:f=null,dataBatching:w=0,maxBatchSize:_=10,rateLimit:y=0,enabled:m=!0,async:g=!1,gzipCompression:b=n&&n.includes(r.PacketType.JSON)}=e;if(!t)throw new Error("Tag not selected!");if(!n||0==n.length)throw new Error("Types is set to 0 length");for(const e of n)if(d(e))throw new Error(`Invalid packet type in "${t}" packet: ${e}`);o?(s=Array.from({length:n.length}).map(()=>l),i=Array.from({length:n.length}).map(()=>0)):(null==s?s=Array.from({length:n.length}).map(()=>1):Array.isArray(s)||(s=Array.from({length:n.length}).map(()=>s)),null==i?i=Array.from({length:n.length}).map((e,t)=>s[t]):Array.isArray(i)||(i=Array.from({length:n.length}).map(()=>i)));const v=s.map(u),k=i.map((e,t)=>n[t]==r.PacketType.NONE?0:h(e,v[t])),S=new a.PacketSchema(!0,n,g,k,v,y,c,p,!1,w,_,b);return new a.Packet(t,S,f,m,!1)},t.CreateEnumPacket=function(e){const{tag:t,enumData:n,dataMax:a=1,dataMin:r=0,noDataRange:s=!1,dontSpread:i=!1,validator:o=null,dataBatching:c=0,maxBatchSize:d=10,rateLimit:l=0,enabled:u=!0,async:h=!1}=e;return p({tag:t,type:n,dataMax:a,dataMin:r,noDataRange:s,dontSpread:i,validator:o,dataBatching:c,maxBatchSize:d,rateLimit:l,enabled:u,async:h})},t.CreateKeyEffective=function(e){const{tag:t,count:n=2,validator:a=null,async:r=!1}=e;if(!t)throw new Error("Tag not selected!");if(n<2)throw new Error("Must have at least 2 key consumptions on key effective packet!");throw new Error("Currently W.I.P.")},t.FlattenData=f,t.UnFlattenData=function(e){return e[0]?.map((t,n)=>e.map(e=>e[n]))??[]};const a=n(402),r=n(319),s=n(14),i=n(26),o=n(718);async function c(e,t,n,a,s,d=!1){const l=e.getKey(t),u=e.getPacket(t);return async function(e,t,n,a,r,s,i){if(e[0]&&!s)return new Promise(t=>e[1].push([t,a,r]));e[0]=!0;const o=await i();if(e[1].length>0){const[a,r,s]=e[1].shift();queueMicrotask(async()=>{a(await c(t,r,s,e,n,!0))})}else e[0]=!1;return o}(a,e,s,t,n,d,async()=>{if(u.rereference){if(-1===s)throw new Error("Cannot send a re-referenced packet from the server-wide sender!");const e=(0,o.hashValue)(n);if(u.lastSent[s]===e)return[l,i.EMPTY_UINT8,u];u.lastSent[s]=e}if(u.autoFlatten)n=f(n[0]);else{if(n.length>u.maxSize)throw new Error(`Packet "${t}" only allows ${u.maxSize} values!`);if(n.length<u.minSize)throw new Error(`Packet "${t}" requires at least ${u.minSize} values!`)}if(u.object){if(n=n.map(e=>Array.isArray(e)?e:[e]),!u.autoFlatten){const e=u.dataMin,a=u.dataMax;for(let r=0;r<e.length;r++){if(n[r].length<e[r])throw new Error(`Section ${r+1} of packet "${t}" requires at least ${e[r]} values!`);if(n[r].length>a[r])throw new Error(`Section ${r+1} of packet "${t}" only allows ${a[r]} values!`)}}}else if(u.type!==r.PacketType.JSON){const e=n.find(e=>"object"==typeof e&&null!=e);e&&console.warn(`Passing an array will result in undefined behavior (${JSON.stringify(e)}). Spread the array with ...arr`)}const e=n.length>0?await u.processSend(n):i.EMPTY_UINT8;return[l,e,u]})}function d(e){return!(("number"==typeof e&&e in r.PacketType||e instanceof s.EnumPackage)&&e!=r.PacketType.KEY_EFFECTIVE)}const l=2048383;function u(e){return e<0?(console.warn("Having a data maximum below 0 does not do anything!"),0):e>l?(console.warn("Only 2048383 values can be sent on a type! Uhh make an issue if you want to send more."),l):e}function h(e,t){return e<0?(console.warn("Having a data minimum below 0 does not do anything!"),0):e>t?(console.warn("Data minimum can not be higher than the data maximum!"),t):e}function p(e){let{tag:t,type:n=r.PacketType.NONE,dataMax:s=1,dataMin:i=1,noDataRange:o=!1,dontSpread:c=!1,validator:p=null,dataBatching:f=0,maxBatchSize:w=10,rateLimit:_=0,enabled:y=!0,async:m=!1,gzipCompression:g=n==r.PacketType.JSON,rereference:b=!1}=e;if(!t)throw new Error("Tag not selected!");if(o?(i=b?1:0,s=l):null==i&&(i=n==r.PacketType.NONE?0:s),b&&0==i)throw new Error("Rereference cannot be true if the dataMin is 0");if(d(n))throw new Error(`Invalid packet type: ${n}`);const v=new a.PacketSchema(!1,n,m,h(i,s),u(s),_,c,!1,b,f,w,g);return new a.Packet(t,v,p,y,!1)}function f(e){if(null==e)return[];const t=e[0];if(null==t)return[];if(!Array.isArray(t))throw new Error(`Cannot flatten array: ${e}`);return t.map((t,n)=>e.map(e=>e[n]))??[]}},980(e,t,n){Object.defineProperty(t,"__esModule",{value:!0}),t.decompressJSON=t.compressJSON=void 0;const a=n(818),r=e=>Array.from({length:8},(t,n)=>!!(e&1<<7-n));function s(e){if(!Number.isInteger(e)||e<0)throw new Error(`Invalid JSON variable integer: ${e}`);const t=[];do{let n=127&e;(e>>>=7)>0&&(n|=128),t.push(n)}while(e>0);return t}function i(e,t){let n=0,a=0;for(;;){if(t>=e.length||a>28)throw new Error("Invalid JSON variable integer");const r=e[t++];if(n+=(127&r)<<a,!(128&r))return[t,n];a+=7}}var o;!function(e){e[e.NULL=0]="NULL",e[e.BOOL=1]="BOOL",e[e.INT=2]="INT",e[e.FLOAT=3]="FLOAT",e[e.STRING=4]="STRING",e[e.ARRAY=5]="ARRAY",e[e.OBJECT=6]="OBJECT"}(o||(o={}));const c=e=>{const t=(new TextEncoder).encode(e);return[...s(t.length),...t]},d=(e,t)=>{const[n,a]=i(e,t);return{value:(new TextDecoder).decode(e.subarray(n,n+a)),length:n+a-t}},l=e=>{let t="";for(const n of e)t+=n.toString(2).padStart(3,"0");return(e=>new Uint8Array(e.match(/.{1,8}/g)?.map(e=>parseInt(e.padEnd(8,"0"),2))??[]))(t)},u=(e,t)=>{const n=(e=>Array.from(e,e=>e.toString(2).padStart(8,"0")).join(""))(e),a=[];for(let e=0;e<t;e++)a.push(parseInt(n.slice(3*e,3*e+3),2));return a};t.compressJSON=e=>{const t=[],n=[],r=[],i=e=>{switch(null===e?"null":Array.isArray(e)?"array":typeof e){case"null":r.push(o.NULL);break;case"boolean":r.push(o.BOOL),t.push(e);break;case"number":Number.isInteger(e)?(r.push(o.INT),n.push(...s((e=>e<<1^e>>31)(e)))):(r.push(o.FLOAT),n.push(...function(e){if(Number.isNaN(e))return[127,128,0,1];const t=e<0?1:0;if(0===(e=Math.abs(e)))return[0,0,0,0];const n=Math.floor(Math.log2(e));if(!Number.isFinite(e)||n>127||n<-126)return[t?255:127,128,0,0];const a=(t<<31|n+127<<23|8388607&Math.round((e/2**n-1)*2**23))>>>0;return[a>>>24,a>>>16&255,a>>>8&255,255&a]}(e)));break;case"string":r.push(o.STRING),n.push(...c(e));break;case"array":r.push(o.ARRAY),n.push(...s(e.length));for(const t of e)i(t);break;case"object":{r.push(o.OBJECT);const t=Object.keys(e);n.push(...s(t.length));for(const a of t)n.push(...c(a)),i(e[a]);break}default:throw new Error("Unsupported type")}};i(e);const d=t.length?(0,a.splitArray)(t,8).map(e=>e.reduce((e,t,n)=>e|Number(t)<<7-n,0)):[],u=l(r),h=[...s(d.length),...s(u.length)];return Uint8Array.from([...h,...d.flat(),...u,...n])};t.decompressJSON=e=>{let t=0;const[n,a]=i(e,t);t=n;const[s,c]=i(e,t);t=s;const l=[];for(let n=0;n<a;n++)l.push(...r(e[t++]));let h=0;const p=e.subarray(t,t+c);t+=c;const f=u(p,8*p.length/3);let w=0;const _=n=>{if(n>500)throw new Error("JSON array too deep.");const a=f[w++];switch(a){case o.NULL:return null;case o.BOOL:return l[h++];case o.INT:{const[n,a]=i(e,t);return t=n,(r=a)>>>1^-(1&r)}case o.FLOAT:{const n=function(e){const t=(e[0]<<24|e[1]<<16|e[2]<<8|e[3])>>>0,n=t>>>23&255,a=(0===n?0:1)+(8388607&t)/2**23,r=255===n?0===a?1/0:NaN:a*2**(0===n?-126:n-127);return t>>>31?-r:r}(Array.from(e.subarray(t,t+4)));return t+=4,n}case o.STRING:{const{value:n,length:a}=d(e,t);return t+=a,n}case o.ARRAY:{const[a,r]=i(e,t);t=a;const s=[];for(let e=0;e<r;e++)s.push(_(n+1));return s}case o.OBJECT:{const[a,r]=i(e,t);t=a;const s={};for(let a=0;a<r;a++){const{value:a,length:r}=d(e,t);t+=r,s[a]=_(n+1)}return s}default:throw new Error(`Unknown type ${a}`)}var r};return _(0)}}},__webpack_module_cache__={},hasSymbol,webpackQueues,webpackExports,webpackError,resolveQueue;function __webpack_require__(e){var t=__webpack_module_cache__[e];if(void 0!==t)return t.exports;var n=__webpack_module_cache__[e]={id:e,exports:{}};return __webpack_modules__[e](n,n.exports,__webpack_require__),n.exports}hasSymbol="function"==typeof Symbol,webpackQueues=hasSymbol?Symbol("webpack queues"):"__webpack_queues__",webpackExports=hasSymbol?Symbol("webpack exports"):"__webpack_exports__",webpackError=hasSymbol?Symbol("webpack error"):"__webpack_error__",resolveQueue=e=>{e&&e.d<1&&(e.d=1,e.forEach(e=>e.r--),e.forEach(e=>e.r--?e.r++:e()))},__webpack_require__.a=(e,t,n)=>{var a;n&&((a=[]).d=-1);var r,s,i,o=new Set,c=e.exports,d=new Promise((e,t)=>{i=t,s=e});d[webpackExports]=c,d[webpackQueues]=e=>(a&&e(a),o.forEach(e),d.catch(e=>{})),e.exports=d,t(e=>{var t;r=(e=>e.map(e=>{if(null!==e&&"object"==typeof e){if(e[webpackQueues])return e;if(e.then){var t=[];t.d=0,e.then(e=>{n[webpackExports]=e,resolveQueue(t)},e=>{n[webpackError]=e,resolveQueue(t)});var n={};return n[webpackQueues]=e=>e(t),n}}var a={};return a[webpackQueues]=e=>{},a[webpackExports]=e,a}))(e);var n=()=>r.map(e=>{if(e[webpackError])throw e[webpackError];return e[webpackExports]}),s=new Promise(e=>{(t=()=>e(n)).r=0;var s=e=>e!==a&&!o.has(e)&&(o.add(e),e&&!e.d&&(t.r++,e.push(t)));r.map(e=>e[webpackQueues](s))});return t.r?s:n()},e=>(e?i(d[webpackError]=e):s(c),resolveQueue(a))),a&&a.d<0&&(a.d=0)},__webpack_require__.d=(e,t)=>{for(var n in t)__webpack_require__.o(t,n)&&!__webpack_require__.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},__webpack_require__.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(e){if("object"==typeof window)return window}}(),__webpack_require__.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),__webpack_require__.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},__webpack_require__.v=(e,t,n,a)=>{var r=fetch(__webpack_require__.p+"bundle.wasm"),s=()=>r.then(e=>e.arrayBuffer()).then(e=>WebAssembly.instantiate(e,a)).then(t=>Object.assign(e,t.instance.exports));return r.then(t=>"function"==typeof WebAssembly.instantiateStreaming?WebAssembly.instantiateStreaming(t,a).then(t=>Object.assign(e,t.instance.exports),e=>{if("application/wasm"!==t.headers.get("Content-Type"))return console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",e),s();throw e}):s())},(()=>{var e;__webpack_require__.g.importScripts&&(e=__webpack_require__.g.location+"");var t=__webpack_require__.g.document;if(!e&&t&&(t.currentScript&&"SCRIPT"===t.currentScript.tagName.toUpperCase()&&(e=t.currentScript.src),!e)){var n=t.getElementsByTagName("script");if(n.length)for(var a=n.length-1;a>-1&&(!e||!/^http(s?):/.test(e));)e=n[a--].src}if(!e)throw new Error("Automatic publicPath is not supported in this browser");e=e.replace(/^blob:/,"").replace(/#.*$/,"").replace(/\?.*$/,"").replace(/\/[^\/]+$/,"/"),__webpack_require__.p=e})();var __webpack_exports__={};(()=>{const e=__webpack_require__(241),t=__webpack_require__(864),n=__webpack_require__(917),a=__webpack_require__(765),r=__webpack_require__(795);class s extends a.SonicWSCore{static initialize(){return(0,r.initializeWasmCore)()}antiTamperCall=()=>{};constructor(e,t,n=!1){const a=new WebSocket(e,t);if(super(a,async e=>new Uint8Array(await e.data.arrayBuffer()),a.addEventListener.bind(a),a.removeEventListener.bind(a)),n){const e=this,t=a.send.bind(a),n=this.send.bind(this);let r;this.send=async(t,...a)=>(r=e.clientPackets.getKey(t),await n(t,...a)),a.send=n=>n instanceof Uint8Array&&r==n[0]?t(n):(e.antiTamperCall(),void e.close())}}on_tamper(e){this.antiTamperCall=e}WrapEnum(e,n){return(0,t.WrapEnum)(e,n)}DeWrapEnum(e,n){return(0,t.DeWrapEnum)(e,n)}FlattenData(e){return(0,n.FlattenData)(e)}UnFlattenData(e){return(0,n.UnFlattenData)(e)}debugClient=null;OpenDebug(){if(null!=this.debugClient)throw new Error("Debug client has already been opened!");this.debugClient=new e.DebugClient(this)}}window.SonicWS=s})()})();
|
|
Binary file
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2026 Lily (liwybloc)
|
|
3
|
-
*
|
|
2
|
+
* Copyright (c) 2026 Lily (liwybloc)
|
|
3
|
+
* License-Identifier: LicenseRef-Lily-Personal-NonCommercial-2026
|
|
4
|
+
* See LICENSE for personal, non-commercial license terms.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Copyright (c) 2026 Lily (liwybloc)
|
|
8
|
+
* License-Identifier: LicenseRef-Lily-Personal-NonCommercial-2026
|
|
9
|
+
* See LICENSE for personal, non-commercial license terms.
|
|
4
10
|
*/
|
|
5
11
|
export { SonicWS } from './ws/client/node/ClientNode';
|
|
6
12
|
export { SonicWSConnection } from './ws/server/SonicWSConnection';
|
|
@@ -9,3 +15,4 @@ export { PacketType } from './ws/packets/PacketType';
|
|
|
9
15
|
export { BasicMiddleware, ConnectionMiddleware, ServerMiddleware, BCInfo } from './ws/PacketProcessor';
|
|
10
16
|
export { CreatePacket, CreateObjPacket, CreateEnumPacket, FlattenData, UnFlattenData } from './ws/util/packets/PacketUtils';
|
|
11
17
|
export { DefineEnum, WrapEnum } from './ws/util/enums/EnumHandler';
|
|
18
|
+
export { initializeWasmCore } from './native/wrapper';
|
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
* Copyright 2026 Lily (liwybloc)
|
|
3
|
+
* Copyright (c) 2026 Lily (liwybloc)
|
|
4
4
|
*
|
|
5
|
-
* Licensed
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Licensed for personal, non-commercial use only.
|
|
6
|
+
* Commercial use, redistribution, sublicensing, sale, rental, lease,
|
|
7
|
+
* or inclusion in a paid product or service is prohibited without prior
|
|
8
|
+
* written permission from the copyright holder.
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
+
* See the LICENSE file in the project root for the full license terms.
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
12
|
+
* License-Identifier: LicenseRef-Lily-Personal-NonCommercial-2026
|
|
16
13
|
*/
|
|
17
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.WrapEnum = exports.DefineEnum = exports.UnFlattenData = exports.FlattenData = exports.CreateEnumPacket = exports.CreateObjPacket = exports.CreatePacket = exports.PacketType = exports.SonicWSServer = exports.SonicWSConnection = exports.SonicWS = void 0;
|
|
15
|
+
exports.initializeWasmCore = exports.WrapEnum = exports.DefineEnum = exports.UnFlattenData = exports.FlattenData = exports.CreateEnumPacket = exports.CreateObjPacket = exports.CreatePacket = exports.PacketType = exports.SonicWSServer = exports.SonicWSConnection = exports.SonicWS = void 0;
|
|
19
16
|
var ClientNode_1 = require("./ws/client/node/ClientNode");
|
|
20
17
|
Object.defineProperty(exports, "SonicWS", { enumerable: true, get: function () { return ClientNode_1.SonicWS; } });
|
|
21
18
|
var SonicWSConnection_1 = require("./ws/server/SonicWSConnection");
|
|
@@ -33,3 +30,5 @@ Object.defineProperty(exports, "UnFlattenData", { enumerable: true, get: functio
|
|
|
33
30
|
var EnumHandler_1 = require("./ws/util/enums/EnumHandler");
|
|
34
31
|
Object.defineProperty(exports, "DefineEnum", { enumerable: true, get: function () { return EnumHandler_1.DefineEnum; } });
|
|
35
32
|
Object.defineProperty(exports, "WrapEnum", { enumerable: true, get: function () { return EnumHandler_1.WrapEnum; } });
|
|
33
|
+
var wrapper_1 = require("./native/wrapper");
|
|
34
|
+
Object.defineProperty(exports, "initializeWasmCore", { enumerable: true, get: function () { return wrapper_1.initializeWasmCore; } });
|