Use a better method for detecting if a voice socket is needed.
This commit is contained in:
@@ -52,7 +52,7 @@ namespace Discord
|
|||||||
|
|
||||||
/// <summary> Initializes a new instance of the DiscordClient class. </summary>
|
/// <summary> Initializes a new instance of the DiscordClient class. </summary>
|
||||||
public DiscordClient(DiscordClientConfig config = null)
|
public DiscordClient(DiscordClientConfig config = null)
|
||||||
: base(config, enableVoice: config.VoiceMode != DiscordVoiceMode.Disabled && !config.EnableVoiceMultiserver)
|
: base(config)
|
||||||
{
|
{
|
||||||
_rand = new Random();
|
_rand = new Random();
|
||||||
_api = new DiscordAPIClient(_config.LogLevel, _config.UserAgent, _config.APITimeout);
|
_api = new DiscordAPIClient(_config.LogLevel, _config.UserAgent, _config.APITimeout);
|
||||||
@@ -740,7 +740,7 @@ namespace Discord
|
|||||||
config.EnableVoiceMultiserver = false;
|
config.EnableVoiceMultiserver = false;
|
||||||
config.VoiceOnly = true;
|
config.VoiceOnly = true;
|
||||||
config.VoiceClientId = unchecked(++_nextVoiceClientId);
|
config.VoiceClientId = unchecked(++_nextVoiceClientId);
|
||||||
return new DiscordSimpleClient(config, true, serverId);
|
return new DiscordSimpleClient(config, serverId);
|
||||||
});
|
});
|
||||||
client.LogMessage += (s, e) => RaiseOnLog(e.Severity, e.Source, $"(#{client.Config.VoiceClientId}) {e.Message}");
|
client.LogMessage += (s, e) => RaiseOnLog(e.Severity, e.Source, $"(#{client.Config.VoiceClientId}) {e.Message}");
|
||||||
await client.Connect(_gateway, _token).ConfigureAwait(false);
|
await client.Connect(_gateway, _token).ConfigureAwait(false);
|
||||||
|
|||||||
@@ -27,6 +27,9 @@ namespace Discord
|
|||||||
public bool AckMessages { get { return _ackMessages; } set { SetValue(ref _ackMessages, value); } }
|
public bool AckMessages { get { return _ackMessages; } set { SetValue(ref _ackMessages, value); } }
|
||||||
private bool _ackMessages = false;
|
private bool _ackMessages = false;
|
||||||
|
|
||||||
|
//Internal
|
||||||
|
internal override bool EnableVoice => base.EnableVoice && !EnableVoiceMultiserver;
|
||||||
|
|
||||||
public new DiscordClientConfig Clone()
|
public new DiscordClientConfig Clone()
|
||||||
{
|
{
|
||||||
var config = this.MemberwiseClone() as DiscordClientConfig;
|
var config = this.MemberwiseClone() as DiscordClientConfig;
|
||||||
|
|||||||
@@ -51,14 +51,11 @@ namespace Discord
|
|||||||
|
|
||||||
/// <summary> Initializes a new instance of the DiscordClient class. </summary>
|
/// <summary> Initializes a new instance of the DiscordClient class. </summary>
|
||||||
public DiscordSimpleClient(DiscordSimpleClientConfig config = null)
|
public DiscordSimpleClient(DiscordSimpleClientConfig config = null)
|
||||||
: this(config, enableVoice: config.VoiceMode != DiscordVoiceMode.Disabled) { }
|
|
||||||
internal DiscordSimpleClient(DiscordSimpleClientConfig config = null, bool enableVoice = false, string voiceServerId = null)
|
|
||||||
{
|
{
|
||||||
_config = config ?? new DiscordSimpleClientConfig();
|
_config = config ?? new DiscordSimpleClientConfig();
|
||||||
_config.Lock();
|
_config.Lock();
|
||||||
|
|
||||||
_enableVoice = enableVoice;
|
_enableVoice = _config.EnableVoice;
|
||||||
_voiceServerId = voiceServerId;
|
|
||||||
|
|
||||||
_state = (int)DiscordClientState.Disconnected;
|
_state = (int)DiscordClientState.Disconnected;
|
||||||
_cancelToken = new CancellationToken(true);
|
_cancelToken = new CancellationToken(true);
|
||||||
@@ -69,6 +66,11 @@ namespace Discord
|
|||||||
if (_enableVoice)
|
if (_enableVoice)
|
||||||
_voiceSocket = CreateVoiceSocket();
|
_voiceSocket = CreateVoiceSocket();
|
||||||
}
|
}
|
||||||
|
internal DiscordSimpleClient(DiscordSimpleClientConfig config = null, string voiceServerId = null)
|
||||||
|
: this(config)
|
||||||
|
{
|
||||||
|
_voiceServerId = voiceServerId;
|
||||||
|
}
|
||||||
|
|
||||||
internal virtual DataWebSocket CreateDataSocket()
|
internal virtual DataWebSocket CreateDataSocket()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ namespace Discord
|
|||||||
private bool _voiceOnly;
|
private bool _voiceOnly;
|
||||||
internal uint VoiceClientId { get { return _voiceClientId; } set { SetValue(ref _voiceClientId, value); } }
|
internal uint VoiceClientId { get { return _voiceClientId; } set { SetValue(ref _voiceClientId, value); } }
|
||||||
private uint _voiceClientId;
|
private uint _voiceClientId;
|
||||||
|
internal virtual bool EnableVoice => _voiceMode != DiscordVoiceMode.Disabled;
|
||||||
|
|
||||||
internal string UserAgent
|
internal string UserAgent
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user