Exemplo n.º 1
0
        public async Task NotifyConsultationResponseAsync(Conference conference, string roomLabel, Guid requestedForId,
                                                          ConsultationAnswer answer)
        {
            var endpoint = conference.Endpoints.FirstOrDefault(e => e.Id == requestedForId);

            if (endpoint != null)
            {
                await PublishResponseMessage(conference, roomLabel, endpoint.Id, answer);

                return;
            }

            var participantFor = conference.Participants.First(x => x.Id == requestedForId);
            await _consultationResponseTracker.UpdateConsultationResponse(conference, participantFor.Id, answer);

            var haveAllAccepted =
                await _consultationResponseTracker.HaveAllParticipantsAccepted(conference, participantFor.Id);

            if (answer == ConsultationAnswer.Accepted && !haveAllAccepted)
            {
                return;
            }

            await PublishResponseMessage(conference, roomLabel, participantFor.Id, answer);

            if (participantFor.LinkedParticipants.Any())
            {
                await NotifyLinkedParticipantsOfConsultationResponseAsync(conference, participantFor, roomLabel, answer);
            }

            if (answer == ConsultationAnswer.Transferring && participantFor.LinkedParticipants.Any())
            {
                await _consultationResponseTracker.ClearResponses(conference, requestedForId);
            }
        }
        public async Task UpdateConsultationResponse(Conference conference, Guid participantId,
                                                     ConsultationAnswer answer)
        {
            var participant = conference.Participants.First(x => x.Id == participantId);

            if (!participant.LinkedParticipants.Any())
            {
                return;
            }

            var interpreterRoom = GetRoomForParticipant(conference, participant);

            if (answer == ConsultationAnswer.Rejected)
            {
                await StopTrackingResponsesForInterpreterRoom(interpreterRoom.Id);
            }

            var acceptedConsultations = await _cache.GetResponses(interpreterRoom.Id);

            if (!acceptedConsultations.Contains(participantId))
            {
                acceptedConsultations.Add(participantId);
            }

            await _cache.AddOrUpdateResponses(interpreterRoom.Id, acceptedConsultations);
        }
Exemplo n.º 3
0
 private async Task InitiateStartConsultationAsync(Conference conference, Participant requestedBy,
                                                   Participant requestedFor, ConsultationAnswer answer)
 {
     if (answer == ConsultationAnswer.Accepted)
     {
         _logger.LogInformation(
             "Conference: {conferenceId} - Attempting to start private consultation between {requestedById} and {requestedForId}", conference.Id, requestedBy.Id, requestedFor.Id);
         await _videoPlatformService.StartPrivateConsultationAsync(conference, requestedBy, requestedFor);
     }
 }
Exemplo n.º 4
0
        public void should_map_to_private_consultation_request(ConsultationAnswer answer, ConsultationAnswer expectedAnswer)
        {
            var request = Builder <PrivateConsultationRequest> .CreateNew()
                          .With(x => x.ConferenceId   = Guid.NewGuid())
                          .With(x => x.RequestedById  = Guid.NewGuid())
                          .With(x => x.RequestedForId = Guid.NewGuid())
                          .With(x => x.Answer         = answer)
                          .Build();

            var result = _sut.Map(request);

            result.Answer.Should().Be(expectedAnswer);
            result.ConferenceId.Should().Be(request.ConferenceId);
            result.RequestedBy.Should().Be(request.RequestedById);
            result.RequestedFor.Should().Be(request.RequestedForId);
        }
Exemplo n.º 5
0
        public void should_map_to_admin_consultation_request(ConsultationAnswer answer, ApiConsultationRequestAnswer?expectedAnswer)
        {
            var request = Builder <PrivateAdminConsultationRequest> .CreateNew()
                          .With(x => x.ConferenceId     = Guid.NewGuid())
                          .With(x => x.ParticipantId    = Guid.NewGuid())
                          .With(x => x.ConsultationRoom = RoomType.ConsultationRoom1)
                          .With(x => x.Answer           = answer)
                          .Build();

            var result = PrivateAdminConsultationRequestMapper.MapToAdminConsultationRequest(request);

            result.Conference_id.Should().Be(request.ConferenceId);
            result.Participant_id.Should().Be(request.ParticipantId);
            result.Consultation_room.Should().Be(request.ConsultationRoom);
            result.Answer.Should().Be(answer);
        }
        public async Task should_send_message_to_other_party_when_participant_responds(ConsultationAnswer answer)
        {
            // arrange
            var allNonJudgeAndNonLinkedParticipants = _conference.Participants
                                                      .Where(x => !x.IsJudge() && !x.LinkedParticipants.Any()).ToList();
            var roomLabel    = "ConsultationRoom1";
            var requestedFor = allNonJudgeAndNonLinkedParticipants[0];

            // act
            await _sut.NotifyConsultationResponseAsync(_conference, roomLabel, requestedFor.Id, answer);

            // assert
            _mocker.Mock <IEventHubClient>().Verify(
                x => x.ConsultationRequestResponseMessage(_conference.Id, roomLabel, requestedFor.Id, answer),
                Times.Exactly(_conference.Participants.Count));
        }
Exemplo n.º 7
0
        private async Task NotifyLinkedParticipantsOfConsultationResponseAsync(Conference conference, Participant participantFor, string roomLabel, ConsultationAnswer answer)
        {
            var linkedIds          = participantFor.LinkedParticipants.Select(x => x.LinkedId);
            var linkedParticipants = conference.Participants.Where(p => linkedIds.Contains(p.Id));

            foreach (var linkedParticipant in linkedParticipants)
            {
                await PublishResponseMessage(conference, roomLabel, linkedParticipant.Id, answer);
            }
        }
Exemplo n.º 8
0
 private async Task PublishResponseMessage(Conference conference, string roomLabel, Guid requestedForId, ConsultationAnswer answer)
 {
     var tasks = conference.Participants.Select(p =>
                                                _hubContext.Clients?.Group(p.Username.ToLowerInvariant())
                                                .ConsultationRequestResponseMessage(conference.Id, roomLabel, requestedForId, answer) ?? Task.CompletedTask);
     await Task.WhenAll(tasks);
 }
Exemplo n.º 9
0
 public static PrivateAdminConsultationRequest GetAdminConsultationRequest(Conference conference, ConsultationAnswer answer)
 {
     return(Builder <PrivateAdminConsultationRequest> .CreateNew()
            .With(x => x.ConferenceId = conference.Id)
            .With(x => x.ParticipantId = conference.Participants[1].Id)
            .With(x => x.ConsultationRoom = RoomType.ConsultationRoom1)
            .With(x => x.Answer = answer)
            .Build());
 }