Exemple #1
0
        public void RtcConnect()
        {
            try
            {
                //if (!_SocketClient.IsAlive) return;
                //RtcInitial();

                Task.Run(() =>
                {
                    var ok = _WebRtc.InitializePeerConnection();
                    if (ok)
                    {
                        _WebRtc.CreateOffer();
                        while (_WebRtc.ProcessMessages(3))
                        {
                        }
                        _WebRtc.ProcessMessages(3);
                    }
                    else
                    {
                        Debug.WriteLine("InitializePeerConnection failed");
                    }
                });
            }
            catch (Exception ex)
            {
            }
        }
Exemple #2
0
        private void checkBoxTurn_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxTurn.Checked)
            {
                var ui = TaskScheduler.FromCurrentSynchronizationContext();

                Task.Factory.StartNew(delegate()
                {
                    using (var mc = new WebRtcNative())
                    {
                        var ok = mc.RunTurnServer("0.0.0.0:3478", textBoxExtIP.Text, "test", "auth.txt");
                        if (!ok)
                        {
                            Task.Factory.StartNew(delegate()
                            {
                                MessageBox.Show("TURN server start failed ;/");
                            }, CancellationToken.None, TaskCreationOptions.None, ui);
                        }
                        else
                        {
                            using (turnCancel = new CancellationTokenSource())
                            {
                                var stop = turnCancel.Token;
                                while (!stop.IsCancellationRequested && mc.ProcessMessages(1000))
                                {
                                    Debug.WriteLine(".");
                                }

                                Task.Factory.StartNew(delegate()
                                {
                                    MessageBox.Show("TURN server stoped.");
                                }, CancellationToken.None, TaskCreationOptions.None, ui);
                            }
                        }
                    }
                }, TaskCreationOptions.LongRunning);
            }
            else
            {
                if (turnCancel != null && !turnCancel.IsCancellationRequested)
                {
                    turnCancel.Cancel();
                    turnCancel           = null;
                    checkBoxTurn.Enabled = false; // after dispose it fails to start again wtf?.. ;/
                }
            }
        }