Beispiel #1
0
        private void ConnectWebSocket()
        {
            // Continuously attempt connections to Lavalink
            Task.Run(async() =>
            {
                while (!webSocket.IsConnected())
                {
                    if (lavalinkCancellation.IsCancellationRequested)
                    {
                        break;
                    }

                    try
                    {
                        await webSocket.Connect();
                    }
                    catch (Exception ex)
                    {
                        connectionWait = connectionWait + 3000;
                        Console.WriteLine(new LogMessage(LogSeverity.Info, "Lavalink", "Failed to connect to Lavalink node. Waiting " + connectionWait / 1000 + " seconds", ex));
                    }

                    if (!webSocket.IsConnected())
                    {
                        connectionWait = connectionWait + 3000;
                        Console.WriteLine(new LogMessage(LogSeverity.Info, "Lavalink", "Failed to connect to Lavalink node. Waiting " + connectionWait / 1000 + " seconds"));
                    }

                    await Task.Delay(connectionWait);
                }
            });
        }
Beispiel #2
0
        private void ConnectWebSocket()
        {
            // Continuously attempt connections to Lavalink
            Task.Run(async() =>
            {
                while (!webSocket.IsConnected())
                {
                    if (lavalinkCancellation.IsCancellationRequested)
                    {
                        break;
                    }

                    try
                    {
                        await webSocket.Connect();
                    }
                    catch (Exception ex)
                    {
                        logger.Log("An exception occured while opening the WebSocket connection", LogSeverity.Debug, ex);
                    }
                    finally
                    {
                        if (!webSocket.IsConnected())
                        {
                            // Please no really long connection waits :(
                            if (connectionWait < 30000)
                            {
                                connectionWait = connectionWait + 3000;
                            }
                            logger.Log($"Failed to connect to Lavalink node at {webSocket.GetHostUri()}", LogSeverity.Warning);
                            logger.Log($"Waiting {connectionWait / 1000} seconds before reconnecting", LogSeverity.Warning);
                        }
                    }

                    await Task.Delay(connectionWait);
                }
            });
        }