/// <summary>
        /// Get the image for a particular call
        /// </summary>
        /// <param name="conversationResult"></param>
        /// <returns></returns>
        public static HttpResponseMessage GetVideoImageResponse(string callId)
        {
            RealTimeMediaCall mediaCall = RealTimeMediaCall.GetCallForCallId(callId);

            if (mediaCall == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            MediaSession mediaSession = mediaCall.MediaSession;

            Log.Info(new CallerInfo(), LogContext.FrontEnd, $"[{callId}] Received request to retrieve image for call");
            Bitmap bitmap = mediaSession.CurrentVideoImage;

            if (bitmap == null)
            {
                return(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            response.Content = new PushStreamContent((targetStream, httpContext, transportContext) =>
            {
                using (targetStream)
                {
                    bitmap.Save(targetStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                }
            }, new MediaTypeHeaderValue("image/jpeg"));

            response.Headers.Add("Cache-Control", "private,must-revalidate,post-check=1,pre-check=2,no-cache");

            string url = $"{Service.Instance.Configuration.AzureInstanceBaseUrl}/{HttpRouteConstants.CallSignalingRoutePrefix}/{HttpRouteConstants.Image}";

            url = url.Replace("{callid}", callId);
            response.Headers.Add("Refresh", $"3; url={url}");

            return(response);
        }
Example #2
0
 private Task OnAnswerAppHostedMediaCompleted(AnswerAppHostedMediaOutcomeEvent answerAppHostedMediaOutcomeEvent)
 {
     try
     {
         Log.Info(new CallerInfo(), LogContext.FrontEnd, $"[{CallId}] OnAnswerAppHostedMediaCompleted");
         AnswerAppHostedMediaOutcome answerAppHostedMediaOutcome = answerAppHostedMediaOutcomeEvent.AnswerAppHostedMediaOutcome;
         if (answerAppHostedMediaOutcome.Outcome == Outcome.Failure)
         {
             Log.Info(new CallerInfo(), LogContext.FrontEnd, $"[{CallId}] AnswerAppHostedMedia failed with reason: {answerAppHostedMediaOutcome.FailureReason}");
             //cleanup internal resources
             MediaSession.Dispose();
         }
         else
         {
             answerAppHostedMediaOutcomeEvent.RealTimeMediaWorkflow.NotificationSubscriptions = new NotificationType[] { NotificationType.CallStateChange };
         }
         return(Task.CompletedTask);
     } catch (Exception ex)
     {
         Log.Info(new CallerInfo(), LogContext.FrontEnd, $"[{CallId}] threw {ex.ToString()}");
         throw;
     }
 }