public async Task OpenDirectMessage(string username) { try { string uid = UserManagement.GetIdFromUsername(username); if (uid.Equals(Context.ConnectionId)) { await Clients.Caller.SendAsync("SameUserError"); return; } string groupname = Context.ConnectionId + uid; string[] v = { Context.ConnectionId, uid }; await Groups.AddToGroupAsync(Context.ConnectionId, groupname); await Groups.AddToGroupAsync(uid, groupname); await Clients.Clients(v).SendAsync("UpdateGroups", groupname); } catch (UserManagement.UserDoesntExistException e) { await Clients.Caller.SendAsync("UserDoesntExistError"); } }
public async Task SendMessage(string room, string msg) { await Clients.Group(room).SendAsync("ReceiveMessage", room, UserManagement.GetUsername(Context.ConnectionId), msg); }
public override async Task OnDisconnectedAsync(Exception exception) { UserManagement.Remove(Context.ConnectionId); await base.OnDisconnectedAsync(exception); }