private async Task VerifyConnectionAsync(VoiceUpdatePacket packet, Task task) { if (task.VerifyTask()) { LogHandler <WsVoiceClient> .Log.Error(exception : task.Exception); return; } _receiveTask = _socket .ReceiveAsync <WsVoiceClient, BaseDiscordPayload>(_receiveCancel, ProcessPayloadAsync) .ContinueWith(DisposeAsync); var payload = new BaseDiscordPayload(VoiceOpType.Identify, new IdentifyPayload { ServerId = $"{packet.GuildId}", SessionId = packet.SessionId, UserId = $"{packet.UserId}", Token = packet.Token }); await _socket.SendAsync(payload) .ConfigureAwait(false); }
public async Task HandleVoiceUpdateAsync(VoiceUpdatePacket voiceUpdate) { if (_socket != null && _socket.State == WebSocketState.Open && _hostName != voiceUpdate.EndPoint) { await _socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Changing voice server.", CancellationToken.None) .ConfigureAwait(false); } try { _hostName = voiceUpdate.EndPoint; var url = $"wss://{voiceUpdate.EndPoint}" .WithParameter("encoding", "json") .WithParameter("v", "4") .ToUrl(); await _socket.ConnectAsync(url, _mainCancel.Token) .ContinueWith(x => VerifyConnectionAsync(voiceUpdate, x)) .ConfigureAwait(false); } catch { // Ignore } }