JsonHCS.Net.Proxies.SignalR 1.1.1

.NET Standard 2.0
Install-Package JsonHCS.Net.Proxies.SignalR -Version 1.1.1
dotnet add package JsonHCS.Net.Proxies.SignalR --version 1.1.1
<PackageReference Include="JsonHCS.Net.Proxies.SignalR" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonHCS.Net.Proxies.SignalR --version 1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JsonHCS.Net.Proxies.SignalR, 1.1.1"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install JsonHCS.Net.Proxies.SignalR as a Cake Addin
#addin nuget:?package=JsonHCS.Net.Proxies.SignalR&version=1.1.1

// Install JsonHCS.Net.Proxies.SignalR as a Cake Tool
#tool nuget:?package=JsonHCS.Net.Proxies.SignalR&version=1.1.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

JsonHCS.Net.Proxies.SignalR

A simple JsonHCS.Net.Proxies plugin with strongly typed SignalR hub support.

NuGet version (JsonHCS.Net.Proxies)

Support

Supported platforms: .Net Standard 2.0+

Simple usage

  • Include the plugin from NuGet

  • Add the plugin to the proxy generator and construct the api

JsonHCSProxyGenerator pg = new JsonHCSProxyGenerator(null, new SignalRPlugin(), new BasicPlugin());
var api = pg.CreateClassProxy<API>("http://localhost:5000/");
  • Include the plugin declaration in the API object with any or multiple of its usages:
    public abstract class API
    {
        //Connect with strongly typed methods and Events
        [Route("hub")]
        public abstract Task<HubConnection<Client, Events>> Connect();

        //Connect a plain HubConnection like normal SignalR
        [Route("hub")]
        public abstract Task<HubConnection> ConnectPlain();

        //Connects and call the specified method
        //implied: [HubMethod("Broadcast", SendType.Invoke)]
        [HubMethod]
        public abstract Task Broadcast(string text);
    }

    public interface Client
    {
        //Calls his method on the Hub, can be a shared interface to prevent mistakes!
        Task Broadcast(string text);
    }

    public interface Events
    {
        //Triggers when "Receive" gets called from the Hub
        event Func<string, Task> Receive;

        //System.Reactive compatible IObservable gets updated when Receive gets called
        //Only supports single argument calls for obvious reasons
        [HubMethod("Receive")]
        IObservable<string> Message { get; }
    }
  • Usage of HubConnection<,>:
var api = pg.CreateClassProxy<API>("http://localhost:5000/");

//Connects to the hub
var hub = await api.Connect();

//Use hub.On for events/observables
hub.On.Receive += ...;
var subscription = hub.On.Message.Subscribe(s => Console.WriteLine($"{DateTime.Now.TimeOfDay}: Subscription was updated to: {s}")));

//Use hub.Send or hub.Invoke to Send/Invoke to the hub
await hub.Send.Broadcast("Test 1");
Console.WriteLine($"{DateTime.Now.TimeOfDay}: Sending Test 2");
await hub.Send.Broadcast("Test 2");
Console.WriteLine($"{DateTime.Now.TimeOfDay}: Sending Test 3");
await hub.Send.Broadcast("Test 3");

Note: Any connection created will get cached and reused on multiple calls to prevent reconnecting.

A more complete sample can be found in the source.

Issues

Found an issue? Submit an issue!

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.1 273 11/10/2020
1.1.0 287 2/17/2020
1.0.2 312 10/21/2019
1.0.1 306 10/17/2019
1.0.0 296 10/15/2019

- Updated dependencies