wse-client 1.4.1 → 1.4.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.
package/README.md CHANGED
@@ -33,17 +33,28 @@ Embed WSE into your existing FastAPI app on the same port:
33
33
  ```python
34
34
  from fastapi import FastAPI
35
35
  from wse_server import create_wse_router, WSEConfig
36
+ import redis.asyncio as redis
36
37
 
37
38
  app = FastAPI()
38
39
 
40
+ redis_client = redis.Redis(host="localhost", port=6379, decode_responses=False)
41
+
39
42
  wse = create_wse_router(WSEConfig(
40
- redis_url="redis://localhost:6379",
43
+ redis_client=redis_client,
41
44
  ))
42
45
 
43
46
  app.include_router(wse, prefix="/wse")
47
+ ```
48
+
49
+ Publish events from anywhere in your app via the PubSub bus:
50
+
51
+ ```python
52
+ bus = app.state.pubsub_bus
44
53
 
45
- # Publish from anywhere in your app
46
- await wse.publish("notifications", {"text": "Order shipped!", "order_id": 42})
54
+ await bus.publish(
55
+ topic="notifications",
56
+ event={"event_type": "order_shipped", "order_id": 42, "text": "Order shipped!"},
57
+ )
47
58
  ```
48
59
 
49
60
  ### Server (Python) -- Standalone Mode
@@ -279,14 +290,69 @@ See benchmark docs for full results: [Overview](docs/BENCHMARKS.md) | [Rust Clie
279
290
 
280
291
  ## Use Cases
281
292
 
282
- WSE works for any real-time communication between frontend and backend:
293
+ ### Live Dashboards
294
+
295
+ Push price updates, sensor data, or analytics to the browser in real time.
296
+
297
+ ```python
298
+ # Server: push price updates
299
+ await bus.publish(
300
+ topic="prices",
301
+ event={"event_type": "price_update", "symbol": "AAPL", "price": 187.42},
302
+ )
303
+ ```
304
+
305
+ ```tsx
306
+ // React: consume them
307
+ window.addEventListener('price_update', (e: CustomEvent) => {
308
+ updateChart(e.detail.symbol, e.detail.price);
309
+ });
310
+ ```
311
+
312
+ ### Notifications
313
+
314
+ Push order updates, alerts, or system events to specific users.
315
+
316
+ ```python
317
+ # Server: notify a specific user
318
+ await bus.publish(
319
+ topic=f"user:{user_id}:events",
320
+ event={"event_type": "order_shipped", "order_id": 42, "text": "Your order shipped!"},
321
+ )
322
+ ```
323
+
324
+ ```tsx
325
+ // React: show a toast
326
+ window.addEventListener('order_shipped', (e: CustomEvent) => {
327
+ showToast(e.detail.text);
328
+ });
329
+ ```
330
+
331
+ ### Chat and Messaging
332
+
333
+ Group chats, DMs, typing indicators, read receipts. Enable encryption for privacy.
334
+
335
+ ```python
336
+ # Server: broadcast a chat message
337
+ await bus.publish(
338
+ topic=f"chat:{channel_id}",
339
+ event={"event_type": "message_sent", "text": body.text, "author": user.name},
340
+ )
341
+ ```
342
+
343
+ ```python
344
+ # Python client: listen for messages
345
+ async with connect("ws://localhost:5006/wse", token=jwt) as client:
346
+ await client.subscribe([f"chat:{channel_id}"])
347
+ async for event in client:
348
+ print(f"{event.payload['author']}: {event.payload['text']}")
349
+ ```
350
+
351
+ ### Other Use Cases
283
352
 
284
- - **Live dashboards** -- stock prices, sensor data, analytics, monitoring panels
285
- - **Notifications** -- order updates, alerts, system events pushed to the browser
286
- - **Collaborative apps** -- shared cursors, document editing, whiteboarding
287
- - **Chat and messaging** -- group chats, DMs, typing indicators, read receipts
288
- - **IoT and telemetry** -- device status, real-time metrics, command and control
289
- - **Gaming** -- game state sync, leaderboards, matchmaking updates
353
+ - **Collaborative editing** -- shared cursors, document changes, conflict detection via sequence numbers
354
+ - **IoT and telemetry** -- device status, sensor metrics, command and control. Use LOW priority for telemetry, HIGH for alerts
355
+ - **Gaming** -- game state sync, leaderboards, matchmaking. Use msgpack binary protocol for lower latency
290
356
 
291
357
  ---
292
358
 
@@ -1,5 +1,5 @@
1
1
  export declare const WS_PROTOCOL_VERSION = 1;
2
- export declare const WS_CLIENT_VERSION = "1.4.1";
2
+ export declare const WS_CLIENT_VERSION = "1.4.3";
3
3
  export declare const HEARTBEAT_INTERVAL = 15000;
4
4
  export declare const IDLE_TIMEOUT = 40000;
5
5
  export declare const CONNECTION_TIMEOUT = 10000;
package/dist/constants.js CHANGED
@@ -5,7 +5,7 @@
5
5
  // Protocol Constants
6
6
  // ---------------------------------------------------------------------------
7
7
  export const WS_PROTOCOL_VERSION = 1;
8
- export const WS_CLIENT_VERSION = '1.4.1';
8
+ export const WS_CLIENT_VERSION = '1.4.3';
9
9
  // ---------------------------------------------------------------------------
10
10
  // Connection Constants
11
11
  // ---------------------------------------------------------------------------
package/dist/index.d.ts CHANGED
@@ -21,5 +21,5 @@ export type { OfflineQueueConfig } from './services/OfflineQueue';
21
21
  export { EventHandlers } from './handlers/EventHandlers';
22
22
  export { registerAllHandlers } from './handlers/index';
23
23
  export * from './constants';
24
- export declare const WSE_VERSION = "1.4.1";
24
+ export declare const WSE_VERSION = "1.4.3";
25
25
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -44,5 +44,5 @@ export * from './constants';
44
44
  // ---------------------------------------------------------------------------
45
45
  // Version Info
46
46
  // ---------------------------------------------------------------------------
47
- export const WSE_VERSION = '1.4.1';
47
+ export const WSE_VERSION = '1.4.3';
48
48
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wse-client",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
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",