wse-client 1.2.0 → 1.2.2

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 (2) hide show
  1. package/README.md +34 -5
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -25,7 +25,9 @@ The engine is Rust-accelerated via PyO3. Up to **2M msg/s** sustained throughput
25
25
 
26
26
  ## Quick Start
27
27
 
28
- ### Server (Python)
28
+ ### Server (Python) -- Router Mode
29
+
30
+ Embed WSE into your existing FastAPI app on the same port:
29
31
 
30
32
  ```python
31
33
  from fastapi import FastAPI
@@ -43,6 +45,31 @@ app.include_router(wse, prefix="/wse")
43
45
  await wse.publish("notifications", {"text": "Order shipped!", "order_id": 42})
44
46
  ```
45
47
 
48
+ ### Server (Python) -- Standalone Mode
49
+
50
+ Run the Rust WebSocket server on a dedicated port for maximum throughput:
51
+
52
+ ```python
53
+ from wse_server._wse_accel import RustWSEServer
54
+
55
+ server = RustWSEServer(
56
+ "0.0.0.0", 5006,
57
+ max_connections=10000,
58
+ jwt_secret=b"your-secret-key", # Rust JWT validation in handshake
59
+ jwt_issuer="your-app",
60
+ jwt_audience="your-api",
61
+ )
62
+ server.start()
63
+
64
+ # Drain inbound events in a background thread
65
+ while True:
66
+ events = server.drain_inbound(256, 50) # batch size, timeout ms
67
+ for event in events:
68
+ handle(event)
69
+ ```
70
+
71
+ Standalone mode gives you a dedicated Rust tokio runtime on its own port -- no FastAPI overhead, no GIL on the hot path. This is how WSE achieves 2M msg/s.
72
+
46
73
  ### Client (React)
47
74
 
48
75
  ```tsx
@@ -124,7 +151,7 @@ Compression, sequencing, filtering, rate limiting, and the WebSocket server itse
124
151
  | **Compression** | Flate2 zlib with configurable levels (1-9). Adaptive threshold -- only compress when payload exceeds size limit. Binary mode via msgpack (rmp-serde) for 30% smaller payloads. |
125
152
  | **Rate Limiter** | Atomic token-bucket rate limiter in Rust. Per-connection rate enforcement. 100K tokens capacity, 10K tokens/sec refill. |
126
153
  | **Message Deduplication** | AHashSet-backed dedup with bounded queue. Prevents duplicate delivery across reconnections and Redis fan-out. |
127
- | **Wire Envelope** | Protocol v2: `{t, id, ts, seq, p, v}`. Generic payload extraction with automatic type conversion (UUID, datetime, Enum, bytes to JSON-safe primitives). Latency tracking (`latency_ms` field). |
154
+ | **Wire Envelope** | Protocol v1: `{t, id, ts, seq, p, v}`. Generic payload extraction with automatic type conversion (UUID, datetime, Enum, bytes to JSON-safe primitives). Latency tracking (`latency_ms` field). |
128
155
  | **Snapshot Provider** | Protocol for initial state delivery. Implement `get_snapshot(user_id, topics)` and clients receive current state immediately on subscribe -- no waiting for the next publish cycle. |
129
156
  | **Circuit Breaker** | Three-state machine (CLOSED / OPEN / HALF_OPEN). Sliding-window failure tracking. Automatic recovery probes. Prevents cascade failures when downstream services are unhealthy. |
130
157
  | **Message Categories** | `S` (snapshot), `U` (update), `WSE` (system). Category prefixing for client-side routing and filtering. |
@@ -217,9 +244,11 @@ Client (React + TypeScript) Server (Python + Rust)
217
244
  ======================== ========================
218
245
 
219
246
  useWSE hook FastAPI Router (/wse)
220
- | |
221
- v v
222
- ConnectionPool Rust Engine (PyO3)
247
+ | -- OR --
248
+ v RustWSEServer (standalone :5006)
249
+ ConnectionPool |
250
+ | (multi-endpoint, v
251
+ | health scoring) Rust Engine (PyO3)
223
252
  | (multi-endpoint, | (drain mode,
224
253
  | health scoring) | write coalescing)
225
254
  v v
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wse-client",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "WSE (WebSocket Engine) React client. Type-safe hooks, auto-reconnect, offline queue, E2E encryption.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",