Pregunta

I have the following code:

public void JoinGroup(string groupName, string userFullName)
{
    Groups.Add(Context.ConnectionId, groupName);
    // Send data back to everyone including the caller   
    Clients.Group(groupName).dataChanged(...);
}

I would expect Clients.Group(groupName) to call back to the client who just joined the group but it does not. Clients.Caller... however does correctly call the client who just joined the group.

QUESTION

Why isn't Clients.Group(groupName) including the caller who just joined the group?

¿Fue útil?

Solución

Groups.Add is async, so you need to await it if you want to use the group in the same method (as stated in the documentation):

public async Task JoinGroup(string groupName, string userFullName)
{
    await Groups.Add(Context.ConnectionId, groupName);
    // Send data back to everyone including the caller   
    Clients.Group(groupName).dataChanged(...);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top