sonic-ws 1.3.3 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/LICENSE +56 -196
  2. package/README.md +88 -17
  3. package/dist/{index.d.ts → ts/index.d.ts} +6 -0
  4. package/dist/{index.js → ts/index.js} +10 -11
  5. package/dist/ts/native/wrapper.d.ts +59 -0
  6. package/dist/ts/native/wrapper.js +7 -0
  7. package/dist/{version.d.ts → ts/version.d.ts} +5 -0
  8. package/dist/ts/version.js +7 -0
  9. package/dist/{ws → ts/ws}/Connection.d.ts +5 -0
  10. package/dist/ts/ws/Connection.js +7 -0
  11. package/dist/{ws → ts/ws}/PacketProcessor.d.ts +5 -0
  12. package/dist/ts/ws/PacketProcessor.js +7 -0
  13. package/dist/{ws → ts/ws}/client/core/ClientCore.d.ts +5 -0
  14. package/dist/ts/ws/client/core/ClientCore.js +7 -0
  15. package/dist/{ws → ts/ws}/client/node/ClientNode.d.ts +5 -0
  16. package/dist/ts/ws/client/node/ClientNode.js +7 -0
  17. package/dist/{ws → ts/ws}/debug/DebugServer.d.ts +5 -0
  18. package/dist/ts/ws/debug/DebugServer.js +7 -0
  19. package/dist/{ws → ts/ws}/packets/PacketType.d.ts +6 -1
  20. package/dist/ts/ws/packets/PacketType.js +7 -0
  21. package/dist/{ws → ts/ws}/packets/Packets.d.ts +5 -3
  22. package/dist/ts/ws/packets/Packets.js +7 -0
  23. package/dist/{ws → ts/ws}/server/SonicWSConnection.d.ts +5 -0
  24. package/dist/ts/ws/server/SonicWSConnection.js +7 -0
  25. package/dist/{ws → ts/ws}/server/SonicWSServer.d.ts +8 -0
  26. package/dist/ts/ws/server/SonicWSServer.js +7 -0
  27. package/dist/{ws → ts/ws}/util/BufferUtil.d.ts +5 -0
  28. package/dist/ts/ws/util/BufferUtil.js +7 -0
  29. package/dist/{ws → ts/ws}/util/StringUtil.d.ts +5 -2
  30. package/dist/ts/ws/util/StringUtil.js +7 -0
  31. package/dist/{ws → ts/ws}/util/enums/EnumHandler.d.ts +5 -0
  32. package/dist/ts/ws/util/enums/EnumHandler.js +7 -0
  33. package/dist/{ws → ts/ws}/util/enums/EnumType.d.ts +5 -0
  34. package/dist/ts/ws/util/enums/EnumType.js +7 -0
  35. package/dist/ts/ws/util/packets/BatchHelper.d.ts +6 -0
  36. package/dist/ts/ws/util/packets/BatchHelper.js +7 -0
  37. package/dist/ts/ws/util/packets/CompressionUtil.d.ts +13 -0
  38. package/dist/ts/ws/util/packets/CompressionUtil.js +7 -0
  39. package/dist/ts/ws/util/packets/HashUtil.d.ts +7 -0
  40. package/dist/ts/ws/util/packets/HashUtil.js +7 -0
  41. package/dist/ts/ws/util/packets/JSONUtil.d.ts +7 -0
  42. package/dist/ts/ws/util/packets/JSONUtil.js +7 -0
  43. package/dist/ts/ws/util/packets/PacketHolder.d.ts +6 -0
  44. package/dist/ts/ws/util/packets/PacketHolder.js +7 -0
  45. package/dist/{ws → ts/ws}/util/packets/PacketUtils.d.ts +5 -0
  46. package/dist/ts/ws/util/packets/PacketUtils.js +7 -0
  47. package/dist/ts/ws/util/packets/RateHandler.d.ts +6 -0
  48. package/dist/ts/ws/util/packets/RateHandler.js +7 -0
  49. package/package.json +14 -10
  50. package/dist/version.js +0 -25
  51. package/dist/ws/Connection.js +0 -126
  52. package/dist/ws/PacketProcessor.js +0 -52
  53. package/dist/ws/client/core/ClientCore.js +0 -251
  54. package/dist/ws/client/node/ClientNode.js +0 -36
  55. package/dist/ws/debug/DebugServer.js +0 -607
  56. package/dist/ws/packets/PacketProcessors.d.ts +0 -13
  57. package/dist/ws/packets/PacketProcessors.js +0 -317
  58. package/dist/ws/packets/PacketType.js +0 -61
  59. package/dist/ws/packets/Packets.js +0 -277
  60. package/dist/ws/server/SonicWSConnection.js +0 -298
  61. package/dist/ws/server/SonicWSServer.js +0 -307
  62. package/dist/ws/util/BufferUtil.js +0 -42
  63. package/dist/ws/util/StringUtil.js +0 -51
  64. package/dist/ws/util/enums/EnumHandler.js +0 -60
  65. package/dist/ws/util/enums/EnumType.js +0 -72
  66. package/dist/ws/util/packets/BatchHelper.d.ts +0 -1
  67. package/dist/ws/util/packets/BatchHelper.js +0 -85
  68. package/dist/ws/util/packets/CompressionUtil.d.ts +0 -35
  69. package/dist/ws/util/packets/CompressionUtil.js +0 -277
  70. package/dist/ws/util/packets/HashUtil.d.ts +0 -2
  71. package/dist/ws/util/packets/HashUtil.js +0 -122
  72. package/dist/ws/util/packets/JSONUtil.d.ts +0 -2
  73. package/dist/ws/util/packets/JSONUtil.js +0 -179
  74. package/dist/ws/util/packets/PacketHolder.d.ts +0 -1
  75. package/dist/ws/util/packets/PacketHolder.js +0 -126
  76. package/dist/ws/util/packets/PacketUtils.js +0 -283
  77. package/dist/ws/util/packets/RateHandler.d.ts +0 -1
  78. package/dist/ws/util/packets/RateHandler.js +0 -66
