internal static async Task SendUrlForConversationId(string threadId) { RealTimeMediaCall mediaCall = ActiveMediaCalls.Values.FirstOrDefault(x => (x.ThreadId == threadId)); if (mediaCall == null) { Log.Warning(new CallerInfo(), LogContext.FrontEnd, $"No active mediacall for {threadId}"); return; } await SendMessageForCall(mediaCall); }
internal static async Task SendMessageForCall(RealTimeMediaCall mediaCall) { string url = $"{Service.Instance.Configuration.AzureInstanceBaseUrl}/{HttpRouteConstants.CallSignalingRoutePrefix}/{HttpRouteConstants.Image}"; url = url.Replace("{callid}", mediaCall.CallId); try { await MessageSender.SendMessage(mediaCall.ThreadId, url); } catch (Exception ex) { Log.Error(new CallerInfo(), LogContext.FrontEnd, $"[{mediaCall.CallId}] Exception in sending chat {ex}"); } }
/// <summary> /// Create a new instance of the MediaSession. /// </summary> public MediaSession(string id, string correlationId, RealTimeMediaCall call) { _correlationId = correlationId; this.Id = id; RealTimeMediaCall = call; Log.Info(new CallerInfo(), LogContext.FrontEnd, $"[{this.Id}]: Call created"); try { _audioSocket = new AudioSocket(new AudioSocketSettings { StreamDirections = StreamDirection.Recvonly, SupportedAudioFormat = AudioFormat.Pcm16K, // audio format is currently fixed at PCM 16 KHz. CallId = correlationId }); Log.Info(new CallerInfo(), LogContext.FrontEnd, $"[{this.Id}]:Created AudioSocket"); // video socket _videoSocket = new VideoSocket(new VideoSocketSettings { StreamDirections = StreamDirection.Recvonly, ReceiveColorFormat = VideoColorFormat.NV12, CallId = correlationId }); Log.Info(new CallerInfo(), LogContext.FrontEnd, $"[{this.Id}]: Created VideoSocket"); //audio socket events _audioSocket.DominantSpeakerChanged += OnDominantSpeakerChanged; //Video socket events _videoSocket.VideoMediaReceived += OnVideoMediaReceived; MediaConfiguration = MediaPlatform.CreateMediaConfiguration(_audioSocket, _videoSocket); Log.Info(new CallerInfo(), LogContext.FrontEnd, $"[{this.Id}]: MediaConfiguration={MediaConfiguration.ToString(Formatting.Indented)}"); } catch (Exception ex) { Log.Error(new CallerInfo(), LogContext.FrontEnd, "Error in MediaSession creation" + ex.ToString()); Dispose(); throw; } }
/// <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); }