signalr core - how to call hub method from client

Refresh

February 2019

Views

3 time

0

I'm adding SignalR to my app. I can send messages from server to client, but can't call hub methods from client. Here's my hub interface:

    public interface IGeneralHub
{
    Task BroadcastMessage(HubMessage msg); //string type, string payload);
    Task JoinHub(List<int> ids);
}

and hub client:

    public class AuctionHub : Hub<IGeneralHub>
    {
    public void Broadcast(HubMessage msg)
    {
        Clients.All.BroadcastMessage(msg);
    }
    public void JoinHub(List<int> ids)
    {
        foreach (var id in ids.Distinct())
            Groups.AddToGroupAsync(Context.ConnectionId, id.ToString());
    }
}

And client side:

this.hubConnections = new signalR.HubConnectionBuilder()
                    .withUrl(`${environment.hubHost}/document/`)
                    .build();
                this.hubConnections
                    .start()
                    .then(() => console.log('Connection started'))
                    .catch(err => console.log('Error while starting connection: ' + err));
                this.hubConnections.invoke('joinGroup', JSON.parse(localStorage.getItem('ws-document')));

I receive messages, but joinGroup is never called. What am I doing wrong?

0 answers