|
@@ -583,27 +583,34 @@ namespace Discord |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Voice |
|
|
//Voice |
|
|
#if !DNXCORE50 |
|
|
|
|
|
public Task JoinVoiceServer(string channelId) |
|
|
public Task JoinVoiceServer(string channelId) |
|
|
=> JoinVoiceServer(_channels[channelId]); |
|
|
=> JoinVoiceServer(_channels[channelId]); |
|
|
public async Task JoinVoiceServer(Channel channel) |
|
|
public async Task JoinVoiceServer(Channel channel) |
|
|
{ |
|
|
{ |
|
|
CheckReady(); |
|
|
CheckReady(); |
|
|
if (!_config.EnableVoice) throw new InvalidOperationException("Voice is not enabled for this client."); |
|
|
|
|
|
|
|
|
CheckVoice(); |
|
|
if (channel == null) throw new ArgumentNullException(nameof(channel)); |
|
|
if (channel == null) throw new ArgumentNullException(nameof(channel)); |
|
|
|
|
|
|
|
|
await LeaveVoiceServer(); |
|
|
await LeaveVoiceServer(); |
|
|
//_currentVoiceServerId = channel.ServerId; |
|
|
//_currentVoiceServerId = channel.ServerId; |
|
|
_webSocket.JoinVoice(channel); |
|
|
_webSocket.JoinVoice(channel); |
|
|
|
|
|
#if !DNXCORE50 |
|
|
await _voiceWebSocket.BeginConnect(); |
|
|
await _voiceWebSocket.BeginConnect(); |
|
|
|
|
|
#else |
|
|
|
|
|
await Task.CompletedTask; |
|
|
|
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async Task LeaveVoiceServer() |
|
|
public async Task LeaveVoiceServer() |
|
|
{ |
|
|
{ |
|
|
CheckReady(); |
|
|
CheckReady(); |
|
|
if (!_config.EnableVoice) throw new InvalidOperationException("Voice is not enabled for this client."); |
|
|
|
|
|
|
|
|
CheckVoice(); |
|
|
|
|
|
|
|
|
|
|
|
#if !DNXCORE50 |
|
|
await _voiceWebSocket.DisconnectAsync(); |
|
|
await _voiceWebSocket.DisconnectAsync(); |
|
|
|
|
|
#else |
|
|
|
|
|
await Task.CompletedTask; |
|
|
|
|
|
#endif |
|
|
//if (_voiceWebSocket.CurrentVoiceServerId != null) |
|
|
//if (_voiceWebSocket.CurrentVoiceServerId != null) |
|
|
_webSocket.LeaveVoice(); |
|
|
_webSocket.LeaveVoice(); |
|
|
} |
|
|
} |
|
@@ -615,35 +622,40 @@ namespace Discord |
|
|
public void SendVoicePCM(byte[] data, int count) |
|
|
public void SendVoicePCM(byte[] data, int count) |
|
|
{ |
|
|
{ |
|
|
CheckReady(); |
|
|
CheckReady(); |
|
|
if (!_config.EnableVoice) throw new InvalidOperationException("Voice is not enabled for this client."); |
|
|
|
|
|
|
|
|
CheckVoice(); |
|
|
if (count == 0) return; |
|
|
if (count == 0) return; |
|
|
|
|
|
|
|
|
if (_isDebugMode) |
|
|
if (_isDebugMode) |
|
|
RaiseOnDebugMessage(DebugMessageType.VoiceOutput, $"Queued {count} bytes for voice output."); |
|
|
RaiseOnDebugMessage(DebugMessageType.VoiceOutput, $"Queued {count} bytes for voice output."); |
|
|
|
|
|
#if !DNXCORE50 |
|
|
_voiceWebSocket.SendPCMFrame(data, count); |
|
|
_voiceWebSocket.SendPCMFrame(data, count); |
|
|
|
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary> Clears the PCM buffer. </summary> |
|
|
/// <summary> Clears the PCM buffer. </summary> |
|
|
public void ClearVoicePCM() |
|
|
public void ClearVoicePCM() |
|
|
{ |
|
|
{ |
|
|
CheckReady(); |
|
|
CheckReady(); |
|
|
if (!_config.EnableVoice) throw new InvalidOperationException("Voice is not enabled for this client."); |
|
|
|
|
|
|
|
|
CheckVoice(); |
|
|
|
|
|
|
|
|
if (_isDebugMode) |
|
|
if (_isDebugMode) |
|
|
RaiseOnDebugMessage(DebugMessageType.VoiceOutput, $"Cleared the voice buffer."); |
|
|
RaiseOnDebugMessage(DebugMessageType.VoiceOutput, $"Cleared the voice buffer."); |
|
|
|
|
|
#if !DNXCORE50 |
|
|
_voiceWebSocket.ClearPCMFrames(); |
|
|
_voiceWebSocket.ClearPCMFrames(); |
|
|
|
|
|
#endif |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary> Returns a task that completes once the voice output buffer is empty. </summary> |
|
|
/// <summary> Returns a task that completes once the voice output buffer is empty. </summary> |
|
|
public async Task WaitVoice() |
|
|
public async Task WaitVoice() |
|
|
{ |
|
|
{ |
|
|
CheckReady(); |
|
|
CheckReady(); |
|
|
if (!_config.EnableVoice) throw new InvalidOperationException("Voice is not enabled for this client."); |
|
|
|
|
|
|
|
|
CheckVoice(); |
|
|
|
|
|
|
|
|
|
|
|
#if !DNXCORE50 |
|
|
_voiceWebSocket.Wait(); |
|
|
_voiceWebSocket.Wait(); |
|
|
|
|
|
#endif |
|
|
await TaskHelper.CompletedTask; |
|
|
await TaskHelper.CompletedTask; |
|
|
} |
|
|
} |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
//Helpers |
|
|
//Helpers |
|
|
private void CheckReady() |
|
|
private void CheckReady() |
|
@@ -653,6 +665,13 @@ namespace Discord |
|
|
else if (!_isConnected) |
|
|
else if (!_isConnected) |
|
|
throw new InvalidOperationException("The client is not currently connected to Discord"); |
|
|
throw new InvalidOperationException("The client is not currently connected to Discord"); |
|
|
} |
|
|
} |
|
|
|
|
|
private void CheckVoice() |
|
|
|
|
|
{ |
|
|
|
|
|
#if !DNXCORE50 |
|
|
|
|
|
if (!_config.EnableVoice) |
|
|
|
|
|
#endif |
|
|
|
|
|
throw new InvalidOperationException("Voice is not enabled for this client."); |
|
|
|
|
|
} |
|
|
internal string CleanMessageText(string text) |
|
|
internal string CleanMessageText(string text) |
|
|
{ |
|
|
{ |
|
|
text = _userRegex.Replace(text, _userRegexEvaluator); |
|
|
text = _userRegex.Replace(text, _userRegexEvaluator); |
|
|