@djangocfg/centrifugo 2.1.52 → 2.1.54
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 +50 -0
- package/package.json +5 -5
- package/src/core/client/CentrifugoRPCClient.ts +30 -0
package/README.md
CHANGED
|
@@ -443,6 +443,56 @@ interface UseNamedRPCResult {
|
|
|
443
443
|
|
|
444
444
|
> **Note:** `useNamedRPC` uses native Centrifugo RPC which requires RPC proxy to be configured in Centrifugo server. See the [Setup Guide](https://djangocfg.com/docs/features/integrations/centrifugo/client-generation/) for configuration details.
|
|
445
445
|
|
|
446
|
+
### namedRPCNoWait() - Fire-and-Forget RPC
|
|
447
|
+
|
|
448
|
+
For latency-sensitive operations (like terminal input), use the fire-and-forget variant that returns immediately without waiting for a response.
|
|
449
|
+
|
|
450
|
+
**When to use:**
|
|
451
|
+
- Terminal input (user typing)
|
|
452
|
+
- Real-time cursor position updates
|
|
453
|
+
- Any operation where you don't need the response
|
|
454
|
+
|
|
455
|
+
**Direct Client Usage:**
|
|
456
|
+
|
|
457
|
+
```tsx
|
|
458
|
+
import { useCentrifugo } from '@djangocfg/centrifugo';
|
|
459
|
+
|
|
460
|
+
function TerminalInput() {
|
|
461
|
+
const { client } = useCentrifugo();
|
|
462
|
+
|
|
463
|
+
const handleKeyPress = (key: string) => {
|
|
464
|
+
// Fire-and-forget: returns immediately, doesn't wait for response
|
|
465
|
+
client?.namedRPCNoWait('terminal.input', {
|
|
466
|
+
session_id: 'abc-123',
|
|
467
|
+
data: btoa(key)
|
|
468
|
+
});
|
|
469
|
+
};
|
|
470
|
+
|
|
471
|
+
return <input onKeyPress={(e) => handleKeyPress(e.key)} />;
|
|
472
|
+
}
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
**Backend Handler (Django):**
|
|
476
|
+
|
|
477
|
+
```python
|
|
478
|
+
@websocket_rpc("terminal.input", no_wait=True)
|
|
479
|
+
async def terminal_input(conn, params: TerminalInputParams) -> SuccessResult:
|
|
480
|
+
"""Handle terminal input (fire-and-forget)."""
|
|
481
|
+
import asyncio
|
|
482
|
+
|
|
483
|
+
# Spawn background task, return immediately
|
|
484
|
+
asyncio.create_task(_send_input_to_agent(params.session_id, params.data))
|
|
485
|
+
|
|
486
|
+
return SuccessResult(success=True, message="Input queued")
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
**Performance comparison:**
|
|
490
|
+
|
|
491
|
+
| Method | Latency | Use Case |
|
|
492
|
+
|--------|---------|----------|
|
|
493
|
+
| `namedRPC()` | ~800-1800ms | Commands that need response |
|
|
494
|
+
| `namedRPCNoWait()` | ~10-30ms | Real-time input, fire-and-forget |
|
|
495
|
+
|
|
446
496
|
## Auto-Generated Type-Safe Clients
|
|
447
497
|
|
|
448
498
|
Django-CFG can auto-generate TypeScript clients from your `@websocket_rpc` handlers, providing full type safety and eliminating manual RPC calls.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/centrifugo",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.54",
|
|
4
4
|
"description": "Production-ready Centrifugo WebSocket client for React with real-time subscriptions, RPC patterns, and connection state management",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"centrifugo",
|
|
@@ -51,9 +51,9 @@
|
|
|
51
51
|
"centrifuge": "^5.2.2"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
|
-
"@djangocfg/api": "^2.1.
|
|
55
|
-
"@djangocfg/ui-nextjs": "^2.1.
|
|
56
|
-
"@djangocfg/layouts": "^2.1.
|
|
54
|
+
"@djangocfg/api": "^2.1.54",
|
|
55
|
+
"@djangocfg/ui-nextjs": "^2.1.54",
|
|
56
|
+
"@djangocfg/layouts": "^2.1.54",
|
|
57
57
|
"consola": "^3.4.2",
|
|
58
58
|
"lucide-react": "^0.545.0",
|
|
59
59
|
"moment": "^2.30.1",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"react-dom": "^19.1.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
64
|
+
"@djangocfg/typescript-config": "^2.1.54",
|
|
65
65
|
"@types/react": "^19.1.0",
|
|
66
66
|
"@types/react-dom": "^19.1.0",
|
|
67
67
|
"moment": "^2.30.1",
|
|
@@ -604,4 +604,34 @@ export class CentrifugoRPCClient {
|
|
|
604
604
|
throw error;
|
|
605
605
|
}
|
|
606
606
|
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Fire-and-forget RPC call - sends without waiting for response.
|
|
610
|
+
* Use for latency-sensitive operations like terminal input.
|
|
611
|
+
*
|
|
612
|
+
* Flow:
|
|
613
|
+
* 1. Client calls namedRPCNoWait('terminal.input', data)
|
|
614
|
+
* 2. Centrifuge.js sends RPC over WebSocket
|
|
615
|
+
* 3. Client returns immediately (doesn't wait for response)
|
|
616
|
+
* 4. Backend processes asynchronously
|
|
617
|
+
*
|
|
618
|
+
* @param method - RPC method name (e.g., 'terminal.input')
|
|
619
|
+
* @param data - Request data
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* // Terminal input - user types, we send immediately
|
|
623
|
+
* client.namedRPCNoWait('terminal.input', {
|
|
624
|
+
* session_id: 'abc-123',
|
|
625
|
+
* data: btoa('ls')
|
|
626
|
+
* });
|
|
627
|
+
*/
|
|
628
|
+
namedRPCNoWait<TRequest = any>(method: string, data: TRequest): void {
|
|
629
|
+
this.logger.info(`Native RPC (fire-and-forget): ${method}`, { data });
|
|
630
|
+
|
|
631
|
+
// Fire and forget - don't await the promise
|
|
632
|
+
this.centrifuge.rpc(method, data).catch((error) => {
|
|
633
|
+
// Log but don't throw - this is fire-and-forget
|
|
634
|
+
this.logger.warning(`Fire-and-forget RPC failed: ${method}`, error);
|
|
635
|
+
});
|
|
636
|
+
}
|
|
607
637
|
}
|