sonic-ws 1.0.0-rc.8 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/LICENSE +190 -209
  2. package/README.md +11 -11
  3. package/dist/index.d.ts +0 -0
  4. package/dist/index.js +1 -1
  5. package/dist/version.d.ts +5 -3
  6. package/dist/version.js +8 -5
  7. package/dist/ws/Connection.d.ts +44 -0
  8. package/dist/ws/Connection.js +17 -0
  9. package/dist/ws/client/core/ClientCore.d.ts +9 -17
  10. package/dist/ws/client/core/ClientCore.js +122 -159
  11. package/dist/ws/client/node/ClientNode.d.ts +0 -0
  12. package/dist/ws/client/node/ClientNode.js +8 -25
  13. package/dist/ws/packets/PacketProcessors.d.ts +11 -7
  14. package/dist/ws/packets/PacketProcessors.js +218 -177
  15. package/dist/ws/packets/PacketType.d.ts +20 -16
  16. package/dist/ws/packets/PacketType.js +21 -17
  17. package/dist/ws/packets/Packets.d.ts +8 -10
  18. package/dist/ws/packets/Packets.js +186 -161
  19. package/dist/ws/server/SonicWSConnection.d.ts +7 -21
  20. package/dist/ws/server/SonicWSConnection.js +117 -148
  21. package/dist/ws/server/SonicWSServer.d.ts +0 -0
  22. package/dist/ws/server/SonicWSServer.js +79 -98
  23. package/dist/ws/util/ArrayUtil.d.ts +0 -0
  24. package/dist/ws/util/ArrayUtil.js +3 -3
  25. package/dist/ws/util/BufferUtil.d.ts +3 -0
  26. package/dist/ws/util/BufferUtil.js +19 -3
  27. package/dist/ws/util/StringUtil.d.ts +6 -0
  28. package/dist/ws/util/StringUtil.js +66 -0
  29. package/dist/ws/util/enums/EnumHandler.d.ts +2 -3
  30. package/dist/ws/util/enums/EnumHandler.js +17 -17
  31. package/dist/ws/util/enums/EnumType.d.ts +1 -1
  32. package/dist/ws/util/enums/EnumType.js +28 -24
  33. package/dist/ws/util/packets/BatchHelper.d.ts +9 -5
  34. package/dist/ws/util/packets/BatchHelper.js +50 -39
  35. package/dist/ws/util/packets/CompressionUtil.d.ts +22 -15
  36. package/dist/ws/util/packets/CompressionUtil.js +179 -141
  37. package/dist/ws/util/packets/PacketHolder.d.ts +1 -6
  38. package/dist/ws/util/packets/PacketHolder.js +43 -41
  39. package/dist/ws/util/packets/PacketUtils.d.ts +2 -6
  40. package/dist/ws/util/packets/PacketUtils.js +71 -70
  41. package/dist/ws/util/packets/RateHandler.d.ts +0 -0
  42. package/dist/ws/util/packets/RateHandler.js +24 -26
  43. package/package.json +6 -6
