public virtual async Task HandleAsync(CallbackEvent callbackEvent) { _logger.LogDebug("Handling callback"); var sw = Stopwatch.StartNew(); SourceConference = await QueryHandler.Handle <GetConferenceByIdQuery, Conference>( new GetConferenceByIdQuery(callbackEvent.ConferenceId)); if (SourceConference == null) { throw new ConferenceNotFoundException(callbackEvent.ConferenceId); } SourceParticipant = SourceConference.GetParticipants() .SingleOrDefault(x => x.Id == callbackEvent.ParticipantId); SourceEndpoint = SourceConference.GetEndpoints().SingleOrDefault(x => x.Id == callbackEvent.ParticipantId); await PublishStatusAsync(callbackEvent); _logger.LogDebug("Handled callback in {ElapsedMilliseconds}ms", sw.ElapsedMilliseconds); }
protected override async Task PublishStatusAsync(CallbackEvent callbackEvent) { var participantStatus = DeriveParticipantStatusForTransferEvent(callbackEvent); var command = new UpdateParticipantStatusAndRoomCommand(SourceConference.Id, SourceParticipant.Id, participantStatus, callbackEvent.TransferTo, callbackEvent.TransferredToRoomLabel); await CommandHandler.Handle(command); if (!callbackEvent.TransferredFromRoomLabel.ToLower().Contains("consultation") || callbackEvent.TransferTo == RoomType.HearingRoom) { return; } var roomQuery = new GetConsultationRoomByIdQuery(SourceConference.Id, callbackEvent.TransferredFromRoomLabel); var room = await QueryHandler.Handle <GetConsultationRoomByIdQuery, ConsultationRoom>(roomQuery); if (room == null) { _logger.LogError("Unable to find room {roomLabel} in conference {conferenceId}", callbackEvent.TransferredFromRoomLabel, SourceConference.Id); } else if (room.Status == RoomStatus.Live && !room.RoomParticipants.Any()) { foreach (var endpoint in room.RoomEndpoints) { await _consultationService.EndpointTransferToRoomAsync(SourceConference.Id, endpoint.EndpointId, RoomType.WaitingRoom.ToString()); } } else if (room.RoomEndpoints.Any()) { var participantsEndpoints = SourceConference.GetEndpoints().Where(x => x.DefenceAdvocate?.Equals(SourceParticipant.Username, System.StringComparison.OrdinalIgnoreCase) ?? false).Select(x => x.Id).ToList(); foreach (var endpoint in room.RoomEndpoints.Where(roomEndpoint => participantsEndpoints.Contains(roomEndpoint.EndpointId))) { await _consultationService.EndpointTransferToRoomAsync(SourceConference.Id, endpoint.EndpointId, RoomType.WaitingRoom.ToString()); } } }