sonic-ws 1.3.2 → 1.3.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 (46) hide show
  1. package/dist/index.d.ts +0 -4
  2. package/dist/version.d.ts +1 -5
  3. package/dist/version.js +23 -4
  4. package/dist/ws/Connection.d.ts +0 -4
  5. package/dist/ws/Connection.js +124 -4
  6. package/dist/ws/PacketProcessor.d.ts +0 -4
  7. package/dist/ws/PacketProcessor.js +50 -4
  8. package/dist/ws/client/core/ClientCore.d.ts +0 -4
  9. package/dist/ws/client/core/ClientCore.js +249 -4
  10. package/dist/ws/client/node/ClientNode.d.ts +0 -4
  11. package/dist/ws/client/node/ClientNode.js +34 -4
  12. package/dist/ws/debug/DebugServer.d.ts +0 -4
  13. package/dist/ws/debug/DebugServer.js +605 -4
  14. package/dist/ws/packets/PacketProcessors.d.ts +0 -4
  15. package/dist/ws/packets/PacketProcessors.js +315 -4
  16. package/dist/ws/packets/PacketType.d.ts +0 -4
  17. package/dist/ws/packets/PacketType.js +59 -4
  18. package/dist/ws/packets/Packets.d.ts +0 -4
  19. package/dist/ws/packets/Packets.js +275 -4
  20. package/dist/ws/server/SonicWSConnection.d.ts +0 -4
  21. package/dist/ws/server/SonicWSConnection.js +296 -4
  22. package/dist/ws/server/SonicWSServer.d.ts +1 -5
  23. package/dist/ws/server/SonicWSServer.js +305 -4
  24. package/dist/ws/util/BufferUtil.d.ts +0 -4
  25. package/dist/ws/util/BufferUtil.js +40 -4
  26. package/dist/ws/util/StringUtil.d.ts +0 -4
  27. package/dist/ws/util/StringUtil.js +49 -4
  28. package/dist/ws/util/enums/EnumHandler.d.ts +0 -4
  29. package/dist/ws/util/enums/EnumHandler.js +58 -4
  30. package/dist/ws/util/enums/EnumType.d.ts +0 -4
  31. package/dist/ws/util/enums/EnumType.js +70 -4
  32. package/dist/ws/util/packets/BatchHelper.d.ts +0 -4
  33. package/dist/ws/util/packets/BatchHelper.js +83 -4
  34. package/dist/ws/util/packets/CompressionUtil.d.ts +5 -9
  35. package/dist/ws/util/packets/CompressionUtil.js +275 -4
  36. package/dist/ws/util/packets/HashUtil.d.ts +0 -4
  37. package/dist/ws/util/packets/HashUtil.js +120 -4
  38. package/dist/ws/util/packets/JSONUtil.d.ts +0 -4
  39. package/dist/ws/util/packets/JSONUtil.js +177 -4
  40. package/dist/ws/util/packets/PacketHolder.d.ts +0 -4
  41. package/dist/ws/util/packets/PacketHolder.js +124 -4
  42. package/dist/ws/util/packets/PacketUtils.d.ts +0 -4
  43. package/dist/ws/util/packets/PacketUtils.js +281 -4
  44. package/dist/ws/util/packets/RateHandler.d.ts +0 -4
  45. package/dist/ws/util/packets/RateHandler.js +64 -4
  46. package/package.json +3 -3
@@ -1,6 +1,66 @@
1
- /**
1
+ "use strict";
2
+ /*
2
3
  * Copyright 2026 Lily (liwybloc)
3
- * Licensed under the Apache License, Version 2.0.
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.
4
16
  */
5
-
6
- Object.defineProperty(exports,"__esModule",{value:!0}),exports.RateHandler=void 0;const t=require("../../Connection");exports.RateHandler=class{rates={};limits={};setInterval;socket;constructor(t){this.setInterval=t.setInterval,this.socket=t.socket}start(){0!=Object.keys(this.rates).length&&this.setInterval(()=>{for(const t in this.rates)this.rates[t]=0},1e3)}registerRate(t,e){0!=e&&(this.rates[t]=0,this.limits[t]=e)}registerAll(t,e){const s=t.getPackets();for(const r of s)this.registerRate(e+t.getKey(r.tag),r.rateLimit)}trigger(e){return e in this.rates&&++this.rates[e]>this.limits[e]&&(this.socket.close(t.CloseCodes.RATELIMIT),!0)}subtract(t){t in this.rates&&this.rates[t]--}};
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.RateHandler = void 0;
19
+ const Connection_1 = require("../../Connection");
20
+ /** @internal */
21
+ class RateHandler {
22
+ rates = {};
23
+ limits = {};
24
+ setInterval;
25
+ socket;
26
+ constructor(host) {
27
+ // shared values
28
+ this.setInterval = host.setInterval;
29
+ this.socket = host.socket;
30
+ }
31
+ start() {
32
+ // no rates? don't start an interval
33
+ if (Object.keys(this.rates).length == 0)
34
+ return;
35
+ this.setInterval(() => {
36
+ for (const tag in this.rates) {
37
+ this.rates[tag] = 0;
38
+ }
39
+ }, 1000);
40
+ }
41
+ registerRate(tag, limit) {
42
+ // ignore no limits
43
+ if (limit == 0)
44
+ return;
45
+ this.rates[tag] = 0;
46
+ this.limits[tag] = limit;
47
+ }
48
+ registerAll(packetHolder, prefix) {
49
+ const packets = packetHolder.getPackets();
50
+ for (const packet of packets)
51
+ this.registerRate(prefix + packetHolder.getKey(packet.tag), packet.rateLimit);
52
+ }
53
+ trigger(tag) {
54
+ if (tag in this.rates && ++this.rates[tag] > this.limits[tag]) {
55
+ this.socket.close(Connection_1.CloseCodes.RATELIMIT);
56
+ return true;
57
+ }
58
+ return false;
59
+ }
60
+ subtract(tag) {
61
+ if (!(tag in this.rates))
62
+ return;
63
+ this.rates[tag]--;
64
+ }
65
+ }
66
+ exports.RateHandler = RateHandler;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sonic-ws",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Ultra-lightweight, high-performance, and bandwidth efficient websocket library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,10 +8,10 @@
8
8
  "webpack": "webpack --mode production",
9
9
  "build_web": "rimraf ./html && tsc --moduleResolution nodenext --module nodenext --outDir ./html src/ws/client/browser/ClientBrowser.ts && npm run webpack",
10
10
  "build_node": "rimraf ./dist && tsc -d",
11
- "build": "npm run build_node && npm run build_web && rimraf ./dist/ws/client/browser && rimraf ./dist/ws/debug/DebugClient.d.ts && rimraf ./dist/ws/debug/DebugClient.js && node minify",
11
+ "build": "npm run build_node && npm run build_web && rimraf ./dist/ws/client/browser && rimraf ./dist/ws/debug/DebugClient.d.ts && rimraf ./dist/ws/debug/DebugClient.js",
12
12
  "test_web": "npm run build && node test-site/server.mjs",
13
13
  "test_node": "npm run build_node && node test.mjs",
14
- "publish": "npm run build && cp ./bundled/SonicWS_bundle.js ./release/SonicWS_bundle.js"
14
+ "publish": "npm run build && node minify && cp ./bundled/SonicWS_bundle.js ./release/SonicWS_bundle.js && sleep 1"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",