Browse Source

Fixed a few voice crashes

tags/docs-0.9
RogueException 9 years ago
parent
commit
5b9f31a445
2 changed files with 10 additions and 16 deletions
  1. +7
    -4
      src/Discord.Net/DiscordClient.Voice.cs
  2. +3
    -12
      src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs

+ 7
- 4
src/Discord.Net/DiscordClient.Voice.cs View File

@@ -22,10 +22,13 @@ namespace Discord
public async Task LeaveVoiceServer()
{
CheckReady(checkVoice: true);
await _voiceSocket.Disconnect().ConfigureAwait(false);
await TaskHelper.CompletedTask.ConfigureAwait(false);
_dataSocket.SendLeaveVoice();

if (_voiceSocket.CurrentVoiceServerId != null)
{
await _voiceSocket.Disconnect().ConfigureAwait(false);
await TaskHelper.CompletedTask.ConfigureAwait(false);
_dataSocket.SendLeaveVoice();
}
}

/// <summary> Sends a PCM frame to the voice server. </summary>


+ 3
- 12
src/Discord.Net/Net/WebSockets/VoiceWebSocket.cs View File

@@ -52,23 +52,14 @@ namespace Discord.Net.WebSockets
_targetAudioBufferLength = client.Config.VoiceBufferLength / 20; //20 ms frames
}

public async Task Login(string host, string serverId, string userId, string sessionId, string token)
public Task Login(string host, string serverId, string userId, string sessionId, string token)
{
_serverId = serverId;
_userId = userId;
_sessionId = sessionId;
_token = token;

await base.Connect(host);

Commands.Login msg = new Commands.Login();
msg.Payload.Token = token;
//msg.Payload.Properties["$os"] = "";
//msg.Payload.Properties["$browser"] = "";
msg.Payload.Properties["$device"] = "Discord.Net";
//msg.Payload.Properties["$referrer"] = "";
//msg.Payload.Properties["$referring_domain"] = "";
QueueMessage(msg);
return base.Connect(host);
}

protected override Task[] Run()
@@ -405,7 +396,7 @@ namespace Discord.Net.WebSockets
int frameSize = _encoder.FrameSize;
int frames = bytes / frameSize;
int expectedBytes = frames * frameSize;
int lastFrameSize = expectedBytes - bytes;
int lastFrameSize = bytes - expectedBytes;

//If this only consists of a partial frame and the buffer is too small to pad the end, make a new one
if (data.Length < frameSize)


Loading…
Cancel
Save