@@ -50,34 +50,21 @@ namespace Discord.Audio | |||||
private ConnectionState _gatewayState; | private ConnectionState _gatewayState; | ||||
internal Logger Logger { get; } | internal Logger Logger { get; } | ||||
/// <summary> Gets the unique identifier for this client. </summary> | |||||
public int Id { get; } | public int Id { get; } | ||||
/// <summary> Gets the service managing this client. </summary> | |||||
public AudioService Service { get; } | public AudioService Service { get; } | ||||
/// <summary> Gets the configuration object used to make this client. </summary> | |||||
public AudioServiceConfig Config { get; } | public AudioServiceConfig Config { get; } | ||||
/// <summary> Gets the internal RestClient for the Client API endpoint. </summary> | |||||
public RestClient ClientAPI { get; } | public RestClient ClientAPI { get; } | ||||
/// <summary> Gets the internal WebSocket for the Gateway event stream. </summary> | |||||
public GatewaySocket GatewaySocket { get; } | public GatewaySocket GatewaySocket { get; } | ||||
/// <summary> Gets the internal WebSocket for the Voice control stream. </summary> | |||||
public VoiceSocket VoiceSocket { get; } | public VoiceSocket VoiceSocket { get; } | ||||
/// <summary> Gets the JSON serializer used by this client. </summary> | |||||
public JsonSerializer Serializer { get; } | public JsonSerializer Serializer { get; } | ||||
/// <summary> </summary> | |||||
public Stream OutputStream { get; } | public Stream OutputStream { get; } | ||||
/// <summary> Gets a cancellation token that triggers when the client is manually disconnected. </summary> | |||||
public CancellationToken CancelToken { get; private set; } | public CancellationToken CancelToken { get; private set; } | ||||
/// <summary> Gets the session id for the current connection. </summary> | |||||
public string SessionId { get; private set; } | public string SessionId { get; private set; } | ||||
/// <summary> Gets the current state of this client. </summary> | |||||
public ConnectionState State => VoiceSocket.State; | public ConnectionState State => VoiceSocket.State; | ||||
/// <summary> Gets the server this client is bound to. </summary> | |||||
public Server Server => VoiceSocket.Server; | public Server Server => VoiceSocket.Server; | ||||
/// <summary> Gets the channel </summary> | |||||
public Channel Channel => VoiceSocket.Channel; | public Channel Channel => VoiceSocket.Channel; | ||||
public AudioClient(DiscordClient client, Server server, int id) | public AudioClient(DiscordClient client, Server server, int id) | ||||
@@ -116,7 +103,6 @@ namespace Discord.Audio | |||||
OutputStream = new OutStream(this); | OutputStream = new OutStream(this); | ||||
} | } | ||||
/// <summary> Connects to the Discord server with the provided token. </summary> | |||||
public async Task Connect() | public async Task Connect() | ||||
{ | { | ||||
if (Config.EnableMultiserver) | if (Config.EnableMultiserver) | ||||
@@ -172,7 +158,6 @@ namespace Discord.Audio | |||||
_gatewayState = ConnectionState.Connected; | _gatewayState = ConnectionState.Connected; | ||||
} | } | ||||
/// <summary> Disconnects from the Discord server, canceling any pending requests. </summary> | |||||
public async Task Disconnect() | public async Task Disconnect() | ||||
{ | { | ||||
await _taskManager.Stop(true).ConfigureAwait(false); | await _taskManager.Stop(true).ConfigureAwait(false); | ||||
@@ -277,9 +262,6 @@ namespace Discord.Audio | |||||
} | } | ||||
} | } | ||||
/// <summary> Sends a PCM frame to the voice server. Will block until space frees up in the outgoing buffer. </summary> | |||||
/// <param name="data">PCM frame to send. This must be a single or collection of uncompressed 48Kz monochannel 20ms PCM frames. </param> | |||||
/// <param name="count">Number of bytes in this frame. </param> | |||||
public void Send(byte[] data, int offset, int count) | public void Send(byte[] data, int offset, int count) | ||||
{ | { | ||||
if (data == null) throw new ArgumentException(nameof(data)); | if (data == null) throw new ArgumentException(nameof(data)); | ||||
@@ -291,14 +273,11 @@ namespace Discord.Audio | |||||
VoiceSocket.SendPCMFrames(data, offset, count); | VoiceSocket.SendPCMFrames(data, offset, count); | ||||
} | } | ||||
/// <summary> Clears the PCM buffer. </summary> | |||||
public void Clear() | public void Clear() | ||||
{ | { | ||||
if (VoiceSocket.Server == null) return; //Has been closed | if (VoiceSocket.Server == null) return; //Has been closed | ||||
VoiceSocket.ClearPCMFrames(); | VoiceSocket.ClearPCMFrames(); | ||||
} | } | ||||
/// <summary> Returns a task that completes once the voice output buffer is empty. </summary> | |||||
public void Wait() | public void Wait() | ||||
{ | { | ||||
if (VoiceSocket.Server == null) return; //Has been closed | if (VoiceSocket.Server == null) return; //Has been closed | ||||
@@ -1,16 +1,38 @@ | |||||
using System.IO; | |||||
using Discord.Net.Rest; | |||||
using Discord.Net.WebSockets; | |||||
using System.IO; | |||||
using System.Threading; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord.Audio | namespace Discord.Audio | ||||
{ | { | ||||
public interface IAudioClient | public interface IAudioClient | ||||
{ | { | ||||
/// <summary> Gets the unique identifier for this client. </summary> | |||||
int Id { get; } | |||||
/// <summary> Gets the session id for the current connection. </summary> | |||||
string SessionId { get; } | |||||
/// <summary> Gets the current state of this client. </summary> | |||||
ConnectionState State { get; } | ConnectionState State { get; } | ||||
/// <summary> Gets the channel this client is currently a member of. </summary> | |||||
Channel Channel { get; } | Channel Channel { get; } | ||||
/// <summary> Gets the server this client is bound to. </summary> | |||||
Server Server { get; } | Server Server { get; } | ||||
/// <summary> Gets a stream object that wraps the Send() function. </summary> | |||||
Stream OutputStream { get; } | Stream OutputStream { get; } | ||||
/// <summary> Gets a cancellation token that triggers when the client is manually disconnected. </summary> | |||||
CancellationToken CancelToken { get; } | |||||
/// <summary> Gets the internal RestClient for the Client API endpoint. </summary> | |||||
RestClient ClientAPI { get; } | |||||
/// <summary> Gets the internal WebSocket for the Gateway event stream. </summary> | |||||
GatewaySocket GatewaySocket { get; } | |||||
/// <summary> Gets the internal WebSocket for the Voice control stream. </summary> | |||||
VoiceSocket VoiceSocket { get; } | |||||
/// <summary> Moves the client to another channel on the same server. </summary> | |||||
Task Join(Channel channel); | Task Join(Channel channel); | ||||
/// <summary> Disconnects from the Discord server, canceling any pending requests. </summary> | |||||
Task Disconnect(); | Task Disconnect(); | ||||
/// <summary> Sends a PCM frame to the voice server. Will block until space frees up in the outgoing buffer. </summary> | /// <summary> Sends a PCM frame to the voice server. Will block until space frees up in the outgoing buffer. </summary> | ||||
@@ -4,13 +4,13 @@ using System.Security; | |||||
namespace Discord.Audio.Opus | namespace Discord.Audio.Opus | ||||
{ | { | ||||
public enum OpusApplication : int | |||||
internal enum OpusApplication : int | |||||
{ | { | ||||
Voice = 2048, | Voice = 2048, | ||||
MusicOrMixed = 2049, | MusicOrMixed = 2049, | ||||
LowLatency = 2051 | LowLatency = 2051 | ||||
} | } | ||||
public enum OpusError : int | |||||
internal enum OpusError : int | |||||
{ | { | ||||
OK = 0, | OK = 0, | ||||
BadArg = -1, | BadArg = -1, | ||||
@@ -22,7 +22,7 @@ namespace Discord.Audio.Opus | |||||
AllocFail = -7 | AllocFail = -7 | ||||
} | } | ||||
public abstract class OpusConverter : IDisposable | |||||
internal abstract class OpusConverter : IDisposable | |||||
{ | { | ||||
protected enum Ctl : int | protected enum Ctl : int | ||||
{ | { | ||||
@@ -2,7 +2,6 @@ | |||||
namespace Discord.Audio.Opus | namespace Discord.Audio.Opus | ||||
{ | { | ||||
/// <summary> Opus codec wrapper. </summary> | |||||
internal class OpusDecoder : OpusConverter | internal class OpusDecoder : OpusConverter | ||||
{ | { | ||||
/// <summary> Creates a new Opus decoder. </summary> | /// <summary> Creates a new Opus decoder. </summary> | ||||
@@ -2,7 +2,6 @@ | |||||
namespace Discord.Audio.Opus | namespace Discord.Audio.Opus | ||||
{ | { | ||||
/// <summary> Opus codec wrapper. </summary> | |||||
internal class OpusEncoder : OpusConverter | internal class OpusEncoder : OpusConverter | ||||
{ | { | ||||
/// <summary> Gets the bit rate in kbit/s. </summary> | /// <summary> Gets the bit rate in kbit/s. </summary> | ||||
@@ -1,4 +1,7 @@ | |||||
using System.IO; | |||||
using Discord.Net.Rest; | |||||
using Discord.Net.WebSockets; | |||||
using System.IO; | |||||
using System.Threading; | |||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
namespace Discord.Audio | namespace Discord.Audio | ||||
@@ -9,9 +12,17 @@ namespace Discord.Audio | |||||
public Server Server { get; } | public Server Server { get; } | ||||
public ConnectionState State => _client.VoiceSocket.Server == Server ? _client.VoiceSocket.State : ConnectionState.Disconnected; | |||||
public Channel Channel => _client.VoiceSocket.Server == Server ? _client.VoiceSocket.Channel : null; | |||||
public Stream OutputStream => _client.VoiceSocket.Server == Server ? _client.OutputStream : null; | |||||
public int Id => 0; | |||||
public string SessionId => _client.Server == Server ? _client.SessionId : null; | |||||
public ConnectionState State => _client.Server == Server ? _client.State : ConnectionState.Disconnected; | |||||
public Channel Channel => _client.Server == Server ? _client.Channel : null; | |||||
public Stream OutputStream => _client.Server == Server ? _client.OutputStream : null; | |||||
public CancellationToken CancelToken => _client.Server == Server ? _client.CancelToken : CancellationToken.None; | |||||
public RestClient ClientAPI => _client.Server == Server ? _client.ClientAPI : null; | |||||
public GatewaySocket GatewaySocket => _client.Server == Server ? _client.GatewaySocket : null; | |||||
public VoiceSocket VoiceSocket => _client.Server == Server ? _client.VoiceSocket : null; | |||||
public VirtualClient(AudioClient client, Server server) | public VirtualClient(AudioClient client, Server server) | ||||
{ | { | ||||