Add SignalR client functionality to a Fable.Elmish application

82 views Asked by At

I found 2 resources from the community

1.Fable.SignalR - A functional type-safe wrapper for SignalR and Fable. I am using Elmish so the package is Fable.SignalR.Elmish

2.fable-signalr - Fable bindings for SignalR

2 Is declared to work only before Fable 3, which is not my case.

With 1 I have a problem: I do not control the server side. The server application is a standard C# ASP.NET core Web Api application that uses SignalR. All the examples I found for 1 require a shared F# library, which cannot be done in this case.

Let's suppose to have a simple Hub like in the official docs:

using Microsoft.AspNetCore.SignalR;

namespace SignalRChat.Hubs
{
    public class ChatHub : Hub {}
}

and an Api controller that receives the hub context through DI and simply broadcasts a message:

class YatpApiController(IHubContext<ChatHub> hubContext) : ControllerBase() {
   [HttpPost("signalr-broadcast")]
   public SignalrBroadcast()
   {
       hubContext.Clients.All.SendAsync("Method1", "Message1");
   }
}

Can someone please

  • Show how to use Fable.SignalR.Elmish client side with this very simple case?
  • Give advise on an alternative way to connect to this simple hub from a Fable.Elmish application, without writing bindings to the javascript signalr package?
0

There are 0 answers

Related Questions in FABLE-F#