Example #1
0
 public async Task StopConnection()
 {
     await Task.Run(() =>
     {
         token?.Cancel();
         connection?.Stop();
     });
 }
Example #2
0
 public void Disconnect()
 {
     Connection.Stop();
 }
Example #3
0
        static void Main(string[] args)
        {
            Initialize();

            Connection.OpenPlayback();
            Console.WriteLine($"Playback: {Connection.PlaybackDevice}");
            Connection.OpenCapture();
            Console.WriteLine($"Capture: {Connection.CaptureDevice}");

            string identity = ReadIdentity() ?? Library.CreateIdentity();
            Task   starting = Connection.Start(identity, "localhost", 9987, "client", serverPassword: "******");

            Console.WriteLine("Client lib initialized and running");
            Console.WriteLine($"Client lib version: {Library.Version}({Library.VersionNumber})");

            try
            {
                starting.Wait();
            }
            catch (AggregateException e)
            {
                if (e.InnerException is TeamSpeakException)
                {
                    Error errorCode = ((TeamSpeakException)e.InnerException).ErrorCode;
                    Console.WriteLine("Failed to connect to server: {0}", errorCode);
                    return;
                }
                else
                {
                    throw;
                }
            }
            Console.WriteLine();
            Console.WriteLine("TeamSpeak 3 client commandline interface");
            ShowHelp();

            do
            {
                string line = Console.ReadLine();
                if (line.Length != 1)
                {
                    continue;
                }
                char     c    = line[0];
                MenuItem item = Menu.FirstOrDefault(i => i.Key == c);
                if (item != null)
                {
                    try
                    {
                        item.Method();
                    }
                    catch (TeamSpeakException e)
                    {
                        Console.WriteLine($"Error in {item.Method.Method.Name}: {e.Message} ({e.ErrorCode})");
                    }
                }
            }while (Abort == false);

            Connection.IsVoiceRecording = false;
            Speakers channelFillMask = (Speakers)0;

            Connection_EditMixedPlaybackVoiceData(Connection, null, 0, null, ref channelFillMask);
            Connection.Stop();
        }
Example #4
0
 public void Stop()
 {
     Connection.Stop();
 }
Example #5
0
 /**
  * Stops the connection.
  *
  * No more frames or other events are received from a stopped connection. You can
  * restart with StartConnection().
  *
  * @since 3.0
  */
 public void StopConnection()
 {
     _connection.Stop();
 }
Example #6
0
 public void Dispose()
 {
     Connection?.Stop();
     Connection?.Dispose();
 }
        private void PollingLoop(Connection connection, string data, Action initializeCallback, Action<Exception> errorCallback, bool raiseReconnect = false)
        {
            string url = connection.Url;
            var reconnectTokenSource = new CancellationTokenSource();
            int reconnectFired = 0;

            if (connection.MessageId == null)
            {
                url += "connect";
            }

            url += GetReceiveQueryString(connection, data);

            HttpHelper.PostAsync(url, PrepareRequest(connection)).ContinueWith(task =>
            {
                // Clear the pending request
                connection.Items.Remove(HttpRequestKey);

                bool shouldRaiseReconnect = false;
                bool disconnectedReceived = false;

                try
                {
                    if (!task.IsFaulted)
                    {
                        if (raiseReconnect)
                        {
                            // If the timeout for the reconnect hasn't fired as yet just fire the 
                            // event here before any incoming messages are processed
                            FireReconnected(connection, reconnectTokenSource, ref reconnectFired);
                        }

                        // Get the response
                        var raw = task.Result.ReadAsString();

                        ProcessResponse(connection, raw, out shouldRaiseReconnect, out disconnectedReceived);
                    }
                }
                finally
                {
                    if (disconnectedReceived)
                    {
                        connection.Stop();
                    }
                    else
                    {
                        bool requestAborted = false;
                        bool continuePolling = true;

                        if (task.IsFaulted)
                        {
                            // Cancel the previous reconnect event
                            reconnectTokenSource.Cancel();

                            // Raise the reconnect event if we successfully reconnect after failing
                            shouldRaiseReconnect = true;

                            // Get the underlying exception
                            Exception exception = task.Exception.GetBaseException();

                            // If the error callback isn't null then raise it and don't continue polling
                            if (errorCallback != null)
                            {
                                // Raise on error
                                connection.OnError(exception);

                                // Call the callback
                                errorCallback(exception);

                                // Don't continue polling if the error is on the first request
                                continuePolling = false;
                            }
                            else
                            {
                                // Figure out if the request was aborted
                                requestAborted = IsRequestAborted(exception);

                                // Sometimes a connection might have been closed by the server before we get to write anything
                                // so just try again and don't raise OnError.
                                if (!requestAborted && !(exception is IOException))
                                {
                                    // Raise on error
                                    connection.OnError(exception);

                                    // If the connection is still active after raising the error event wait for 2 seconds
                                    // before polling again so we aren't hammering the server
                                    if (connection.IsActive)
                                    {
                                        Thread.Sleep(2000);
                                    }
                                }
                            }
                        }

                        // Only continue if the connection is still active and wasn't aborted
                        if (continuePolling && !requestAborted && connection.IsActive)
                        {
                            PollingLoop(connection, data, null, null, shouldRaiseReconnect);
                        }
                    }
                }
            });

            if (initializeCallback != null)
            {
                initializeCallback();
            }

            if (raiseReconnect)
            {
                TaskAsyncHelper.Delay(ReconnectDelay).Then(() =>
                {
                    // Fire the reconnect event after the delay. This gives the 
                    FireReconnected(connection, reconnectTokenSource, ref reconnectFired);
                });
            }
        }
