1

The following code adds a user to a signalR group:

[Function("AddToGroup")]
public SignalROutputEntity AddUserToGroup(
    [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "addtogroup/{groupName}/{myId}")]
    HttpRequestData req,
    string groupName,
    string myId)
{
    var output = new SignalROutputEntity();
    output.Notifications.Add(new
    {
        userId = myId,
        groupName = groupName,
        action = "add"
    });
    output.Response = req.CreateResponse(HttpStatusCode.OK);
    return output;
}

public class SignalROutputEntity
{
    [SignalROutput(HubName = "myHub", ConnectionStringSetting = "AzureSignalRConnectionString")]
    public List<object> Notifications { get; set; } = new();

    public HttpResponseData? Response { get; set; }
}

I am aware that we can leverage signalR upstream to listen to and handle events when a user connects or disconnects to/from the signalR hub to increment or decrement a kind of counter. Aside from this method, is there a method or technique to query the Azure SignalR Service instance to determine the number of connected users per group?

Arash
  • 3,628
  • 5
  • 46
  • 70

0 Answers0