Example #1
0
        /// <summary>
        /// Establish a connection with the Mumble server
        /// </summary>
        /// <param name="userName">Username of Mumble client</param>
        /// <param name="password">Password for authenticating with server</param>
        /// <returns>Empty task</returns>
        public async Task ConnectAsync(string userName, string password)
        {
            if (this.Connected)
            {
                return;
            }

            this.cancellationTokenSource = new CancellationTokenSource();
            this.connection = this.connectionFactory.CreateConnection(this.ServerInfo.HostName, this.ServerInfo.Port);
            await this.connection.ConnectAsync().ConfigureAwait(false);

            await this.SendMessageAsync(new Messages.Version.Builder
            {
                Version_  = ClientMumbleVersion.EncodeVersion(),
                Release   = string.Format(CultureInfo.InvariantCulture, "Mumble.NET {0}", Assembly.GetExecutingAssembly().GetName().Version),
                Os        = Environment.OSVersion.Platform.ToString(),
                OsVersion = Environment.OSVersion.VersionString,
            }).ConfigureAwait(false);

            await this.SendMessageAsync(new Authenticate.Builder
            {
                Username = userName,
                Password = password,
                Opus     = true,
            }).ConfigureAwait(false);

            await this.StartLoopingTaskAsync(() => !this.Connected, this.ReadMessageAsync).ConfigureAwait(false);

            this.readTask = this.StartLoopingTaskAsync(() => true, this.ReadMessageAsync);
            this.pingTask = this.StartLoopingTaskAsync(() => true, this.SendPingAsync);
        }