package/LICENSE CHANGED
@@ -1,209 +1,190 @@
1
- Copyright 2025 Lily (cutelittlelily)
2
-
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file 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
- Apache License
10
- Version 2.0, January 2004
11
- http://www.apache.org/licenses/
12
-
13
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
14
-
15
- 1. Definitions.
16
-
17
- "License" shall mean the terms and conditions for use, reproduction,
18
- and distribution as defined by Sections 1 through 9 of this document.
19
-
20
- "Licensor" shall mean the copyright owner or entity authorized by
21
- the copyright owner that is granting the License.
22
-
23
- "Legal Entity" shall mean the union of the acting entity and all
24
- other entities that control, are controlled by, or are under common
25
- control with that entity. For the purposes of this definition,
26
- "control" means (i) the power, direct or indirect, to cause the
27
- direction or management of such entity, whether by contract or
28
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
29
- outstanding shares, or (iii) beneficial ownership of such entity.
30
-
31
- "You" (or "Your") shall mean an individual or Legal Entity
32
- exercising permissions granted by this License.
33
-
34
- "Source" form shall mean the preferred form for making modifications,
35
- including but not limited to software source code, documentation
36
- source, and configuration files.
37
-
38
- "Object" form shall mean any form resulting from mechanical
39
- transformation or translation of a Source form, including but
40
- not limited to compiled object code, generated documentation,
41
- and conversions to other media types.
42
-
43
- "Work" shall mean the work of authorship, whether in Source or
44
- Object form, made available under the License, as indicated by a
45
- copyright notice that is included in or attached to the work
46
- (an example is provided in the Appendix below).
47
-
48
- "Derivative Works" shall mean any work, whether in Source or Object
49
- form, that is based on (or derived from) the Work and for which the
50
- editorial revisions, annotations, elaborations, or other modifications
51
- represent, as a whole, an original work of authorship. For the purposes
52
- of this License, Derivative Works shall not include works that remain
53
- separable from, or merely link (or bind by name) to the interfaces of,
54
- the Work and Derivative Works thereof.
55
-
56
- "Contribution" shall mean any work of authorship, including
57
- the original version of the Work and any modifications or additions
58
- to that Work or Derivative Works thereof, that is intentionally
59
- submitted to Licensor for inclusion in the Work by the copyright owner
60
- or by an individual or Legal Entity authorized to submit on behalf of
61
- the copyright owner. For the purposes of this definition, "submitted"
62
- means any form of electronic, verbal, or written communication sent
63
- to the Licensor or its representatives, including but not limited to
64
- communication on electronic mailing lists, source code control systems,
65
- and issue tracking systems that are managed by, or on behalf of, the
66
- Licensor for the purpose of discussing and improving the Work, but
67
- excluding communication that is conspicuously marked or otherwise
68
- designated in writing by the copyright owner as "Not a Contribution."
69
-
70
- "Contributor" shall mean Licensor and any individual or Legal Entity
71
- on behalf of whom a Contribution has been received by Licensor and
72
- subsequently incorporated within the Work.
73
-
74
- 2. Grant of Copyright License. Subject to the terms and conditions of
75
- this License, each Contributor hereby grants to You a perpetual,
76
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
- copyright license to reproduce, prepare Derivative Works of,
78
- publicly display, publicly perform, sublicense, and distribute the
79
- Work and such Derivative Works in Source or Object form.
80
-
81
- 3. Grant of Patent License. Subject to the terms and conditions of
82
- this License, each Contributor hereby grants to You a perpetual,
83
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
84
- (except as stated in this section) patent license to make, have made,
85
- use, offer to sell, sell, import, and otherwise transfer the Work,
86
- where such license applies only to those patent claims licensable
87
- by such Contributor that are necessarily infringed by their
88
- Contribution(s) alone or by combination of their Contribution(s)
89
- with the Work to which such Contribution(s) was submitted. If You
90
- institute patent litigation against any entity (including a
91
- cross-claim or counterclaim in a lawsuit) alleging that the Work
92
- or a Contribution incorporated within the Work constitutes direct
93
- or contributory patent infringement, then any patent licenses
94
- granted to You under this License for that Work shall terminate
95
- as of the date such litigation is filed.
96
-
97
- 4. Redistribution. You may reproduce and distribute copies of the
98
- Work or Derivative Works thereof in any medium, with or without
99
- modifications, and in Source or Object form, provided that You
100
- meet the following conditions:
101
-
102
- (a) You must give any other recipients of the Work or
103
- Derivative Works a copy of this License; and
104
-
105
- (b) You must cause any modified files to carry prominent notices
106
- stating that You changed the files; and
107
-
108
- (c) You must retain, in the Source form of any Derivative Works
109
- that You distribute, all copyright, patent, trademark, and
110
- attribution notices from the Source form of the Work,
111
- excluding those notices that do not pertain to any part of
112
- the Derivative Works; and
113
-
114
- (d) If the Work includes a "NOTICE" text file as part of its
115
- distribution, then any Derivative Works that You distribute must
116
- include a readable copy of the attribution notices contained
117
- within such NOTICE file, excluding those notices that do not
118
- pertain to any part of the Derivative Works, in at least one
119
- of the following places: within a NOTICE text file distributed
120
- as part of the Derivative Works; within the Source form or
121
- documentation, if provided along with the Derivative Works; or,
122
- within a display generated by the Derivative Works, if and
123
- wherever such third-party notices normally appear. The contents
124
- of the NOTICE file are for informational purposes only and
125
- do not modify the License. You may add Your own attribution
126
- notices within Derivative Works that You distribute, alongside
127
- or as an addendum to the NOTICE text from the Work, provided
128
- that such additional attribution notices cannot be construed
129
- as modifying the License.
130
-
131
- You may add Your own copyright statement to Your modifications and
132
- may provide additional or different license terms and conditions
133
- for use, reproduction, or distribution of Your modifications, or
134
- for any such Derivative Works as a whole, provided Your use,
135
- reproduction, and distribution of the Work otherwise complies with
136
- the conditions stated in this License.
137
-
138
- 5. Submission of Contributions. Unless You explicitly state otherwise,
139
- any Contribution intentionally submitted for inclusion in the Work
140
- by You to the Licensor shall be under the terms and conditions of
141
- this License, without any additional terms or conditions.
142
- Notwithstanding the above, nothing herein shall supersede or modify
143
- the terms of any separate license agreement you may have executed
144
- with Licensor regarding such Contributions.
145
-
146
- 6. Trademarks. This License does not grant permission to use the trade
147
- names, trademarks, service marks, or product names of the Licensor,
148
- except as required for reasonable and customary use in describing the
149
- origin of the Work and reproducing the content of the NOTICE file.
150
-
151
- 7. Disclaimer of Warranty. Unless required by applicable law or
152
- agreed to in writing, Licensor provides the Work (and each
153
- Contributor provides its Contributions) on an "AS IS" BASIS,
154
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
155
- implied, including, without limitation, any warranties or conditions
156
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
157
- PARTICULAR PURPOSE. You are solely responsible for determining the
158
- appropriateness of using or redistributing the Work and assume any
159
- risks associated with Your exercise of permissions under this License.
160
-
161
- 8. Limitation of Liability. In no event and under no legal theory,
162
- whether in tort (including negligence), contract, or otherwise,
163
- unless required by applicable law (such as deliberate and grossly
164
- negligent acts) or agreed to in writing, shall any Contributor be
165
- liable to You for damages, including any direct, indirect, special,
166
- incidental, or consequential damages of any character arising as a
167
- result of this License or out of the use or inability to use the
168
- Work (including but not limited to damages for loss of goodwill,
169
- work stoppage, computer failure or malfunction, or any and all
170
- other commercial damages or losses), even if such Contributor
171
- has been advised of the possibility of such damages.
172
-
173
- 9. Accepting Warranty or Additional Liability. While redistributing
174
- the Work or Derivative Works thereof, You may choose to offer,
175
- and charge a fee for, acceptance of support, warranty, indemnity,
176
- or other liability obligations and/or rights consistent with this
177
- License. However, in accepting such obligations, You may act only
178
- on Your own behalf and on Your sole responsibility, not on behalf
179
- of any other Contributor, and only if You agree to indemnify,
180
- defend, and hold each Contributor harmless for any liability
181
- incurred by, or claims asserted against, such Contributor by reason
182
- of your accepting any such warranty or additional liability.
183
-
184
- END OF TERMS AND CONDITIONS
185
-
186
- APPENDIX: How to apply the Apache License to your work.
187
-
188
- To apply the Apache License to your work, attach the following
189
- boilerplate notice, with the fields enclosed by brackets "[]"
190
- replaced with your own identifying information. (Don't include
191
- the brackets!) The text should be enclosed in the appropriate
192
- comment syntax for the file format. We also recommend that a
193
- file or class name and description of purpose be included on the
194
- same "printed page" as the copyright notice for easier
195
- identification within third-party archives.
196
-
197
- Copyright [yyyy] [name of copyright owner]
198
-
199
- Licensed under the Apache License, Version 2.0 (the "License");
200
- you may not use this file except in compliance with the License.
201
- You may obtain a copy of the License at
202
-
203
- http://www.apache.org/licenses/LICENSE-2.0
204
-
205
- Unless required by applicable law or agreed to in writing, software
206
- distributed under the License is distributed on an "AS IS" BASIS,
207
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
208
- See the License for the specific language governing permissions and
209
- limitations under the License.
1
+ Copyright 2025 Lily (cutelittlelily)
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
+ Apache License
10
+ Version 2.0, January 2004
11
+ http://www.apache.org/licenses/
12
+
13
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
14
+
15
+ 1. Definitions.
16
+
17
+ "License" shall mean the terms and conditions for use, reproduction,
18
+ and distribution as defined by Sections 1 through 9 of this document.
19
+
20
+ "Licensor" shall mean the copyright owner or entity authorized by
21
+ the copyright owner that is granting the License.
22
+
23
+ "Legal Entity" shall mean the union of the acting entity and all
24
+ other entities that control, are controlled by, or are under common
25
+ control with that entity. For the purposes of this definition,
26
+ "control" means (i) the power, direct or indirect, to cause the
27
+ direction or management of such entity, whether by contract or
28
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
29
+ outstanding shares, or (iii) beneficial ownership of such entity.
30
+
31
+ "You" (or "Your") shall mean an individual or Legal Entity
32
+ exercising permissions granted by this License.
33
+
34
+ "Source" form shall mean the preferred form for making modifications,
35
+ including but not limited to software source code, documentation
36
+ source, and configuration files.
37
+
38
+ "Object" form shall mean any form resulting from mechanical
39
+ transformation or translation of a Source form, including but
40
+ not limited to compiled object code, generated documentation,
41
+ and conversions to other media types.
42
+
43
+ "Work" shall mean the work of authorship, whether in Source or
44
+ Object form, made available under the License, as indicated by a
45
+ copyright notice that is included in or attached to the work
46
+ (an example is provided in the Appendix below).
47
+
48
+ "Derivative Works" shall mean any work, whether in Source or Object
49
+ form, that is based on (or derived from) the Work and for which the
50
+ editorial revisions, annotations, elaborations, or other modifications
51
+ represent, as a whole, an original work of authorship. For the purposes
52
+ of this License, Derivative Works shall not include works that remain
53
+ separable from, or merely link (or bind by name) to the interfaces of,
54
+ the Work and Derivative Works thereof.
55
+
56
+ "Contribution" shall mean any work of authorship, including
57
+ the original version of the Work and any modifications or additions
58
+ to that Work or Derivative Works thereof, that is intentionally
59
+ submitted to Licensor for inclusion in the Work by the copyright owner
60
+ or by an individual or Legal Entity authorized to submit on behalf of
61
+ the copyright owner. For the purposes of this definition, "submitted"
62
+ means any form of electronic, verbal, or written communication sent
63
+ to the Licensor or its representatives, including but not limited to
64
+ communication on electronic mailing lists, source code control systems,
65
+ and issue tracking systems that are managed by, or on behalf of, the
66
+ Licensor for the purpose of discussing and improving the Work, but
67
+ excluding communication that is conspicuously marked or otherwise
68
+ designated in writing by the copyright owner as "Not a Contribution."
69
+
70
+ "Contributor" shall mean Licensor and any individual or Legal Entity
71
+ on behalf of whom a Contribution has been received by Licensor and
72
+ subsequently incorporated within the Work.
73
+
74
+ 2. Grant of Copyright License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ copyright license to reproduce, prepare Derivative Works of,
78
+ publicly display, publicly perform, sublicense, and distribute the
79
+ Work and such Derivative Works in Source or Object form.
80
+
81
+ 3. Grant of Patent License. Subject to the terms and conditions of
82
+ this License, each Contributor hereby grants to You a perpetual,
83
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
84
+ (except as stated in this section) patent license to make, have made,
85
+ use, offer to sell, sell, import, and otherwise transfer the Work,
86
+ where such license applies only to those patent claims licensable
87
+ by such Contributor that are necessarily infringed by their
88
+ Contribution(s) alone or by combination of their Contribution(s)
89
+ with the Work to which such Contribution(s) was submitted. If You
90
+ institute patent litigation against any entity (including a
91
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
92
+ or a Contribution incorporated within the Work constitutes direct
93
+ or contributory patent infringement, then any patent licenses
94
+ granted to You under this License for that Work shall terminate
95
+ as of the date such litigation is filed.
96
+
97
+ 4. Redistribution. You may reproduce and distribute copies of the
98
+ Work or Derivative Works thereof in any medium, with or without
99
+ modifications, and in Source or Object form, provided that You
100
+ meet the following conditions:
101
+
102
+ (a) You must give any other recipients of the Work or
103
+ Derivative Works a copy of this License; and
104
+
105
+ (b) You must cause any modified files to carry prominent notices
106
+ stating that You changed the files; and
107
+
108
+ (c) You must retain, in the Source form of any Derivative Works
109
+ that You distribute, all copyright, patent, trademark, and
110
+ attribution notices from the Source form of the Work,
111
+ excluding those notices that do not pertain to any part of
112
+ the Derivative Works; and
113
+
114
+ (d) If the Work includes a "NOTICE" text file as part of its
115
+ distribution, then any Derivative Works that You distribute must
116
+ include a readable copy of the attribution notices contained
117
+ within such NOTICE file, excluding those notices that do not
118
+ pertain to any part of the Derivative Works, in at least one
119
+ of the following places: within a NOTICE text file distributed
120
+ as part of the Derivative Works; within the Source form or
121
+ documentation, if provided along with the Derivative Works; or,
122
+ within a display generated by the Derivative Works, if and
123
+ wherever such third-party notices normally appear. The contents
124
+ of the NOTICE file are for informational purposes only and
125
+ do not modify the License. You may add Your own attribution
126
+ notices within Derivative Works that You distribute, alongside
127
+ or as an addendum to the NOTICE text from the Work, provided
128
+ that such additional attribution notices cannot be construed
129
+ as modifying the License.
130
+
131
+ You may add Your own copyright statement to Your modifications and
132
+ may provide additional or different license terms and conditions
133
+ for use, reproduction, or distribution of Your modifications, or
134
+ for any such Derivative Works as a whole, provided Your use,
135
+ reproduction, and distribution of the Work otherwise complies with
136
+ the conditions stated in this License.
137
+
138
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
139
+ any Contribution intentionally submitted for inclusion in the Work
140
+ by You to the Licensor shall be under the terms and conditions of
141
+ this License, without any additional terms or conditions.
142
+ Notwithstanding the above, nothing herein shall supersede or modify
143
+ the terms of any separate license agreement you may have executed
144
+ with Licensor regarding such Contributions.
145
+
146
+ 6. Trademarks. This License does not grant permission to use the trade
147
+ names, trademarks, service marks, or product names of the Licensor,
148
+ except as required for reasonable and customary use in describing the
149
+ origin of the Work and reproducing the content of the NOTICE file.
150
+
151
+ 7. Disclaimer of Warranty. Unless required by applicable law or
152
+ agreed to in writing, Licensor provides the Work (and each
153
+ Contributor provides its Contributions) on an "AS IS" BASIS,
154
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
155
+ implied, including, without limitation, any warranties or conditions
156
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
157
+ PARTICULAR PURPOSE. You are solely responsible for determining the
158
+ appropriateness of using or redistributing the Work and assume any
159
+ risks associated with Your exercise of permissions under this License.
160
+
161
+ 8. Limitation of Liability. In no event and under no legal theory,
162
+ whether in tort (including negligence), contract, or otherwise,
163
+ unless required by applicable law (such as deliberate and grossly
164
+ negligent acts) or agreed to in writing, shall any Contributor be
165
+ liable to You for damages, including any direct, indirect, special,
166
+ incidental, or consequential damages of any character arising as a
167
+ result of this License or out of the use or inability to use the
168
+ Work (including but not limited to damages for loss of goodwill,
169
+ work stoppage, computer failure or malfunction, or any and all
170
+ other commercial damages or losses), even if such Contributor
171
+ has been advised of the possibility of such damages.
172
+
173
+ 9. Accepting Warranty or Additional Liability. While redistributing
174
+ the Work or Derivative Works thereof, You may choose to offer,
175
+ and charge a fee for, acceptance of support, warranty, indemnity,
176
+ or other liability obligations and/or rights consistent with this
177
+ License. However, in accepting such obligations, You may act only
178
+ on Your own behalf and on Your sole responsibility, not on behalf
179
+ of any other Contributor, and only if You agree to indemnify,
180
+ defend, and hold each Contributor harmless for any liability
181
+ incurred by, or claims asserted against, such Contributor by reason
182
+ of your accepting any such warranty or additional liability.
183
+
184
+ END OF TERMS AND CONDITIONS
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md CHANGED
@@ -8,12 +8,13 @@ Compression:
8
8
  - Lossless compression up to 70% or more (for example, 38kb -> 14kb)
9
9
  - Optimized bandwidth for many different types to fit special constraints
10
10
  - Automatic helpers to flatten typed nested arrays for maximum wire efficiency (for example, [[1,2,3],[4,5,6]] to [[1,4],[2,5],[3,6]])
11
- - Uses raw bytes to transmit data as efficiently as possible
11
+ - Uses raw binary bytes to transmit data as efficiently as possible while still using high level readable code
12
12
 
13
13
  Developer Friendly:
14
- - Predefined data types of various sized integers, decimals, strings, enums, etc. and RAW for any special cases
14
+ - 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
15
15
  - Keys are automatically indexed before transfer, improving readability and efficiency (for example, send("pixel") and send("p") use the same bandwidth)
16
16
  - Data is validated and supports custom validation, ensuring only valid, safe, and untampered packets ever call your listeners
17
+ - Edge cases are heavily tested with heavy data ranges; supports code points fully up to the max of 0x10FFFF
17
18
 
18
19
  Security:
19
20
  - Tamper-proof; any invalid packet instantly causes closure, and tampering becomes incredibly difficult
@@ -31,8 +32,9 @@ Developer Experience:
31
32
  - Minimal boilerplate code due to listeners only receiving valid data
32
33
  - Enums can map to any primitive value (e.g. number, string, boolean, null) and transmits in 1 byte
33
34
  - Timers and intervals for sockets that automatically clear upon closure
34
- - Many data types to bring speed, clarity, and security
35
+ - Many data types to maximize speed, clarity, bandwidth, and security
35
36
  - Debug tools for socket ids, byte size, data logging, etc. for troubleshooting
37
+ - Very minimal learning curve, easy to work in
36
38
  - JSDoc's for understanding
37
39
 
38
40
  Whether you're making a real-time game, a dashboard, a distributed system, or anything else, SonicWS gets you safe, structured packets, fast.
@@ -54,11 +56,11 @@ Browser (Client):
54
56
  ```js
55
57
  const wss = new SonicWSServer({
56
58
  clientPackets: [
57
- CreatePacket({tag: "pong", type: PacketType.INTS_D, dataMax: 1})
59
+ CreatePacket({tag: "pong", type: PacketType.UVARINT, dataMax: 1})
58
60
  ],
59
61
  serverPackets: [
60
- CreatePacket({tag: "ping", type: PacketType.INTS_D, dataMax: 1}),
61
- CreateObjPacket({tag: "data", types: [PacketType.INTS_A, PacketTypes.STRING], dataMaxes: [2, 3]})
62
+ CreatePacket({tag: "ping", type: PacketType.UVARINT, dataMax: 1}),
63
+ CreateObjPacket({tag: "data", types: [PacketType.UBYTES, PacketTypes.STRINGS], dataMaxes: [2, 3]})
62
64
  ],
63
65
  websocketOptions: { port: 1234 }
64
66
  });
@@ -69,10 +71,10 @@ wss.on_connect((socket) => {
69
71
 
70
72
  socket.on("pong", (num) => {
71
73
  console.log("Ponged!", num);
72
- socket.send("data", [Math.floor(Math.random() * 1000), Math.floor(Math.random() * 1000)], ["hello", "from", "server"]);
74
+ socket.send("data", [Math.floor(Math.random() * 26), Math.floor(Math.random() * 256)], ["hello", "from", "server"]);
73
75
  });
74
76
 
75
- setInterval(() => {
77
+ socket.setInterval(() => {
76
78
  socket.send("ping", Date.now());
77
79
  }, 10000);
78
80
 
@@ -107,8 +109,6 @@ ws.on_close((event) => {
107
109
 
108
110
  ## KNOWN ISSUES
109
111
 
110
- Batch rate limit is off by 1
111
-
112
112
  ## PLANNED FEATURES
113
113
 
114
- More data checking and better error handling
114
+ Better error handling
package/dist/index.d.ts CHANGED
File without changes
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright 2025 Lily (cutelittlelily)
3
+ * Copyright 2025 Lily (liwybloc)
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
package/dist/version.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  /** Current protocol version */
2
- export declare const VERSION = 9;
3
- /** Current protocol version as a character */
4
- export declare const VERSION_CHAR: string;
2
+ export declare const VERSION = 12;
3
+ /** Server data suffix */
4
+ export declare const SERVER_SUFFIX = "SWS";
5
+ /** Server data suffix in array */
6
+ export declare const SERVER_SUFFIX_NUMS: number[];
package/dist/version.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright 2025 Lily (cutelittlelily)
3
+ * Copyright 2025 Lily (liwybloc)
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -15,8 +15,11 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.VERSION_CHAR = exports.VERSION = void 0;
18
+ exports.SERVER_SUFFIX_NUMS = exports.SERVER_SUFFIX = exports.VERSION = void 0;
19
+ const StringUtil_1 = require("./ws/util/StringUtil");
19
20
  /** Current protocol version */
20
- exports.VERSION = 9;
21
- /** Current protocol version as a character */
22
- exports.VERSION_CHAR = String.fromCharCode(exports.VERSION);
21
+ exports.VERSION = 12;
22
+ /** Server data suffix */
23
+ exports.SERVER_SUFFIX = "SWS";
24
+ /** Server data suffix in array */
25
+ exports.SERVER_SUFFIX_NUMS = (0, StringUtil_1.processCharCodes)(exports.SERVER_SUFFIX);
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Holds shared connection values. Lets helper functions work on client and server.
3
+ */
4
+ export interface Connection {
5
+ /**
6
+ * List of timers, in object just for efficiency.
7
+ * For internal use only.
8
+ */
9
+ _timers: Record<number, number>;
10
+ /**
11
+ * Sets a timeout that will automatically end when the socket closes
12
+ * @param call The function to call
13
+ * @param time The time between now and the call (ms)
14
+ * @returns The timeout id to be used with socket.clearInterval(id)
15
+ */
16
+ setTimeout(call: () => void, time: number): number;
17
+ /**
18
+ * Sets an interval that will automatically end when the socket closes
19
+ * @param call The function to call
20
+ * @param time The time between calls (ms)
21
+ * @returns The interval id to be used with socket.clearInterval(id)
22
+ */
23
+ setInterval(call: () => void, time: number): number;
24
+ /**
25
+ * Clears a timeout/interval
26
+ * @param id The timeout id
27
+ */
28
+ clearTimeout(index: number): void;
29
+ /**
30
+ * Clears an interval
31
+ *
32
+ * Delegates to `clearTimeout`
33
+ * @param id The interval id
34
+ */
35
+ clearInterval(index: number): void;
36
+ /**
37
+ * Sends raw uint8array data through the connection
38
+ */
39
+ raw_send(data: Uint8Array): void;
40
+ /**
41
+ * Closes the connection
42
+ */
43
+ close(code?: number, reason?: string): void;
44
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright 2025 Lily (liwybloc)
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
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
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.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,6 @@
1
1
  import { PacketHolder } from '../../util/packets/PacketHolder';
2
- export declare abstract class SonicWSCore {
2
+ import { Connection } from '../../Connection';
3
+ export declare abstract class SonicWSCore implements Connection {
3
4
  /** Raw 'ws' library connection / webjs WebSocket class */
4
5
  socket: WebSocket;
5
6
  protected listeners: {
@@ -16,12 +17,12 @@ export declare abstract class SonicWSCore {
16
17
  protected serverPackets: PacketHolder;
17
18
  private pastKeys;
18
19
  private readyListeners;
19
- private keyHandler;
20
- private timers;
21
20
  private batcher;
22
21
  private bufferHandler;
23
22
  id: number;
23
+ _timers: Record<number, number>;
24
24
  constructor(ws: WebSocket, bufferHandler: (val: MessageEvent) => Promise<Uint8Array>);
25
+ private reading;
25
26
  private serverKeyHandler;
26
27
  private invalidPacket;
27
28
  private listenPacket;
@@ -32,10 +33,6 @@ export declare abstract class SonicWSCore {
32
33
  * @param listener Callback for when data is received
33
34
  */
34
35
  raw_onmessage(listener: (data: Uint8Array) => void): void;
35
- /**
36
- * Sends raw data
37
- */
38
- raw_send(data: Uint8Array): void;
39
36
  /**
40
37
  * Sends a packet to the server
41
38
  * @param tag The tag of the packet
@@ -58,16 +55,11 @@ export declare abstract class SonicWSCore {
58
55
  * @param listener The callback with the values
59
56
  */
60
57
  on(tag: string, listener: (value: any[]) => void): void;
61
- /**
62
- * Sets a timeout that will automatically end when the socket closes
63
- * @param call The function to call
64
- * @param time The time between now and the call (ms)
65
- */
58
+ raw_send(data: Uint8Array): void;
66
59
  setTimeout(call: () => void, time: number): number;
67
- /**
68
- * Sets an interval that will automatically end when the socket closes
69
- * @param call The function to call
70
- * @param time The time between calls (ms)
71
- */
72
60
  setInterval(call: () => void, time: number): number;
61
+ private setTimer;
62
+ clearTimeout(id: number): void;
63
+ clearInterval(id: number): void;
64
+ close(code?: number, reason?: string): void;
73
65
  }