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..."); Dtls.InitialiseOpenSSL(); Srtp.InitialiseLibSrtp(); Task.Run(SendTestPattern); // 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(); }
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..."); Dtls.InitialiseOpenSSL(); Srtp.InitialiseLibSrtp(); // Initialise the Media Foundation library that will pull the samples from the mp4 file. _mfSampleGrabber = new SIPSorceryMedia.MFSampleGrabber(); _mfSampleGrabber.OnClockStartEvent += OnClockStartEvent; _mfSampleGrabber.OnVideoResolutionChangedEvent += OnVideoResolutionChangedEvent; unsafe { _mfSampleGrabber.OnProcessSampleEvent += OnProcessSampleEvent; } Task.Run(() => _mfSampleGrabber.Run(MP4_FILE_PATH, true)); // Hook up event handlers to send the media samples to the network. //InitMediaToWebRtcClients(); // 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(); _mfSampleGrabber.StopAndExit(); _webSocketServer.Stop(); }