static async Task Main(string[] args) { Console.WriteLine("WebRTC Client Test Console"); logger = AddConsoleLogger(); CancellationTokenSource cts = new CancellationTokenSource(); var nodeDssWebRTCPeer = new WebRTCNodeDssPeer(NODE_DSS_SERVER, NODE_DSS_MY_USER, NODE_DSS_THEIR_USER, CreatePeerConnection); await nodeDssWebRTCPeer.Start(cts); // Open a Window to display the video feed from the WebRTC peer. _form = new Form(); _form.AutoSize = true; _form.BackgroundImageLayout = ImageLayout.Center; _picBox = new PictureBox { Size = new Size(640, 480), Location = new Point(0, 0), Visible = true }; _form.Controls.Add(_picBox); Application.EnableVisualStyles(); Application.Run(_form); }
static async Task Main(string[] args) { Console.WriteLine("WebRTC Test Pattern Server Demo"); logger = AddConsoleLogger(); CancellationTokenSource cts = new CancellationTokenSource(); var parseResult = Parser.Default.ParseArguments <Options>(args); var options = (parseResult as Parsed <Options>)?.Value; if (options?.NodeDssServer == null) { // Start web socket. Console.WriteLine("Starting web socket server..."); var webSocketServer = new WebSocketServer(IPAddress.Any, WEBSOCKET_PORT); webSocketServer.AddWebSocketService <WebRTCWebSocketPeer>("/", (peer) => peer.CreatePeerConnection = CreatePeerConnection); webSocketServer.Start(); Console.WriteLine($"Waiting for web socket connections on {webSocketServer.Address}:{webSocketServer.Port}..."); Console.WriteLine("Press ctrl-c to exit."); } else { string[] fields = options.NodeDssServer.Split(';'); if (fields.Length < 3) { throw new ArgumentException("The 'nodedss' option must contain 3 semi-colon separated fields, e.g. --nodedss=http://127.0.0.1:3000;myid;theirid."); } Console.WriteLine($"Sending offer to node dss server at {fields[0]}, our ID={fields[1]}, their ID={fields[2]}."); var nodeDssPeer = new WebRTCNodeDssPeer(fields[0], fields[1], fields[2], CreatePeerConnection); await nodeDssPeer.Start(cts); Console.WriteLine($"Waiting for node DSS peer to connect..."); Console.WriteLine("Press ctrl-c to exit."); } // Ctrl-c will gracefully exit the call at any point. ManualResetEvent exitMre = new ManualResetEvent(false); Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; cts.Cancel(); exitMre.Set(); }; // Wait for a signal saying the call failed, was cancelled with ctrl-c or completed. exitMre.WaitOne(); }
// Start is called before the first frame update void Start() { rb = GetComponent <Rigidbody>(); count = 0; SetCountText(); winTextObject.SetActive(false); // Create the peer connection object and start the signalling. _pc = CreatePeerConnection(); _signaller = new WebRTCNodeDssPeer(NODE_DSS_SERVER, NODE_DSS_MY_USER, NODE_DSS_THEIR_USER, _pc); var videoStream = cam.CaptureStream(FRAME_WIDTH, FRAME_HEIGHT, MAX_BIT_RATE); _pc.AddTrack(videoStream.GetVideoTracks().First()); StartCoroutine(WebRTC.Update()); StartCoroutine(_signaller.Start()); }
private static async Task RunCommand(Options options, bool noOptions) { // 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); logger = AddConsoleLogger(); // Start MDNS server. var mdnsServer = new ServiceDiscovery(); if (options.StunServer != null) { string[] fields = options.StunServer.Split(';'); _stunServer = new RTCIceServer { urls = fields[0], username = fields.Length > 1 ? fields[1] : null, credential = fields.Length > 2 ? fields[2] : null, credentialType = RTCIceCredentialType.password }; } _relayOnly = options.RelayOnly; if (!string.IsNullOrEmpty(options.IceTypes)) { options.IceTypes.Split().ToList().ForEach(x => { if (Enum.TryParse <RTCIceCandidateType>(x, out var iceType)) { _iceTypes.Add(iceType); } }); if (!_iceTypes.Any(x => x == RTCIceCandidateType.host)) { _offerOptions = new RTCOfferOptions { X_ExcludeIceCandidates = true }; _answerOptions = new RTCAnswerOptions { X_ExcludeIceCandidates = true }; } } if (!string.IsNullOrEmpty(options.AcceptIceTypes)) { options.AcceptIceTypes.Split().ToList().ForEach(x => { if (Enum.TryParse <RTCIceCandidateType>(x, out var iceType)) { _acceptIceTypes.Add(iceType); } }); } if (options.UseWebSocket || options.UseSecureWebSocket || noOptions) { // Start web socket. Console.WriteLine("Starting web socket server..."); _webSocketServer = new WebSocketServer(IPAddress.Any, WEBSOCKET_PORT, options.UseSecureWebSocket); if (options.UseSecureWebSocket) { _webSocketServer.SslConfiguration.ServerCertificate = new X509Certificate2(LOCALHOST_CERTIFICATE_PATH); _webSocketServer.SslConfiguration.CheckCertificateRevocation = false; } _webSocketServer.AddWebSocketService <WebRTCWebSocketPeer>("/", (peer) => { peer.OfferOptions = _offerOptions; if (_acceptIceTypes != null && _acceptIceTypes.Count > 0) { peer.FilterRemoteICECandidates = (init) => _acceptIceTypes.Any(x => x == RTCIceCandidate.Parse(init.candidate).type); } peer.CreatePeerConnection = CreatePeerConnection; }); _webSocketServer.Start(); Console.WriteLine($"Waiting for browser web socket connection to {_webSocketServer.Address}:{_webSocketServer.Port}..."); } else if (!string.IsNullOrWhiteSpace(options.WebSocketServer)) { // We are the client for a web socket server. The JSON signalling exchange still occurs the same way as when the web socket // server option is used except that as the web socket client we receive the SDP offer from the server. WebRTCWebSocketClient wsockClient = new WebRTCWebSocketClient(options.WebSocketServer, CreatePeerConnection); await wsockClient.Start(exitCts.Token); Console.WriteLine("web socket client started."); } else if (options.CreateJsonOffer) { var pc = await Createpc(null, _stunServer, _relayOnly); var offerSdp = pc.createOffer(null); await pc.setLocalDescription(offerSdp); Console.WriteLine(offerSdp.sdp); var offerJson = JsonConvert.SerializeObject(offerSdp, new Newtonsoft.Json.Converters.StringEnumConverter()); var offerBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(offerJson)); Console.WriteLine(offerBase64); string remoteAnswerB64 = null; while (string.IsNullOrWhiteSpace(remoteAnswerB64)) { Console.Write("Remote Answer => "); remoteAnswerB64 = Console.ReadLine(); } string remoteAnswer = Encoding.UTF8.GetString(Convert.FromBase64String(remoteAnswerB64)); Console.WriteLine(remoteAnswer); RTCSessionDescriptionInit answerInit = JsonConvert.DeserializeObject <RTCSessionDescriptionInit>(remoteAnswer); Console.WriteLine($"Remote answer: {answerInit.sdp}"); var res = pc.setRemoteDescription(answerInit); if (res != SetDescriptionResultEnum.OK) { // No point continuing. Something will need to change and then try again. pc.Close("failed to set remote sdp"); } } else if (options.NodeDssServer != null) { string[] fields = options.NodeDssServer.Split(';'); if (fields.Length < 3) { throw new ArgumentException("The 'nodedss' option must contain 3 semi-colon separated fields, e.g. --nodedss=http://127.0.0.1:3000;myid;theirid."); } var nodeDssPeer = new WebRTCNodeDssPeer(fields[0], fields[1], fields[2], CreatePeerConnection); await nodeDssPeer.Start(exitCts); } _ = Task.Run(() => ProcessInput(exitCts)); // Ctrl-c will gracefully exit the call at any point. Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) { e.Cancel = true; exitCts.Cancel(); }; // Wait for a signal saying the call failed, was cancelled with ctrl-c or completed. exitCts.Token.WaitHandle.WaitOne(); Console.WriteLine(); Console.WriteLine("Exiting..."); _peerConnection?.Close("application exit"); _webSocketServer?.Stop(); Task.Delay(1000).Wait(); }
public Task Start() { return(_webrtcNodePeer.Start(_cts)); }