Example #8
0
 public Task Stop()
 {
     _disconnecting = true;
     Connection.Stop();
     return(Task.FromResult(true));
 }
 private void Connection_Error(Exception ex)
 {
     Connection.Stop();
     HubConnectionErrorFired?.Invoke(this, new HubConnectionErrorFiredEventArgs(DateTime.Now, ex, Connection));
 }
Example #10
0
 public void Stop()
 {
     Host.Disconnect();
     Connection.Stop();
 }
Example #11
0
 public void StopConnection()
 {
     _streamingConnection.Stop();
 }
Example #12
0
 protected override void StopProcessing()
 {
     _cancellationTokenSource.Cancel();
     connection.Stop();
     connection.Dispose();
 }
Example #13
0
 public override void Stop()
 {
     stopping = true;
     Connection?.Stop();
 }
Example #14
0
 private void OnWindowClosing(object sender, CancelEventArgs e)
 {
     ((Kinect)controlDevices[2]).Stop();
     connection?.Stop();
     connection?.CloseUdp();
 }
Example #15
0
        public void Start()
        {
            Initialize();

            Connection.OpenPlayback();
            Console.WriteLine($"Playback: {Connection.PlaybackDevice}");
            Connection.OpenCapture();
            Console.WriteLine($"Capture: {Connection.CaptureDevice}");

            string identity = ReadIdentity();

            if (identity == null)
            {
                identity = Library.CreateIdentity();
                // Write the identity to a file
                WriteIdentity(identity);
            }

            Task starting = Connection.Start(
                identity,
                Properties.Settings.Default.ServerIP,
                Convert.ToUInt32(Properties.Settings.Default.ServerPort),
                Properties.Settings.Default.Username,
                serverPassword: Properties.Settings.Default.ServerPassword
                );

            Console.WriteLine("Client lib initialized and running");
            Console.WriteLine($"Client lib version: {Library.Version}({Library.VersionNumber})");

            try
            {
                starting.Wait();
            }
            catch (AggregateException e)
            {
                if (e.InnerException is TeamSpeakException)
                {
                    Error errorCode = ((TeamSpeakException)e.InnerException).ErrorCode;
                    Console.WriteLine("Failed to connect to server: {0}", errorCode);
                    return;
                }
                else
                {
                    throw;
                }
            }

            // Subscribe to all channels
            Connection.SubscribeAll();

            // Set input preprocessor values
            EnableEchoCanceling(false);
            EnableAGC(true);

            if (Properties.Settings.Default.Properties["VADLevel"] != null)
            {
                //Hooray, we found it!
                SetVADLevel(Properties.Settings.Default.VADLevel);
            }
            else
            {
                //This is a 'no go'
            }

            // Allow whispers from all clients
            foreach (Client client in Connection.AllClients)
            {
                Connection.AllowWhispersFrom(client);
            }

            Console.WriteLine();
            Console.WriteLine("TeamSpeak 3 client commandline interface");
            ShowHelp();

            do
            {
                string line = Console.ReadLine();
                if (line.Length != 1)
                {
                    continue;
                }
                char     c    = line[0];
                MenuItem item = Menu.FirstOrDefault(i => i.Key == c);
                if (item != null)
                {
                    try
                    {
                        item.Method();
                    }
                    catch (TeamSpeakException e)
                    {
                        Console.WriteLine($"Error in {item.Method.Method.Name}: {e.Message} ({e.ErrorCode})");
                    }
                }
            }while (Abort == false);

            Connection.IsVoiceRecording = false;
            Speakers channelFillMask = (Speakers)0;

            Connection_EditMixedPlaybackVoiceData(Connection, null, 0, null, ref channelFillMask);
            Connection.Stop();
        }
Example #16
0
            public void ConnectionCanStartWithAuthenicatedUserAndQueryString()
            {
                using (var host = new MemoryHost())
                {
                    host.Configure(app =>
                    {
                        Func<AppFunc, AppFunc> middleware = (next) =>
                        {
                            return env =>
                            {
                                if (((string)env["owin.RequestQueryString"]).IndexOf("access_token") == -1)
                                {
                                    return next(env);
                                }

                                var user = new CustomPrincipal
                                {
                                    Name = "Bob",
                                    IsAuthenticated = true,
                                    Roles = new[] { "User" }
                                };

                                env["server.User"] = user;

                                return next(env);
                            };
                        };

                        app.Use(middleware);
                        app.MapConnection<MyAuthenticatedConnection>("/authenticatedConnection", new ConnectionConfiguration());

                    });

                    var connection = new Connection("http://foo/authenticatedConnection", "access_token=1234");

                    connection.Start(host).Wait();

                    Assert.Equal(connection.State, ConnectionState.Connected);

                    connection.Stop();
                }
            }
Example #17
0
 public void Dispose()
 {
     _connection.Stop();
 }
Example #18
0
    public Task StopAsync(CancellationToken cancellationToken)
    {
        _logger.LogInformation("Stopping");

        return(_connection.Stop(cancellationToken));
    }
Example #19
0
 /// <summary>
 /// Temporarily stops a connection's delivery of incoming messages.
 /// </summary>
 public void Stop()
 {
     nativeConnection.Stop();
 }
Example #20
0
 /// <summary>
 ///
 /// </summary>
 private void Stop()
 {
     _connection.Stop();
     CanTryToConnect = true;
 }