public override async Task OnConnectedAsync() { var httpContext = Context.GetHttpContext(); var request = httpContext.Request; var cookieVal = request.Query[QueryStringName].ToString(); if (string.IsNullOrEmpty(cookieVal)) { return; } var roomId = Guid.Parse(cookieVal); var userId = long.Parse(Context.UserIdentifier); var command = new ChangeStudyRoomOnlineStatusCommand(userId, true, roomId); await Clients.All.SendAsync("Online", userId); await Groups.AddToGroupAsync(Context.ConnectionId, cookieVal); await _commandBus.DispatchAsync(command, default); await base.OnConnectedAsync(); }
public override async Task OnDisconnectedAsync(Exception exception) { //We cant delete the cookie var request = Context.GetHttpContext().Request; var cookieVal = request.Query[QueryStringName].ToString(); var roomId = Guid.Parse(cookieVal); var userId = long.Parse(Context.UserIdentifier); var command = new ChangeStudyRoomOnlineStatusCommand(userId, false, roomId); await _commandBus.DispatchAsync(command, default); await Clients.All.SendAsync("Offlie", userId); await Groups.RemoveFromGroupAsync(Context.ConnectionId, cookieVal); await base.OnDisconnectedAsync(exception); }