You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

OutputStream.cs 1.1 kB

123456789101112131415161718192021222324252627282930313233
  1. using System.Threading;
  2. using System.Threading.Tasks;
  3. namespace Discord.Audio.Streams
  4. {
  5. ///<summary> Wraps an IAudioClient, sending voice data on write. </summary>
  6. public class OutputStream : AudioOutStream
  7. {
  8. private bool _isSpeaking;
  9. private readonly DiscordVoiceAPIClient _client;
  10. public OutputStream(IAudioClient client)
  11. : this((client as AudioClient).ApiClient) { }
  12. internal OutputStream(DiscordVoiceAPIClient client)
  13. {
  14. _client = client;
  15. }
  16. public async Task SetSpeakingAsync(bool isSpeaking)
  17. {
  18. if (_isSpeaking != isSpeaking)
  19. {
  20. await _client.SendSetSpeaking(isSpeaking).ConfigureAwait(false);
  21. _isSpeaking = isSpeaking;
  22. }
  23. }
  24. public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
  25. {
  26. cancelToken.ThrowIfCancellationRequested();
  27. await _client.SendAsync(buffer, offset, count).ConfigureAwait(false);
  28. }
  29. }
  30. }