Fixed incoming audio, removed nameresolution dep.

This commit is contained in:
RogueException
2017-04-01 12:59:06 -03:00
parent 27d6f4159d
commit 3e988c7549
7 changed files with 11 additions and 13 deletions

View File

@@ -9,7 +9,7 @@ namespace Discord.Net.Udp
event Func<byte[], int, int, Task> ReceivedDatagram;
void SetCancelToken(CancellationToken cancelToken);
void SetDestination(string host, int port);
void SetDestination(string ip, int port);
Task StartAsync();
Task StopAsync();

View File

@@ -7,6 +7,8 @@ namespace Discord.API.Voice
{
[JsonProperty("ssrc")]
public uint SSRC { get; set; }
[JsonProperty("ip")]
public string Ip { get; set; }
[JsonProperty("port")]
public ushort Port { get; set; }
[JsonProperty("modes")]

View File

@@ -248,7 +248,7 @@ namespace Discord.Audio
_heartbeatTask = RunHeartbeatAsync(data.HeartbeatInterval, _connection.CancelToken);
ApiClient.SetUdpEndpoint(_url, data.Port);
ApiClient.SetUdpEndpoint(data.Ip, data.Port);
await ApiClient.SendDiscoveryAsync(_ssrc).ConfigureAwait(false);
}
break;
@@ -302,7 +302,7 @@ namespace Discord.Audio
}
private async Task ProcessPacketAsync(byte[] packet)
{
if (!_connection.IsCompleted)
if (_connection.State == ConnectionState.Connecting)
{
if (packet.Length != 70)
{
@@ -314,7 +314,7 @@ namespace Discord.Audio
try
{
ip = Encoding.UTF8.GetString(packet, 4, 70 - 6).TrimEnd('\0');
port = packet[69] | (packet[68] << 8);
port = (packet[69] << 8) | packet[68];
}
catch (Exception ex)
{
@@ -325,7 +325,7 @@ namespace Discord.Audio
await _audioLogger.DebugAsync("Received Discovery").ConfigureAwait(false);
await ApiClient.SendSelectProtocol(ip, port).ConfigureAwait(false);
}
else
else if (_connection.State == ConnectionState.Connected)
{
uint ssrc;
ulong userId;

View File

@@ -26,8 +26,6 @@ namespace Discord
public ConnectionState State { get; private set; }
public CancellationToken CancelToken { get; private set; }
public bool IsCompleted => _readyPromise.Task.IsCompleted;
internal ConnectionManager(SemaphoreSlim stateLock, Logger logger, int connectionTimeout,
Func<Task> onConnecting, Func<Exception, Task> onDisconnecting, Action<Func<Exception, Task>> clientDisconnectHandler)
{

View File

@@ -16,7 +16,6 @@
<PackageReference Include="System.Runtime.InteropServices" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />
<PackageReference Include="System.Net.Sockets" Version="4.3.0" />
<PackageReference Include="System.Net.WebSockets.Client" Version="4.3.0" />
</ItemGroup>

View File

@@ -228,9 +228,9 @@ namespace Discord.Audio
await _sentDiscoveryEvent.InvokeAsync().ConfigureAwait(false);
}
public void SetUdpEndpoint(string host, int port)
public void SetUdpEndpoint(string ip, int port)
{
_udp.SetDestination(host, port);
_udp.SetDestination(ip, port);
}
//Helpers

View File

@@ -89,10 +89,9 @@ namespace Discord.Net.Udp
}
}
public void SetDestination(string host, int port)
public void SetDestination(string ip, int port)
{
var entry = Dns.GetHostEntryAsync(host).GetAwaiter().GetResult();
_destination = new IPEndPoint(entry.AddressList[0], port);
_destination = new IPEndPoint(IPAddress.Parse(ip), port);
}
public void SetCancelToken(CancellationToken cancelToken)
{