private async Task VoiceWS_SocketClosed(SocketCloseEventArgs e) { this.Discord.DebugLogger.LogMessage(LogLevel.Debug, "VoiceNext", $"Voice socket closed ({e.CloseCode.ToString(CultureInfo.InvariantCulture)}, '{e.CloseMessage}')", DateTime.Now); // generally this should not be disposed on all disconnects, only on requested ones // or something // otherwise problems happen //this.Dispose(); if (e.CloseCode == 4006 || e.CloseCode == 4009) { this.Resume = false; } if (!this.IsDisposed) { this.TokenSource.Cancel(); this.TokenSource = new CancellationTokenSource(); this.VoiceWs = BaseWebSocketClient.Create(); this.VoiceWs.OnDisconnect += this.VoiceWS_SocketClosed; this.VoiceWs.OnMessage += this.VoiceWS_SocketMessage; this.VoiceWs.OnConnect += this.VoiceWS_SocketOpened; await this.ConnectAsync().ConfigureAwait(false); } }
internal VoiceNextConnection(DiscordClient client, DiscordGuild guild, DiscordChannel channel, VoiceNextConfiguration config, VoiceServerUpdatePayload server, VoiceStateUpdatePayload state) { this.Discord = client; this.Guild = guild; this.Channel = channel; this.SSRCMap = new ConcurrentDictionary <uint, ulong>(); this._user_speaking = new AsyncEvent <UserSpeakingEventArgs>(this.Discord.EventErrorHandler, "USER_SPEAKING"); #if !NETSTANDARD1_1 this._voice_received = new AsyncEvent <VoiceReceiveEventArgs>(this.Discord.EventErrorHandler, "VOICE_RECEIVED"); #endif this._voice_socket_error = new AsyncEvent <SocketErrorEventArgs>(this.Discord.EventErrorHandler, "VOICE_WS_ERROR"); this.TokenSource = new CancellationTokenSource(); this.Configuration = config; this.Opus = new OpusCodec(48000, 2, this.Configuration.VoiceApplication); this.Sodium = new SodiumCodec(); this.Rtp = new RtpCodec(); this.UdpLatency = TimeSpan.FromMilliseconds(0.1); this.ServerData = server; this.StateData = state; var eps = this.ServerData.Endpoint; var epi = eps.LastIndexOf(':'); var eph = string.Empty; var epp = 80; if (epi != -1) { eph = eps.Substring(0, epi); epp = int.Parse(eps.Substring(epi + 1)); } else { eph = eps; } this.ConnectionEndpoint = new ConnectionEndpoint { Hostname = eph, Port = epp }; this.ReadyWait = new TaskCompletionSource <bool>(); this.IsInitialized = false; this.IsDisposed = false; this.PlayingWait = null; this.PlaybackSemaphore = new SemaphoreSlim(1, 1); this.UdpClient = BaseUdpClient.Create(); this.VoiceWs = BaseWebSocketClient.Create(); this.VoiceWs.OnDisconnect += this.VoiceWS_SocketClosed; this.VoiceWs.OnMessage += this.VoiceWS_SocketMessage; this.VoiceWs.OnConnect += this.VoiceWS_SocketOpened; this.VoiceWs.OnError += this.VoiceWs_SocketErrored; }
private async Task VoiceWS_SocketClosed(SocketCloseEventArgs e) { this.Discord.DebugLogger.LogMessage(LogLevel.Debug, "VoiceNext", $"Voice socket closed ({e.CloseCode.ToString(CultureInfo.InvariantCulture)}, '{e.CloseMessage}')", DateTime.Now); this.Dispose(); if (!this.IsDisposed) { this.VoiceWs = BaseWebSocketClient.Create(); this.VoiceWs.OnDisconnect += this.VoiceWS_SocketClosed; this.VoiceWs.OnMessage += this.VoiceWS_SocketMessage; this.VoiceWs.OnConnect += this.VoiceWS_SocketOpened; await this.StartAsync(); } }