0

I am using @microsoft/signal on client end and azure Signalr on server end.

I did called SendAsync() from other api but its not worked for me.

Startup.cs:

services.AddSignalR().AddAzureSignalR();

app.UseAzureSignalR(routes =>
        {
            routes.MapHub<MyHub>("/my");
        });

ITypedHubClient.cs:

public interface ITypedHubClient
{
    Task BroadcastMessage(string name, string message);
}

MyHub.cs:

    public class MyHub: Hub<ITypedHubClient>
     {
          public void Send(string name, string message)
          {
               this.Clients.All.BroadcastMessage(name, message);
          }
     }

In Service(Other API service which is in different port than signalR client):

    private readonly IHubContext<MyHub, ITypedHubClient> hubContext;

   // After record will be updated 
   hubContext.Clients.All.BroadcastMessage("RefreshDetails", "test");

In javascript client:

        var connection = new signalR.HubConnectionBuilder().withUrl("/my").withAutomaticReconnect().build();

        connection.on("BroadcastMessage", function (params) {
           //TODO
        }
Komal
  • 11
  • 2
  • https://stackoverflow.com/questions/46904678/call-signalr-core-hub-method-from-controller – Jason Pan Sep 20 '21 at 13:01
  • InvokeAsync() is not supporting , tried with Solution 2 but not working its not giving any error too. – Komal Sep 21 '21 at 09:21
  • Can you show us some of your code and any errors you might be getting? Also, what your setup is in terms of tech etc. being used. – 97ldave Sep 21 '21 at 10:22
  • @97ldave i have edited the description. – Komal Sep 21 '21 at 10:42
  • @Komal thanks. Is the code in your javascript client correct? the .withUrl() should contain the url of your hub your connecting to. The endpoint in your startup class is "/myhub" and in .withUrl("/tic") – 97ldave Sep 21 '21 at 10:44
  • Yes, edited, its correct in my app. @97ldave – Komal Sep 21 '21 at 11:03
  • @Komal are you getting any errors? – 97ldave Sep 21 '21 at 13:14
  • No. Even hubContext.Clients.All.BroadcastMessage("RefreshDetails", "test"); executed successfully but not able to trigger method of javascript client. @97ldave – Komal Sep 22 '21 at 04:50
  • @Komal does signalr connect on the client? is there a successful /negotiate request? – 97ldave Sep 22 '21 at 14:22
  • Yes, negotiate request is successful. @97ldave. – Komal Sep 23 '21 at 04:27

0 Answers0