JsonHCS.Net.Proxies.SignalR 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package JsonHCS.Net.Proxies.SignalR --version 1.0.0                
NuGet\Install-Package JsonHCS.Net.Proxies.SignalR -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JsonHCS.Net.Proxies.SignalR" Version="1.0.0" />                
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.0.0                
#r "nuget: JsonHCS.Net.Proxies.SignalR, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. 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.0.0

// Install JsonHCS.Net.Proxies.SignalR as a Cake Tool
#tool nuget:?package=JsonHCS.Net.Proxies.SignalR&version=1.0.0                

JsonHCS.Net.Proxies.SignalR

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

NuGet version (JsonHCS.Net.Proxies)

This plugin is currently experimental and might contain numerous bugs!

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.

A more complete sample can be found in the source.

Issues

Found an issue? Submit an issue!

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
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.3 114 8/26/2024
1.1.2 101 8/7/2024
1.1.1 498 11/10/2020
1.1.0 473 2/17/2020
1.0.2 505 10/21/2019
1.0.1 487 10/17/2019
1.0.0 484 10/15/2019

- Initial release