public async Task <bool> ConnectVoiceChannel(SocketVoiceChannel voiceChannel) { await DisconnectCurrentVoiceChannel(); if (voiceChannel == null) { throw new ArgumentNullException("VoiceChannel is null"); } CurrentVoiceChannel = voiceChannel; // ボイスチャンネルへの接続を開始 // 音声の送信はConnectedイベント後 // 受信はStreamCreatedイベント後に行われます using (var releaser = await _VoiceChannelLock.LockAsync()) { await voiceChannel.ConnectAsync((client) => { _CurrentVoiceAudioClient = client; client.Connected += VoiceChannelConnected; client.Disconnected += VoiceChannelDisconnected; client.LatencyUpdated += VoiceChannelLatencyUpdated; client.SpeakingUpdated += VoiceChannelSpeakingUpdated; client.StreamCreated += VoiceChannelAudioStreamCreated; client.StreamDestroyed += VoiceChannelAudioStreamDestroyed; }); CurrentVoiceChannel = voiceChannel; ConnectState = UncordChannelConnectState.Connected; } return(true); }
public async Task DisconnectCurrentVoiceChannel() { using (var releaser = await _VoiceChannelLock.LockAsync()) { if (_CurrentVoiceAudioClient != null) { _CurrentVoiceAudioClient.Dispose(); _CurrentVoiceAudioClient = null; } CurrentVoiceChannel = null; ConnectState = UncordChannelConnectState.NotConnect; } }
private async Task VoiceChannelAudioStreamDestroyed(ulong arg) { AudioManager.StopAudioOutput(); // using (var releaser = await _VoiceChannelLock.LockAsync()) { if (IsConnectedVoiceChannel) { // TODO: 意図しない切断の場合 ボイスチャンネルに再接続する ConnectState = UncordChannelConnectState.Disconnected; } } await Task.Delay(0); }