static void Main() { Console.WriteLine("WebRTC Server Sample Program"); Console.WriteLine("Press ctrl-c to exit."); // Plumbing code to facilitate a graceful exit. CancellationTokenSource exitCts = new CancellationTokenSource(); // Cancellation token to stop the SIP transport and RTP stream. ManualResetEvent exitMre = new ManualResetEvent(false); AddConsoleLogger(); if (!File.Exists(MP4_FILE_PATH)) { throw new ApplicationException($"The media file at does not exist at {MP4_FILE_PATH}."); } // Initialise OpenSSL & libsrtp, saves a couple of seconds for the first client connection. Console.WriteLine("Initialising OpenSSL and libsrtp..."); DtlsHandshake.InitialiseOpenSSL(); Srtp.InitialiseLibSrtp(); Task.Run(DoDtlsHandshakeLoopbackTest).Wait(); Console.WriteLine("Test DTLS handshake complete."); _mediaSource = new MediaSource(); _mediaSource.Init(MP4_FILE_PATH, true); //_mediaSource.Init(0, 0, VideoSubTypesEnum.I420, 640, 480); // Start web socket. Console.WriteLine("Starting web socket server..."); _webSocketServer = new WebSocketServer(IPAddress.Any, WEBSOCKET_PORT, true); _webSocketServer.SslConfiguration.ServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(WEBSOCKET_CERTIFICATE_PATH); _webSocketServer.SslConfiguration.CheckCertificateRevocation = false; //_webSocketServer.Log.Level = WebSocketSharp.LogLevel.Debug; _webSocketServer.AddWebSocketService <SDPExchange>("/", (sdpExchanger) => { sdpExchanger.WebSocketOpened += SendSDPOffer; sdpExchanger.SDPAnswerReceived += SDPAnswerReceived; }); _webSocketServer.Start(); Console.WriteLine($"Waiting for browser web socket connection to {_webSocketServer.Address}:{_webSocketServer.Port}..."); // Ctrl-c will gracefully exit the call at any point. Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; exitMre.Set(); }; // Wait for a signal saying the call failed, was cancelled with ctrl-c or completed. exitMre.WaitOne(); _mediaSource.Shutdown(); _webSocketServer.Stop(); }
public Task StartAsync(CancellationToken cancellationToken) { _logger.LogDebug("WebRTCHostedService StartAsync."); // Initialise OpenSSL & libsrtp, saves a couple of seconds for the first client connection. _logger.LogDebug("Initialising OpenSSL and libsrtp..."); DtlsHandshake.InitialiseOpenSSL(); Srtp.InitialiseLibSrtp(); return(Task.CompletedTask); }
static void Main() { Console.WriteLine("WebRTC Server Sample Program"); Console.WriteLine("Press ctrl-c to exit."); // Plumbing code to facilitate a graceful exit. CancellationTokenSource exitCts = new CancellationTokenSource(); // Cancellation token to stop the SIP transport and RTP stream. ManualResetEvent exitMre = new ManualResetEvent(false); AddConsoleLogger(); // Initialise OpenSSL & libsrtp, saves a couple of seconds for the first client connection. Console.WriteLine("Initialising OpenSSL and libsrtp..."); DtlsHandshake.InitialiseOpenSSL(); Srtp.InitialiseLibSrtp(); InitialiseTestPattern(); // Start web socket. Console.WriteLine("Starting web socket server..."); _webSocketServer = new WebSocketServer(IPAddress.Any, WEBSOCKET_PORT, true); _webSocketServer.SslConfiguration.ServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(WEBSOCKET_CERTIFICATE_PATH); _webSocketServer.SslConfiguration.CheckCertificateRevocation = false; //_webSocketServer.Log.Level = WebSocketSharp.LogLevel.Debug; _webSocketServer.AddWebSocketService <SDPExchange>("/", (sdpExchanger) => { sdpExchanger.WebSocketOpened += SendSDPOffer; sdpExchanger.OnMessageReceived += WebSocketMessageReceived; }); _webSocketServer.Start(); Console.WriteLine($"Waiting for browser web socket connection to {_webSocketServer.Address}:{_webSocketServer.Port}..."); // Ctrl-c will gracefully exit the call at any point. Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; _sendTestPatternTimer?.Dispose(); exitMre.Set(); }; // Wait for a signal saying the call failed, was cancelled with ctrl-c or completed. exitMre.WaitOne(); }
public async Task Start(CancellationToken ct) { try { AddConsoleLogger(); logger.LogDebug("WebRTCDaemon starting."); var wssCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(_webSocketCertificatePath, _webSocketCertificatePassword); logger.LogDebug("Web Socket Server Certificate: " + wssCertificate.Subject + ", have key " + wssCertificate.HasPrivateKey + ", Expires " + wssCertificate.GetExpirationDateString() + "."); logger.LogDebug($"DTLS certificate thumbprint {_dtlsCertificateThumbprint}."); logger.LogDebug($"Web socket port {_webSocketPort}."); if (!File.Exists(_mediaFilePath)) { throw new ApplicationException($"The media file at does not exist at {_mediaFilePath}."); } // Initialise OpenSSL & libsrtp, saves a couple of seconds for the first client connection. Console.WriteLine("Initialising OpenSSL and libsrtp..."); DtlsHandshake.InitialiseOpenSSL(); Srtp.InitialiseLibSrtp(); Task.Run(DoDtlsHandshakeLoopbackTest).Wait(); Console.WriteLine("Test DTLS handshake complete."); // Configure the web socket and the different end point handlers. int webSocketPort = (!String.IsNullOrEmpty(_webSocketPort)) ? Int32.Parse(_webSocketPort) : DEFAULT_WEB_SOCKET_PORT; _webSocketServer = new WebSocketServer(IPAddress.Any, webSocketPort, true); _webSocketServer.SslConfiguration.ServerCertificate = wssCertificate; _webSocketServer.SslConfiguration.CheckCertificateRevocation = false; // Standard encrypted WebRtc stream. _webSocketServer.AddWebSocketService <SDPExchange>("/max", (sdpReceiver) => { sdpReceiver.MediaSource = MediaSourceEnum.Max; sdpReceiver.WebSocketOpened += WebRtcStartCall; sdpReceiver.SDPAnswerReceived += WebRtcAnswerReceived; }); if (!String.IsNullOrEmpty(_testPatternImagePath) && File.Exists(_testPatternImagePath)) { _webSocketServer.AddWebSocketService <SDPExchange>("/testpattern", (sdpReceiver) => { sdpReceiver.MediaSource = MediaSourceEnum.TestPattern; sdpReceiver.WebSocketOpened += WebRtcStartCall; sdpReceiver.SDPAnswerReceived += WebRtcAnswerReceived; }); } _webSocketServer.Start(); Console.WriteLine($"Waiting for browser web socket connection to {_webSocketServer.Address}:{_webSocketServer.Port}..."); // Initialise the Media Foundation library that will pull the samples from the mp4 file. _mediaSource = new MediaSource(); _mediaSource.Init(_mediaFilePath, true); _ = Task.Run(ExpireConnections); while (!ct.IsCancellationRequested) { await Task.Delay(1000); } } catch (Exception excp) { logger.LogError("Exception WebRTCDaemon.Start. " + excp); } finally { Stop(); } }
static async Task Main() { Console.WriteLine("WebRTC No Signalling Server Sample Program"); Console.WriteLine("Press ctrl-c to exit."); // Plumbing code to facilitate a graceful exit. CancellationTokenSource exitCts = new CancellationTokenSource(); // Cancellation token to stop the SIP transport and RTP stream. ManualResetEvent exitMre = new ManualResetEvent(false); AddConsoleLogger(); // Initialise OpenSSL & libsrtp, saves a couple of seconds for the first client connection. Console.WriteLine("Initialising OpenSSL and libsrtp..."); DtlsHandshake.InitialiseOpenSSL(); Srtp.InitialiseLibSrtp(); InitialiseTestPattern(); Console.WriteLine($"Starting Peer Connection..."); var pc = await StartPeerConnection(); // Start the DTLS task before entering the ICE credentials to avoid DTLS client Hello retransmits. // Start the DTLS task immediately so that we are ready to receive the client Hello. // If it's missed it can take 10 or more seconds for the peer to retry. var dtlsTask = DoDtlsHandshake(pc); // Ctrl-c will gracefully exit the call at any point. Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; _sendTestPatternTimer?.Dispose(); exitMre.Set(); }; Console.WriteLine("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"); Console.WriteLine("THE SDP OFFER ABOVE NEEDS TO BE PASTED INTO YOUR BROWSER"); Console.WriteLine(); Console.WriteLine("Press enter when you the SDP answer is available and then enter the ICE username and password..."); Console.ReadLine(); Console.Write("Enter the remote peer ICE User (e.g. for 'a=ice-ufrag:tGXy' enter tGXy) => "); var remoteIceUser = Console.ReadLine(); Console.Write("Enter the remote peer ICE Password (e.g. for 'a=ice-pwd:Icew1/BpwUIJLn2dBMbQyYPB' enter Icew1/BpwUIJLn2dBMbQyYPB) => "); var remoteIcePassword = Console.ReadLine(); pc.SetRemoteCredentials(remoteIceUser, remoteIcePassword); var dtlsResult = await dtlsTask; logger.LogDebug($"dtls handshake result {dtlsResult}."); if (dtlsResult) { var remoteEP = pc.AudioDestinationEndPoint; pc.SetDestination(SDPMediaTypesEnum.audio, remoteEP, remoteEP); } else { pc.Close("dtls handshake failed."); } // Wait for a signal saying the call failed, was cancelled with ctrl-c or completed. exitMre.WaitOne(); pc.Close("normal"); }
static void Main() { Console.WriteLine("ICE Console Test Program"); Console.WriteLine("Press ctrl-c to exit."); if (!File.Exists(DTLS_CERTIFICATE_PATH)) { throw new ApplicationException($"The DTLS certificate file could not be found at {DTLS_CERTIFICATE_PATH}."); } else if (!File.Exists(DTLS_KEY_PATH)) { throw new ApplicationException($"The DTLS key file could not be found at {DTLS_KEY_PATH}."); } // Plumbing code to facilitate a graceful exit. CancellationTokenSource exitCts = new CancellationTokenSource(); // Cancellation token to stop the SIP transport and RTP stream. ManualResetEvent exitMre = new ManualResetEvent(false); AddConsoleLogger(); // Initialise OpenSSL & libsrtp, saves a couple of seconds for the first client connection. Console.WriteLine("Initialising OpenSSL and libsrtp..."); DtlsHandshake.InitialiseOpenSSL(); Srtp.InitialiseLibSrtp(); Task.Run(DoDtlsHandshakeLoopbackTest).Wait(); Console.WriteLine("Test DTLS handshake complete."); // Start web socket. Console.WriteLine("Starting web socket server..."); _webSocketServer = new WebSocketServer(IPAddress.Any, WEBSOCKET_PORT, true); _webSocketServer.SslConfiguration.ServerCertificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(WEBSOCKET_CERTIFICATE_PATH); _webSocketServer.SslConfiguration.CheckCertificateRevocation = false; //_webSocketServer.Log.Level = WebSocketSharp.LogLevel.Debug; _webSocketServer.AddWebSocketService <WebRtcClient>("/sendoffer", (client) => { client.WebSocketOpened += SendOffer; client.OnMessageReceived += WebSocketMessageReceived; }); _webSocketServer.AddWebSocketService <WebRtcClient>("/receiveoffer", (client) => { client.WebSocketOpened += ReceiveOffer; client.OnMessageReceived += WebSocketMessageReceived; }); _webSocketServer.Start(); Console.WriteLine($"Waiting for browser web socket connection to {_webSocketServer.Address}:{_webSocketServer.Port}..."); // Ctrl-c will gracefully exit the call at any point. Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; exitMre.Set(); }; // Wait for a signal saying the call failed, was cancelled with ctrl-c or completed. exitMre.WaitOne(); _webSocketServer.Stop(); }