Beispiel #1
0
        private static async void MessageReceived(WebSocketContext context, string msg)
        {
            //Console.WriteLine($"websocket recv: {msg}");
            var offerSDP = SDP.ParseSDPDescription(msg);

            Console.WriteLine($"offer sdp: {offerSDP}");

            var webRtcSession = new WebRtcSession(
                AddressFamily.InterNetwork,
                DTLS_CERTIFICATE_FINGERPRINT,
                null,
                null);

            webRtcSession.setRemoteDescription(new RTCSessionDescription {
                sdp = offerSDP, type = RTCSdpType.offer
            });

            webRtcSession.OnReceiveReport     += RtpSession_OnReceiveReport;
            webRtcSession.OnSendReport        += RtpSession_OnSendReport;
            webRtcSession.OnRtpPacketReceived += RtpSession_OnRtpPacketReceived;
            webRtcSession.OnClose             += (reason) =>
            {
                Console.WriteLine($"webrtc session closed: {reason}");
                _webRtcSessions.Remove(webRtcSession);
            };

            // Add local recvonly tracks. This ensures that the SDP answer includes only
            // the codecs we support.
            MediaStreamTrack audioTrack = new MediaStreamTrack(null, SDPMediaTypesEnum.audio, false, new List <SDPMediaFormat> {
                new SDPMediaFormat(SDPMediaFormatsEnum.PCMU)
            });

            audioTrack.Transceiver.SetStreamStatus(MediaStreamStatusEnum.RecvOnly);
            webRtcSession.addTrack(audioTrack);
            MediaStreamTrack videoTrack = new MediaStreamTrack(null, SDPMediaTypesEnum.video, false, new List <SDPMediaFormat> {
                new SDPMediaFormat(SDPMediaFormatsEnum.VP8)
            });

            videoTrack.Transceiver.SetStreamStatus(MediaStreamStatusEnum.RecvOnly);
            webRtcSession.addTrack(videoTrack);

            var answerSdp = await webRtcSession.createAnswer();

            webRtcSession.setLocalDescription(new RTCSessionDescription {
                sdp = answerSdp, type = RTCSdpType.answer
            });

            Console.WriteLine($"answer sdp: {answerSdp}");

            context.WebSocket.Send(answerSdp.ToString());

            if (DoDtlsHandshake(webRtcSession))
            {
                _webRtcSessions.Add(webRtcSession);
            }
            else
            {
                webRtcSession.Close("dtls handshake failed.");
            }
        }
Beispiel #2
0
 private static void SDPAnswerReceived(WebRtcSession webRtcSession, string sdpAnswer)
 {
     try
     {
         logger.LogDebug("Answer SDP: " + sdpAnswer);
         var answerSDP = SDP.ParseSDPDescription(sdpAnswer);
         webRtcSession.setRemoteDescription(SdpType.answer, answerSDP);
     }
     catch (Exception excp)
     {
         logger.LogError("Exception SDPAnswerReceived. " + excp.Message);
     }
 }
Beispiel #3
0
        private static void SDPAnswerReceived(WebRtcSession webRtcSession, string sdpAnswer)
        {
            try
            {
                Log.LogDebug("Answer SDP: " + sdpAnswer);

                var answerSDP = SDP.ParseSDPDescription(sdpAnswer);
                webRtcSession.setRemoteDescription(new RTCSessionDescription {
                    type = RTCSdpType.answer, sdp = answerSDP
                });

                // Forward audio samples from the SIP session to the WebRTC session (one way).
                //OnMediaFromSIPSampleReady += webRtcSession.SendMedia;
            }
            catch (Exception excp)
            {
                Log.LogError("Exception SDPAnswerReceived. " + excp.Message);
            }
        }