1

Here we are using asp.net core singnalR alpha2 version. How to send notification for groups (group of users)? If any sample is there for scenario, post here the sample link.

In Hub write method with group.

public class SignalRCommonHub : Hub
{
   
    public void SendToGroup(int groupId, int userId)
    {
        Clients.Group(groupId.ToString()).InvokeAsync("refresh", groupId, userId);
    }
}

In controller called the hub method.

private readonly IHubContext<SignalRCommonHub> isignalRhub;

public SignalRModel(IHubContext<SignalRCommonHub> signalRhub)
{
    this.isignalRhub = signalRhub;
}

public void RefreshPage(int groupId, int userId)
{
    this.isignalRhub.Clients.Group(groupId.ToString()).InvokeAsync("refresh", groupId, userId);
}

In client side not trigger when call method in client side.

User online status update based on groups (group of users) using signalR sample available means post here link. Suggest idea for how to implement the user online status.

Thanks,

2
  • Please add some information on what you have tried, the basics of the code you are using and the how you intend to specify groups. Commented Feb 7, 2018 at 9:41
  • Please take some time to clean up your question and format the code. Commented Feb 17, 2018 at 3:18

1 Answer 1

1

from your front end interface, you will need to setup the hub/connection, then make a call to Add/Remove groups using the connectionId and the group id/name.

eg: await _viewerHubContext.Groups.AddAsync(connectionId, groupName);

Then when you broadcast calls, you just use the group id/name and signalR will send to those groups.

eg: return Clients.Group(groupName).InvokeAsync("Send", "SendData", data);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.