Ejemplo n.º 1
0
        public async Task <IActionResult> GetUnreadMessagesForVideoOfficerAsync(Guid conferenceId)
        {
            _logger.LogDebug($"GetMessages for {conferenceId}");
            try
            {
                var messages = await _videoApiClient.GetInstantMessageHistoryAsync(conferenceId);

                if (messages.IsNullOrEmpty())
                {
                    return(Ok(new UnreadInstantMessageConferenceCountResponse()));
                }

                var conference = await _conferenceCache.GetOrAddConferenceAsync
                                 (
                    conferenceId,
                    () => _videoApiClient.GetConferenceDetailsByIdAsync(conferenceId)
                                 );

                var response = UnreadInstantMessageConferenceResponseMapper.MapToResponseModel(conference, messages);
                return(Ok(response));
            }
            catch (VideoApiException e)
            {
                _logger.LogError(e, $"Unable to get messages for conference {conferenceId}");
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
Ejemplo n.º 2
0
        private async Task <bool> IsParticipantAWitnessOrWitnessInterpreter(Guid conferenceId, Guid participantId)
        {
            var conference = await _conferenceCache.GetOrAddConferenceAsync
                             (
                conferenceId,
                () => _videoApiClient.GetConferenceDetailsByIdAsync(conferenceId)
                             );

            var participant = conference.Participants.SingleOrDefault(x => x.Id == participantId);

            if (participant == null)
            {
                return(false);
            }

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

            var witnessRoom = conference.CivilianRooms.First(x => x.Participants.Contains(participant.Id));
            var expectedParticipantsInRoomIds = participant.LinkedParticipants.Select(x => x.LinkedId).ToList();

            expectedParticipantsInRoomIds.Add(participant.Id);
            return(expectedParticipantsInRoomIds.All(p => witnessRoom.Participants.Contains(p)));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetConferenceInstantMessageHistoryForParticipantAsync(Guid conferenceId, Guid participantId)
        {
            _logger.LogDebug($"GetMessages for {conferenceId}");
            try
            {
                var conference = await _conferenceCache.GetOrAddConferenceAsync
                                 (
                    conferenceId,
                    () => _videoApiClient.GetConferenceDetailsByIdAsync(conferenceId)
                                 );

                var participant = conference.Participants.Single(x => x.Id == participantId);

                var messages =
                    await _videoApiClient.GetInstantMessageHistoryForParticipantAsync(conferenceId, participant.Username);

                if (messages == null || !messages.Any())
                {
                    return(Ok(new List <ChatResponse>()));
                }

                var response = await MapMessages(messages.ToList(), conferenceId);

                response = response.OrderBy(r => r.Timestamp).ToList();

                return(Ok(response));
            }
            catch (VideoApiException e)
            {
                _logger.LogError(e, $"Unable to get messages for conference {conferenceId}");
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
Ejemplo n.º 4
0
        private async Task <bool> IsConferenceJudge(Guid conferenceId)
        {
            var conference = await _conferenceCache.GetOrAddConferenceAsync
                             (
                conferenceId,
                () => _videoApiClient.GetConferenceDetailsByIdAsync(conferenceId)
                             );

            return(conference.GetJudge().Username
                   .Equals(User.Identity.Name?.Trim(), StringComparison.InvariantCultureIgnoreCase));
        }
        private async Task <Conference> GetConference(Guid conferenceId)
        {
            var conference = await _conferenceCache.GetOrAddConferenceAsync(conferenceId,
                                                                            () => _videoApiClient.GetConferenceDetailsByIdAsync(conferenceId));

            return(conference);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> UpdateParticipantStatusAsync(Guid conferenceId,
                                                                       UpdateParticipantStatusEventRequest updateParticipantStatusEventRequest)
        {
            var conference = await _conferenceCache.GetOrAddConferenceAsync(conferenceId, () =>
            {
                _logger.LogTrace($"Retrieving conference details for conference: ${conferenceId}");

                return(_videoApiClient.GetConferenceDetailsByIdAsync(conferenceId));
            });

            var username               = User.Identity.Name;
            var participantId          = GetIdForParticipantByUsernameInConference(conference, username);
            var conferenceEventRequest = new ConferenceEventRequest
            {
                Conference_id  = conferenceId.ToString(),
                Participant_id = participantId.ToString(),
                Event_id       = Guid.NewGuid().ToString(),
                Event_type     = updateParticipantStatusEventRequest.EventType,
                Time_stamp_utc = DateTime.UtcNow,
                Reason         = EventTypeReasonMapper.Map(updateParticipantStatusEventRequest.EventType)
            };

            var callbackEvent =
                CallbackEventMapper.MapConferenceEventToCallbackEventModel(conferenceEventRequest, conference);
            var handler = _eventHandlerFactory.Get(callbackEvent.EventType);

            try
            {
                await handler.HandleAsync(callbackEvent);
            }
            catch (ConferenceNotFoundException)
            {
                return(BadRequest());
            }

            try
            {
                await _videoApiClient.RaiseVideoEventAsync(conferenceEventRequest);

                return(NoContent());
            }
            catch (VideoApiException e)
            {
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> UpdateParticipantStatusAsync(Guid conferenceId,
                                                                       UpdateParticipantStatusEventRequest updateParticipantStatusEventRequest)
        {
            var conference = await _conferenceCache.GetOrAddConferenceAsync(conferenceId,
                                                                            () => _videoApiClient.GetConferenceDetailsByIdAsync(conferenceId));

            var participantId          = GetIdForParticipantByUsernameInConference(conference);
            var eventTypeMapper        = _mapperFactory.Get <EventType, string>();
            var conferenceEventRequest = new ConferenceEventRequest
            {
                ConferenceId  = conferenceId.ToString(),
                ParticipantId = participantId.ToString(),
                EventId       = Guid.NewGuid().ToString(),
                EventType     = updateParticipantStatusEventRequest.EventType,
                TimeStampUtc  = DateTime.UtcNow,
                Reason        = eventTypeMapper.Map(updateParticipantStatusEventRequest.EventType)
            };

            var callbackEventMapper = _mapperFactory.Get <ConferenceEventRequest, Conference, CallbackEvent>();
            var callbackEvent       = callbackEventMapper.Map(conferenceEventRequest, conference);
            var handler             = _eventHandlerFactory.Get(callbackEvent.EventType);

            try
            {
                await handler.HandleAsync(callbackEvent);
            }
            catch (ConferenceNotFoundException e)
            {
                _logger.LogError(e, $"Unable to retrieve conference details");
                return(BadRequest(e));
            }

            try
            {
                await _videoApiClient.RaiseVideoEventAsync(conferenceEventRequest);

                return(NoContent());
            }
            catch (VideoApiException e)
            {
                _logger.LogError(e, $"Unable to update participant status for " +
                                 $"participant: {participantId} in conference: {conferenceId}");
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
Ejemplo n.º 8
0
        private async Task <Conference> GetConference(Guid conferenceId)
        {
            return(await _conferenceCache.GetOrAddConferenceAsync(conferenceId, () =>
            {
                _logger.LogTrace($"Retrieving conference details for conference: ${conferenceId}");

                return _videoApiClient.GetConferenceDetailsByIdAsync(conferenceId);
            }));
        }
Ejemplo n.º 9
0
        private async Task <Guid> GetIdForParticipantByUsernameInConference(Guid conferenceId)
        {
            var conference = await _conferenceCache.GetOrAddConferenceAsync
                             (
                conferenceId,
                () => _videoApiClient.GetConferenceDetailsByIdAsync(conferenceId)
                             );

            var username = User.Identity.Name;

            return(conference.Participants
                   .Single(x => x.Username.Equals(username, StringComparison.CurrentCultureIgnoreCase)).Id);
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> SendHearingEventAsync(ConferenceEventRequest request)
        {
            try
            {
                var conferenceId = Guid.Parse(request.ConferenceId);
                var conference   = await _conferenceCache.GetOrAddConferenceAsync(conferenceId, () =>
                {
                    _logger.LogTrace("Retrieving conference details for conference: {ConferenceId}", conferenceId);
                    return(_videoApiClient.GetConferenceDetailsByIdAsync(conferenceId));
                });
                await UpdateConferenceRoomParticipants(conference, request);

                var events = new List <ConferenceEventRequest>()
                {
                    request
                };
                if (request.IsParticipantAVmr(conference, out var roomId))
                {
                    request.ParticipantRoomId = roomId.ToString();
                    request.ParticipantId     = null;
                    events = request.CreateEventsForParticipantsInRoom(conference, roomId);
                }

                var callbackEvents = events.Select(e => TransformAndMapRequest(e, conference)).ToList();
                // DO NOT USE Task.WhenAll because the handlers are not thread safe and will overwrite Source<Variable> for each run
                foreach (var e in events)
                {
                    await SendEventToVideoApi(e);
                }

                foreach (var cb in callbackEvents)
                {
                    await PublishEventToUi(cb);
                }

                return(NoContent());
            }
            catch (VideoApiException e)
            {
                _logger.LogError(e, "ConferenceId: {ConferenceId}, ErrorCode: {StatusCode}", request.ConferenceId,
                                 e.StatusCode);
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> SendHearingEventAsync(ConferenceEventRequest request)
        {
            try
            {
                _logger.LogTrace("Received callback from Kinly.");
                _logger.LogTrace($"ConferenceId: {request.Conference_id}, EventType: {request.Event_type}, Participant ID : {request.Participant_id}");

                var conferenceId = Guid.Parse(request.Conference_id);
                var conference   = await _conferenceCache.GetOrAddConferenceAsync(conferenceId, () =>
                {
                    _logger.LogTrace($"Retrieving conference details for conference: ${conferenceId}");
                    return(_videoApiClient.GetConferenceDetailsByIdAsync(conferenceId));
                });

                var callbackEvent = CallbackEventMapper.MapConferenceEventToCallbackEventModel(request, conference);
                request.Event_type = Enum.Parse <VAEventType>(callbackEvent.EventType.ToString());
                if (callbackEvent.EventType != EventType.VhoCall)
                {
                    _logger.LogTrace($"Raising video event: ConferenceId: {request.Conference_id}, EventType: {request.Event_type}");
                    await _videoApiClient.RaiseVideoEventAsync(request);
                }

                if (!string.IsNullOrEmpty(request.Phone))
                {
                    return(NoContent());
                }

                var handler = _eventHandlerFactory.Get(callbackEvent.EventType);
                await handler.HandleAsync(callbackEvent);

                return(NoContent());
            }
            catch (VideoApiException e)
            {
                _logger.LogError(e, $"ConferenceId: {request.Conference_id}, ErrorCode: {e.StatusCode}");
                return(StatusCode(e.StatusCode, e.Response));
            }
        }
Ejemplo n.º 12
0
 private Task <Conference> GetConference(Guid conferenceId)
 {
     return(_conferenceCache.GetOrAddConferenceAsync(conferenceId,
                                                     () => _videoApiClient.GetConferenceDetailsByIdAsync(conferenceId)));
 }