private static async Task <WebRtcSession> SendSDPOffer(WebSocketContext context) { logger.LogDebug($"Web socket client connection from {context.UserEndPoint}."); var webRtcSession = new WebRtcSession( AddressFamily.InterNetwork, DTLS_CERTIFICATE_FINGERPRINT, null, null); MediaStreamTrack audioTrack = new MediaStreamTrack(null, SDPMediaTypesEnum.audio, false, new List <SDPMediaFormat> { new SDPMediaFormat(SDPMediaFormatsEnum.PCMU) }); webRtcSession.addTrack(audioTrack); MediaStreamTrack videoTrack = new MediaStreamTrack(null, SDPMediaTypesEnum.video, false, new List <SDPMediaFormat> { new SDPMediaFormat(SDPMediaFormatsEnum.VP8) }); webRtcSession.addTrack(videoTrack); //webRtcSession.RtpSession.OnReceiveReport += RtpSession_OnReceiveReport; webRtcSession.OnSendReport += RtpSession_OnSendReport; OnMediaSampleReady += webRtcSession.SendMedia; webRtcSession.OnClose += (reason) => { logger.LogDebug($"WebRtcSession was closed with reason {reason}"); OnMediaSampleReady -= webRtcSession.SendMedia; webRtcSession.OnReceiveReport -= RtpSession_OnReceiveReport; webRtcSession.OnSendReport -= RtpSession_OnSendReport; }; var offerSdp = await webRtcSession.createOffer(null); webRtcSession.setLocalDescription(new RTCSessionDescription { sdp = offerSdp, type = RTCSdpType.offer }); logger.LogDebug($"Sending SDP offer to client {context.UserEndPoint}."); context.WebSocket.Send(offerSdp.ToString()); if (DoDtlsHandshake(webRtcSession)) { if (!_isSampling) { _ = Task.Run(StartMedia); } } else { webRtcSession.Close("dtls handshake failed."); } return(webRtcSession); }
private static WebRtcSession SendSDPOffer(WebSocketContext context) { Log.LogDebug($"Web socket client connection from {context.UserEndPoint}."); _webRtcSession = new WebRtcSession( AddressFamily.InterNetwork, DTLS_CERTIFICATE_FINGERPRINT, null, null); _webRtcSession.OnReceiveReport += RtpSession_OnReceiveReport; _webRtcSession.OnSendReport += RtpSession_OnSendReport; Log.LogDebug($"Sending SDP offer to client {context.UserEndPoint}."); _webRtcSession.OnClose += (reason) => { Log.LogDebug($"WebRtcSession was closed with reason {reason}"); _webRtcSession.OnReceiveReport -= RtpSession_OnReceiveReport; _webRtcSession.OnSendReport -= RtpSession_OnSendReport; }; MediaStreamTrack audioTrack = new MediaStreamTrack(null, SDPMediaTypesEnum.audio, false, new List <SDPMediaFormat> { new SDPMediaFormat(SDPMediaFormatsEnum.PCMU) }); _webRtcSession.addTrack(audioTrack); var offer = _webRtcSession.createOffer(null).Result; _webRtcSession.setLocalDescription(new RTCSessionDescription { type = RTCSdpType.offer, sdp = offer }); context.WebSocket.Send(offer.ToString()); if (DoDtlsHandshake(_webRtcSession)) { Log.LogInformation("DTLS handshake completed successfully."); } else { _webRtcSession.Close("dtls handshake failed."); } return(_webRtcSession); }
private static async Task <WebRtcSession> SendSDPOffer(WebSocketContext context) { logger.LogDebug($"Web socket client connection from {context.UserEndPoint}."); var webRtcSession = new WebRtcSession( AddressFamily.InterNetwork, DTLS_CERTIFICATE_FINGERPRINT, null, null); webRtcSession.addTrack(SDPMediaTypesEnum.video, new List <SDPMediaFormat> { new SDPMediaFormat(SDPMediaFormatsEnum.VP8) }); webRtcSession.RtpSession.OnReceiveReport += RtpSession_OnReceiveReport; webRtcSession.RtpSession.OnSendReport += RtpSession_OnSendReport; webRtcSession.OnClose += (reason) => { logger.LogDebug($"WebRtcSession was closed with reason {reason}"); OnTestPatternSampleReady -= webRtcSession.SendMedia; webRtcSession.RtpSession.OnReceiveReport -= RtpSession_OnReceiveReport; webRtcSession.RtpSession.OnSendReport -= RtpSession_OnSendReport; }; var offerSdp = await webRtcSession.createOffer(); webRtcSession.setLocalDescription(offerSdp); logger.LogDebug($"Sending SDP offer to client {context.UserEndPoint}."); logger.LogDebug(webRtcSession.SDP.ToString()); context.WebSocket.Send(webRtcSession.SDP.ToString()); if (DoDtlsHandshake(webRtcSession)) { OnTestPatternSampleReady += webRtcSession.SendMedia; } else { webRtcSession.Close("dtls handshake failed."); } return(webRtcSession); }