Exemple #1
0
        /// <summary>
        /// 连接对方并保持
        /// </summary>
        /// <returns></returns>
        private async Task connectAsync()
        {
            while (this._connecting())
            {
                if (this.connection == null)
                {
                    this.connection = new MediaConnection(this);
                }
                await Promise.Await(cs =>
                {
                    Action <string> stateChanged = null;
                    stateChanged = state =>
                    {
                        if (state != "closed")
                        {
                            return;
                        }
                        this.connection.StateChanged -= stateChanged;
                        cs();
                    };
                    this.connection.StateChanged += stateChanged;
                });

                this.connection = null;
            }
            this.Closed?.Invoke();
        }
Exemple #2
0
 /**
  * 连接对方并保持
  */
 public void connect()
 {
     this.connection = new MediaConnection(this);
     Task.Factory.StartNew(connectAsync);
 }