|
1 | | -[](https://dotnet-ci.visualstudio.com/DotnetCI/_build/latest?definitionId=5&branch=master) |
2 | | -[](https://www.nuget.org/packages/Blazor.Extensions.SignalR) |
3 | | -[](https://www.nuget.org/packages/Blazor.Extensions.SignalR) |
4 | | -[](https://github.com/BlazorExtensions/SignalR/blob/master/LICENSE) |
5 | | - |
6 | | -# Blazor Extensions |
7 | | - |
8 | | -Blazor Extensions is a set of packages with the goal of adding useful features to [Blazor](https://blazor.net). |
9 | | - |
10 | | -# Blazor Extensions SignalR |
11 | | - |
12 | | -This package adds a [Microsoft ASP.NET Core SignalR](https://github.com/aspnet/SignalR) client library for [Microsoft ASP.NET Blazor](https://github.com/aspnet/Blazor). |
13 | | - |
14 | | -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. |
15 | | - |
16 | | -For more information about SignalR development, please check [SignalR documentation](https://docs.microsoft.com/en-us/aspnet/core/signalr/introduction?view=aspnetcore-2.1). |
17 | | - |
18 | | -# Features |
19 | | - |
20 | | -This package implements all public features of SignalR Typescript client. |
21 | | - |
22 | | -> Note: The _Streaming_ APIs are not implemented yet. We will add it soon. |
23 | | -
|
24 | | -# Sample usage |
25 | | - |
26 | | -The following snippet shows how to setup the client to send and receive messages using SignalR. |
27 | | - |
28 | | -The HubConnectionBuilder needs to get injected, which must be registered: |
29 | | -```c# |
30 | | -// in Startup.cs, ConfigureServices() |
31 | | - services.AddTransient<HubConnectionBuilder>(); |
32 | | -``` |
33 | | -```c# |
34 | | -// in Component class |
35 | | -[Inject] |
36 | | -private HubConnectionBuilder _hubConnectionBuilder { get; set; } |
37 | | -``` |
38 | | -```c# |
39 | | -// in Component Initialization code |
40 | | -var connection = _hubConnectionBuilder // the injected one from above. |
41 | | - .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. |
42 | | - opt => |
43 | | - { |
44 | | - opt.LogLevel = SignalRLogLevel.Trace; // Client log level |
45 | | - opt.Transport = HttpTransportType.WebSockets; // Which transport you want to use for this connection |
46 | | - }) |
47 | | - .Build(); // Build the HubConnection |
48 | | -
|
49 | | -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. |
50 | | -await connection.StartAsync(); // Start the connection. |
51 | | -
|
52 | | -await connection.InvokeAsync("ServerMethod", param1, param2, paramX); // Invoke a method on the server called "ServerMethod" and pass parameters to it. |
53 | | -
|
54 | | -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. |
55 | | -``` |
56 | | - |
57 | | -# Contributions and feedback |
58 | | - |
59 | | -Please feel free to use the component, open issues, fix bugs or provide feedback. |
60 | | - |
61 | | -# Contributors |
62 | | - |
63 | | -The following people are the maintainers of the Blazor Extensions projects: |
64 | | - |
65 | | -- [Attila Hajdrik](https://github.com/attilah) |
66 | | -- [Gutemberg Ribiero](https://github.com/galvesribeiro) |
| 1 | +[](https://github.com/BlazorExtensions/SignalR/actions) |
| 2 | +[](https://www.nuget.org/packages/Blazor.Extensions.SignalR) |
| 3 | +[](https://www.nuget.org/packages/Blazor.Extensions.SignalR) |
| 4 | +[](https://github.com/BlazorExtensions/SignalR/blob/master/LICENSE) |
| 5 | + |
| 6 | +# Blazor Extensions |
| 7 | + |
| 8 | +Blazor Extensions is a set of packages with the goal of adding useful features to [Blazor](https://blazor.net). |
| 9 | + |
| 10 | +# Blazor Extensions SignalR |
| 11 | + |
| 12 | +This package adds a [Microsoft ASP.NET Core SignalR](https://github.com/aspnet/SignalR) client library for [Microsoft ASP.NET Blazor](https://github.com/aspnet/Blazor). |
| 13 | + |
| 14 | +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. |
| 15 | + |
| 16 | +For more information about SignalR development, please check [SignalR documentation](https://docs.microsoft.com/en-us/aspnet/core/signalr/introduction?view=aspnetcore-2.1). |
| 17 | + |
| 18 | +# Features |
| 19 | + |
| 20 | +This package implements all public features of SignalR Typescript client. |
| 21 | + |
| 22 | +> Note: The _Streaming_ APIs are not implemented yet. We will add it soon. |
| 23 | +
|
| 24 | +# Sample usage |
| 25 | + |
| 26 | +The following snippet shows how to setup the client to send and receive messages using SignalR. |
| 27 | + |
| 28 | +The HubConnectionBuilder needs to get injected, which must be registered: |
| 29 | +```c# |
| 30 | +// in Startup.cs, ConfigureServices() |
| 31 | + services.AddTransient<HubConnectionBuilder>(); |
| 32 | +``` |
| 33 | +```c# |
| 34 | +// in Component class |
| 35 | +[Inject] |
| 36 | +private HubConnectionBuilder _hubConnectionBuilder { get; set; } |
| 37 | +``` |
| 38 | +```c# |
| 39 | +// in Component Initialization code |
| 40 | +var connection = _hubConnectionBuilder // the injected one from above. |
| 41 | + .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. |
| 42 | + opt => |
| 43 | + { |
| 44 | + opt.LogLevel = SignalRLogLevel.Trace; // Client log level |
| 45 | + opt.Transport = HttpTransportType.WebSockets; // Which transport you want to use for this connection |
| 46 | + }) |
| 47 | + .Build(); // Build the HubConnection |
| 48 | +
|
| 49 | +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. |
| 50 | +await connection.StartAsync(); // Start the connection. |
| 51 | +
|
| 52 | +await connection.InvokeAsync("ServerMethod", param1, param2, paramX); // Invoke a method on the server called "ServerMethod" and pass parameters to it. |
| 53 | +
|
| 54 | +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. |
| 55 | +``` |
| 56 | + |
| 57 | +# Contributions and feedback |
| 58 | + |
| 59 | +Please feel free to use the component, open issues, fix bugs or provide feedback. |
| 60 | + |
| 61 | +# Contributors |
| 62 | + |
| 63 | +The following people are the maintainers of the Blazor Extensions projects: |
| 64 | + |
| 65 | +- [Attila Hajdrik](https://github.com/attilah) |
| 66 | +- [Gutemberg Ribiero](https://github.com/galvesribeiro) |
0 commit comments