package/LICENSE CHANGED
@@ -1,196 +1,56 @@
1
- Copyright 2026 Lily (liwybloc)
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- You may not use this software except in compliance with the License.
5
- You may obtain a copy of the License at
6
-
7
- http://www.apache.org/licenses/LICENSE-2.0
8
-
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
14
-
15
- Apache License
16
- Version 2.0, January 2004
17
- http://www.apache.org/licenses/
18
-
19
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
20
-
21
- 1. Definitions.
22
-
23
- "License" shall mean the terms and conditions for use, reproduction,
24
- and distribution as defined by Sections 1 through 9 of this document.
25
-
26
- "Licensor" shall mean the copyright owner or entity authorized by
27
- the copyright owner that is granting the License.
28
-
29
- "Legal Entity" shall mean the union of the acting entity and all
30
- other entities that control, are controlled by, or are under common
31
- control with that entity. For the purposes of this definition,
32
- "control" means (i) the power, direct or indirect, to cause the
33
- direction or management of such entity, whether by contract or
34
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
35
- outstanding shares, or (iii) beneficial ownership of such entity.
36
-
37
- "You" (or "Your") shall mean an individual or Legal Entity
38
- exercising permissions granted by this License.
39
-
40
- "Source" form shall mean the preferred form for making modifications,
41
- including but not limited to software source code, documentation
42
- source, and configuration files.
43
-
44
- "Object" form shall mean any form resulting from mechanical
45
- transformation or translation of a Source form, including but
46
- not limited to compiled object code, generated documentation,
47
- and conversions to other media types.
48
-
49
- "Work" shall mean the work of authorship, whether in Source or
50
- Object form, made available under the License, as indicated by a
51
- copyright notice that is included in or attached to the work
52
- (an example is provided in the Appendix below).
53
-
54
- "Derivative Works" shall mean any work, whether in Source or Object
55
- form, that is based on (or derived from) the Work and for which the
56
- editorial revisions, annotations, elaborations, or other modifications
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
- ### WebSockets that handle correctness, security, and performance for you
4
-
5
- - No race conditions
6
- - No invalid packets
7
- - No accidental DoS
8
- - No cleanup bugs
9
- - No boilerplate
10
- - Many built-in security features
11
- - Lower bandwidth cost
12
- - Works much better on mobile
13
- - More readable than every other socket library
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 with heavy data ranges; supports code points fully up to the max of 0x10FFFF
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's for understanding; immensely intuitive (personally, I took a break for half a year and came back and snapped right back in)
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="https://cdn.jsdelivr.net/gh/liwybloc/sonic-ws/release/SonicWS_bundle"></script>
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
- *This will always give the latest release build. I will add branches for each release if this project actually goes anywhere.
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 socket.close();
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.
@@ -1,3 +1,8 @@
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
+ */
1
6
  export { SonicWS } from './ws/client/node/ClientNode';
2
7
  export { SonicWSConnection } from './ws/server/SonicWSConnection';
3
8
  export { SonicWSServer } from './ws/server/SonicWSServer';
@@ -5,3 +10,4 @@ export { PacketType } from './ws/packets/PacketType';
5
10
  export { BasicMiddleware, ConnectionMiddleware, ServerMiddleware, BCInfo } from './ws/PacketProcessor';
6
11
  export { CreatePacket, CreateObjPacket, CreateEnumPacket, FlattenData, UnFlattenData } from './ws/util/packets/PacketUtils';
7
12
  export { DefineEnum, WrapEnum } from './ws/util/enums/EnumHandler';
13
+ 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 under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
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
- * http://www.apache.org/licenses/LICENSE-2.0
10
+ * See the LICENSE file in the project root for the full license terms.
10
11
  *
11
- * Unless required by applicable law or agreed to in writing, software
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; } });
@@ -0,0 +1,59 @@
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
+ import { PacketType } from "../ws/packets/PacketType";
7
+ import { EnumPackage } from "../ws/util/enums/EnumType";
8
+ export interface SonicNativeCore {
9
+ encodeSigned(kind: number, values: number[]): Uint8Array;
10
+ decodeSigned(kind: number, data: Uint8Array): number[];
11
+ encodeUnsigned(kind: number, values: number[]): Uint8Array;
12
+ decodeUnsigned(kind: number, data: Uint8Array): number[];
13
+ encodeFloats(kind: number, values: number[]): Uint8Array;
14
+ decodeFloats(kind: number, data: Uint8Array): number[];
15
+ encodeStrings(kind: number, values: string[]): Uint8Array;
16
+ decodeStrings(kind: number, data: Uint8Array): string[];
17
+ encodeBooleans(values: boolean[]): Uint8Array;
18
+ decodeBooleans(data: Uint8Array, count: number): boolean[];
19
+ encodeRaw(data: Uint8Array): Uint8Array;
20
+ decodeRaw(data: Uint8Array): Uint8Array;
21
+ encodeHex(value: string): Uint8Array;
22
+ decodeHex(data: Uint8Array): string;
23
+ frameObject(sectors: Uint8Array[]): Uint8Array;
24
+ unframeObject(data: Uint8Array, fieldCount: number): Uint8Array[];
25
+ encodeBatch(payloads: Uint8Array[], compress: boolean): Uint8Array;
26
+ decodeBatch(data: Uint8Array, compressed: boolean, maxBatchSize: number, maxOutputSize?: number): Uint8Array[];
27
+ deflateRaw(data: Uint8Array): Uint8Array;
28
+ inflateRaw(data: Uint8Array, maxOutputSize?: number): Uint8Array;
29
+ validateEncoded(kind: number, data: Uint8Array, min: number, max: number, compressed: boolean, batched: boolean, maxBatchSize?: number): void;
30
+ validateEnum(data: Uint8Array, enumSize: number, min: number, max: number): void;
31
+ validateObject(data: Uint8Array, kinds: number[], minimums: number[], maximums: number[], enumSizes: number[]): void;
32
+ }
33
+ export interface NativeObjectSchema {
34
+ types: readonly PacketType[];
35
+ dataMins: readonly number[];
36
+ dataMaxes: readonly number[];
37
+ enumData?: readonly EnumPackage[];
38
+ }
39
+ /** Injects a native implementation, primarily for tests or custom addon loaders. */
40
+ export declare function setNativeCore(core: SonicNativeCore): void;
41
+ /** Loads and selects the webpack-compatible browser WASM implementation. */
42
+ export declare function initializeWasmCore(): Promise<SonicNativeCore>;
43
+ /** Loads the platform-specific Node addon lazily. */
44
+ export declare function loadNativeCore(addonPath?: string): SonicNativeCore;
45
+ export declare function encodeNative(type: PacketType, input: unknown, enumData?: EnumPackage, core?: SonicNativeCore): Uint8Array;
46
+ export declare function decodeNative(type: PacketType, data: Uint8Array, dataMax?: number, enumData?: EnumPackage, core?: SonicNativeCore): unknown;
47
+ export declare function validateNative(type: PacketType, data: Uint8Array, dataMin: number, dataMax: number, options?: {
48
+ compressed?: boolean;
49
+ batched?: boolean;
50
+ maxBatchSize?: number;
51
+ enumData?: EnumPackage;
52
+ }, core?: SonicNativeCore): void;
53
+ export declare function encodeNativeObject(schema: NativeObjectSchema, fields: readonly unknown[], core?: SonicNativeCore): Uint8Array;
54
+ export declare function decodeNativeObject(schema: NativeObjectSchema, data: Uint8Array, core?: SonicNativeCore): unknown[];
55
+ export declare function validateNativeObject(schema: NativeObjectSchema, data: Uint8Array, core?: SonicNativeCore): void;
56
+ export declare function encodeNativeBatch(payloads: readonly Uint8Array[], compressed: boolean, core?: SonicNativeCore): Uint8Array;
57
+ export declare function decodeNativeBatch(data: Uint8Array, compressed: boolean, maxBatchSize?: number, maxOutputSize?: number, core?: SonicNativeCore): Uint8Array[];
58
+ export declare function deflateNative(data: Uint8Array, core?: SonicNativeCore): Uint8Array;
59
+ export declare function inflateNative(data: Uint8Array, maxOutputSize?: number, core?: SonicNativeCore): Uint8Array;
@@ -0,0 +1,7 @@
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
+
7
+ 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=require("../ws/packets/PacketType");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 import("./wasm/pkg/sonic_ws_core.js");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,"undefined"!=typeof __dirname?`${__dirname}/sonic_ws_core.node`:void 0,"undefined"!=typeof __dirname?`${__dirname}/../../../native/sonic_ws_core.node`:void 0].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 a=e.values.findIndex(e=>e===t||"number"==typeof e&&"number"==typeof t&&Number.isNaN(e)&&Number.isNaN(t));if(a<0)throw new Error(`Value ${String(t)} does not exist in enum ${e.tag}`);return a}function encodeNative(e,t,a,r=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 r.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 r.encodeSigned(e,values(t));case PacketType_1.PacketType.UBYTES:case PacketType_1.PacketType.USHORTS:case PacketType_1.PacketType.UVARINT:return r.encodeUnsigned(e,values(t));case PacketType_1.PacketType.FLOATS:case PacketType_1.PacketType.DOUBLES:return r.encodeFloats(e,values(t));case PacketType_1.PacketType.STRINGS_ASCII:case PacketType_1.PacketType.STRINGS_UTF16:return r.encodeStrings(e,values(t));case PacketType_1.PacketType.BOOLEANS:return r.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 r.encodeHex(e)}case PacketType_1.PacketType.ENUMS:if(!a)throw new Error("ENUMS requires an EnumPackage");return Uint8Array.from(values(t).map(e=>enumIndex(a,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,a=4294967295,r,n=loadNativeCore()){const o=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 n.decodeRaw(o);case PacketType_1.PacketType.BYTES:case PacketType_1.PacketType.SHORTS:case PacketType_1.PacketType.VARINT:case PacketType_1.PacketType.DELTAS:return n.decodeSigned(e,o);case PacketType_1.PacketType.UBYTES:case PacketType_1.PacketType.USHORTS:case PacketType_1.PacketType.UVARINT:return n.decodeUnsigned(e,o);case PacketType_1.PacketType.FLOATS:case PacketType_1.PacketType.DOUBLES:return n.decodeFloats(e,o);case PacketType_1.PacketType.STRINGS_ASCII:case PacketType_1.PacketType.STRINGS_UTF16:return n.decodeStrings(e,o);case PacketType_1.PacketType.BOOLEANS:return n.decodeBooleans(o,a);case PacketType_1.PacketType.HEX:return n.decodeHex(o);case PacketType_1.PacketType.ENUMS:if(!r)throw new Error("ENUMS requires an EnumPackage");return[...t].map(e=>{if(e>=r.values.length)throw new Error(`Enum index ${e} is out of range`);return r.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,a,r,n={},o=loadNativeCore()){if(e!==PacketType_1.PacketType.ENUMS)o.validateEncoded(e,buffer(t),a,r,n.compressed??!1,n.batched??!1,n.maxBatchSize);else{if(!n.enumData)throw new Error("ENUMS requires an EnumPackage");o.validateEnum(buffer(t),n.enumData.values.length,a,r)}}function encodeNativeObject(e,t,a=loadNativeCore()){if(t.length!==e.types.length)throw new Error("Object field count does not match schema");let r=0;const n=e.types.map((n,o)=>encodeNative(n,t[o],n===PacketType_1.PacketType.ENUMS?e.enumData?.[r++]:void 0,a));return a.frameObject(n)}function decodeNativeObject(e,t,a=loadNativeCore()){const r=a.unframeObject(buffer(t),e.types.length);let n=0;return r.map((t,r)=>decodeNative(e.types[r],t,e.dataMaxes[r],e.types[r]===PacketType_1.PacketType.ENUMS?e.enumData?.[n++]:void 0,a))}function validateNativeObject(e,t,a=loadNativeCore()){a.validateObject(buffer(t),[...e.types],[...e.dataMins],[...e.dataMaxes],(e.enumData??[]).map(e=>e.values.length))}function encodeNativeBatch(e,t,a=loadNativeCore()){return a.encodeBatch(e.map(buffer),t)}function decodeNativeBatch(e,t,a=0,r,n=loadNativeCore()){const o=Number.isFinite(a)&&a>0?a:0;return n.decodeBatch(buffer(e),t,o,r)}function deflateNative(e,t=loadNativeCore()){return t.deflateRaw(buffer(e))}function inflateNative(e,t,a=loadNativeCore()){return a.inflateRaw(buffer(e),t)}
@@ -1,3 +1,8 @@
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
+ */
1
6
  /** Current protocol version */
2
7
  export declare const VERSION = 22;
3
8
  /** Server data suffix */
@@ -0,0 +1,7 @@
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
+
7
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.SERVER_SUFFIX_NUMS=exports.SERVER_SUFFIX=exports.VERSION=void 0;const e=require("./ws/util/StringUtil");exports.VERSION=22,exports.SERVER_SUFFIX="SWS",exports.SERVER_SUFFIX_NUMS=(0,e.processCharCodes)(exports.SERVER_SUFFIX);
@@ -1,3 +1,8 @@
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
+ */
1
6
  import { ConnectionMiddleware, IMiddlewareHolder, MiddlewareHolder } from "./PacketProcessor";
2
7
  import { BatchHelper } from "./util/packets/BatchHelper";
3
8
  /**
@@ -0,0 +1,7 @@
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
+
7
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.CloseCodes=exports.Connection=void 0,exports.getClosureCause=function(e){if(e>=4e3)return r[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 e=require("./PacketProcessor"),t=require("./util/packets/BatchHelper");class s extends e.MiddlewareHolder{listeners;name;closed=!1;socket;_timers={};batcher;_on;_off;id;constructor(e,s,r,o,i){super(),this.id=s,this.listeners={},this.name=r,this.socket=e,this.batcher=new t.BatchHelper,this._on=o,this._off=i,this._on("close",()=>{this.callMiddleware("onStatusChange",WebSocket.CLOSED),this.closed=!0;for(const[e,t,s]of Object.values(this._timers))this.clearTimeout(e),s&&t(!0)}),this._on("open",()=>this.callMiddleware("onStatusChange",WebSocket.OPEN))}setTimeout(e,t,s=!1){const r=setTimeout(()=>{e(),this.clearTimeout(r)},t);return this._timers[r]=[r,e,s],r}setInterval(e,t,s=!1){const r=setInterval(e,t);return this._timers[r]=[r,e,s],r}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 r;exports.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"}(r||(exports.CloseCodes=r={}));
@@ -1,3 +1,8 @@
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
+ */
1
6
  import { SonicWSConnection } from "./server/SonicWSConnection";
2
7
  /**
3
8
  * A basic middleware interface; extended by other middleware types
@@ -0,0 +1,7 @@
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
+
7
+ Object.defineProperty(exports,"__esModule",{value:!0}),exports.MiddlewareHolder=void 0;exports.MiddlewareHolder=class{middlewares=[];addMiddleware(e){this.middlewares.push(e);const r=e;try{"function"==typeof r.init&&r.init(this)}catch(e){console.warn("Middleware init threw an error:",e)}}async callMiddleware(e,...r){let t=!1;for(const d of this.middlewares){const i=d[e];if(i)try{await i(...r)&&(t=!0)}catch(r){console.warn(`Middleware ${String(e)} threw an error:`,r)}}return t}};
@@ -1,3 +1,8 @@
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
+ */
1
6
  import { PacketHolder } from "../../util/packets/PacketHolder";
2
7
  import { Connection } from "../../Connection";
3
8
  import { AsyncPQ, ClientPQ, PacketQueue } from "../../PacketProcessor";