You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**\*Blazor WebAssembly**: Requires `IJSRuntime` parameter in constructor. The SDK automatically uses browser-native implementations via JavaScript interop for both WebSocket and HTTP Stream transports.
54
+
**\*Blazor WebAssembly**: Requires `builder.Services.AddCentrifugeClient()`in `Program.cs`. The SDK automatically uses browser-native implementations via JavaScript interop for both WebSocket and HTTP Stream transports.
58
55
59
56
**Unity WebGL**: Requires a third-party WebSocket plugin. HTTP Stream is not supported in WebGL.
60
57
@@ -116,7 +113,8 @@ var result = await client.RpcAsync("method", data);
116
113
### Subscriptions
117
114
118
115
```csharp
119
-
// Create subscription, may throw Exception subscription already exists in Client's registry.
116
+
// Create subscription, may throw CentrifugeDuplicateSubscriptionException
117
+
// if subscription to the channel already exists in Client's registry.
// Client will try WebSocket first, then fall back to HTTP Stream if needed
261
261
client.Connect();
262
262
```
263
263
264
+
**Note**: In Blazor WebAssembly, ensure you've called `builder.Services.AddCentrifugeClient()` first (see Blazor Support section). The SDK will automatically use browser-native transports.
265
+
264
266
### Advanced Configuration
265
267
266
268
```csharp
@@ -273,7 +275,7 @@ var options = new CentrifugeClientOptions
// DisposeAsync waits for disconnect to complete before releasing resources
587
-
awaitClient.DisposeAsync();
572
+
if (_client!=null)
573
+
{
574
+
await_client.DisposeAsync();
575
+
}
588
576
}
589
577
}
590
578
```
591
579
592
-
**Important**: The JavaScript interop file is automatically included as a static asset. If you encounter module loading issues, ensure your `index.html` has the standard Blazor script tag:
580
+
**How it works:**
581
+
582
+
- The SDK automatically uses browser-native transports when `AddCentrifugeClient()` is called
583
+
- WebSocket uses browser's native WebSocket via JS interop
584
+
- HTTP Stream uses browser's Fetch API with ReadableStream
585
+
- No need to pass `IJSRuntime` to constructors - it's configured globally
586
+
587
+
**Important**: The JavaScript interop modules are automatically included as static assets. Ensure your `index.html` has the standard Blazor script tag:
Copy file name to clipboardExpand all lines: examples/Centrifugal.Centrifuge.BlazorExample/README.md
+8-3Lines changed: 8 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -68,12 +68,17 @@ The example uses the Centrifuge SDK's browser-native transports:
68
68
-**WebSocket**: Uses browser's native WebSocket via JavaScript interop (`BrowserWebSocketTransport`)
69
69
-**HTTP Stream**: Uses browser's Fetch API with ReadableStream (`BrowserHttpStreamTransport`)
70
70
71
-
The `CentrifugeClient` is registered as a scoped service in `Program.cs` with `IJSRuntime` dependency injection, enabling it to use JavaScript interop for browser APIs.
71
+
The SDK uses a simple DI-based configuration approach:
72
+
73
+
1. Call `builder.Services.AddCentrifugeClient()` in `Program.cs`
74
+
2. Create `CentrifugeClient` instances anywhere in your app without passing `IJSRuntime`
75
+
76
+
This follows standard .NET conventions, just like SignalR's `AddSignalR()` - configure once, use everywhere!
72
77
73
78
## Code Structure
74
79
75
-
-**Program.cs**: Registers `CentrifugeClient` as a scoped service with IJSRuntime
76
-
-**Pages/Home.razor**: Main example component that connects, subscribes, and logs all events
80
+
-**Program.cs**: Registers Centrifuge with `AddCentrifugeClient()`
81
+
-**Pages/Home.razor**: Creates client directly and logs all events
77
82
- All SDK events are logged both to browser console and displayed in the UI
0 commit comments