Blazor Extensions is a set of packages with the goal of adding useful features to Blazor.
This package adds a Microsoft ASP.NET Core SignalR client library for Microsoft ASP.NET Blazor.
The package aims to mimic the C# APIs of SignalR Client as much as possible and it is developed by wrapping the TypeScript client by using Blazor's interop capabilities.
For more information about SignalR development, please check SignalR documentation.
This package implements all public features of SignalR Typescript client.
Note: The Streaming APIs are not implemented yet. We will add it soon.
The following snippet shows how to setup the client to send and receive messages using SignalR.
var connection = new HubConnectionBuilder()
.WithUrl("/myHub", // The hub URL. If the Hub is hosted on the server where the blazor is hosted, you can just use the relative path.
opt =>
{
opt.LogLevel = SignalRLogLevel.Trace; // Client log level
opt.Transport = HttpTransportType.WebSockets; // Which transport you want to use for this connection
})
.Build(); // Build the HubConnection
connection.On("Receive", this.Handle); // Subscribe to messages sent from the Hub to the "Receive" method by passing a handle (Func<object, Task>) to process messages.
await connection.StartAsync(); // Start the connection.
await connection.InvokeAsync("ServerMethod", param1, param2, paramX); // Invoke a method on the server called "ServerMethod" and pass parameters to it.
var result = await connection.InvokeAsync<MyResult>("ServerMethod", param1, param2, paramX); // Invoke a method on the server called "ServerMethod", pass parameters to it and get the result back.
Please feel free to use the component, open issues, fix bugs or provide feedback.
The following people are the maintainers of the Blazor Extensions projects: