Browse Source

More voice prep work

tags/docs-0.9
Brandon Smith 9 years ago
parent
commit
1e4162cd98
7 changed files with 56 additions and 9 deletions
  1. +15
    -0
      src/Discord.Net/API/Models/TextWebSocketCommands.cs
  2. +2
    -0
      src/Discord.Net/API/Models/TextWebSocketEvents.cs
  3. +19
    -5
      src/Discord.Net/DiscordClient.cs
  4. +13
    -0
      src/Discord.Net/DiscordTextWebSocket.cs
  5. +3
    -3
      src/Discord.Net/DiscordVoiceWebSocket.cs
  6. +2
    -1
      src/Discord.Net/Message.cs
  7. +2
    -0
      src/Discord.Net/Server.cs

+ 15
- 0
src/Discord.Net/API/Models/TextWebSocketCommands.cs View File

@@ -39,5 +39,20 @@ namespace Discord.API.Models
public string GameId;
}
}
public sealed class JoinVoice : WebSocketMessage<JoinVoice.Data>
{
public JoinVoice() : base(4) { }
public class Data
{
[JsonProperty(PropertyName = "guild_id")]
public string ServerId;
[JsonProperty(PropertyName = "channel_id")]
public string ChannelId;
[JsonProperty(PropertyName = "self_mute")]
public string SelfMute;
[JsonProperty(PropertyName = "self_deaf")]
public string SelfDeaf;
}
}
}
}

+ 2
- 0
src/Discord.Net/API/Models/TextWebSocketEvents.cs View File

@@ -112,6 +112,8 @@ namespace Discord.API.Models
public string ServerId;
[JsonProperty(PropertyName = "endpoint")]
public string Endpoint;
[JsonProperty(PropertyName = "token")]
public string Token;
}
}
}

+ 19
- 5
src/Discord.Net/DiscordClient.cs View File

@@ -30,7 +30,7 @@ namespace Discord

#if !DNXCORE50
private readonly DiscordVoiceWebSocket _voiceWebSocket;
private string _currentVoiceServer;
private string _currentVoiceServer, _currentVoiceToken;
#endif

/// <summary> Returns the User object for the current logged in user. </summary>
@@ -320,7 +320,8 @@ namespace Discord
{
await Task.Delay(_config.ReconnectDelay);
await _voiceWebSocket.ConnectAsync(Endpoints.WebSocket_Hub);
await _voiceWebSocket.Login(_currentVoiceServer, UserId, SessionId);
if (_currentVoiceServer != null)
await _voiceWebSocket.Login(_currentVoiceServer, UserId, SessionId, _currentVoiceToken);
break;
}
catch (Exception ex)
@@ -334,7 +335,8 @@ namespace Discord
_voiceWebSocket.OnDebugMessage += (s, e) => RaiseOnVoiceDebugMessage(e.Message);
#endif

_webSocket.GotEvent += (s, e) =>
#pragma warning disable CS1998 //Disable unused async keyword warning
_webSocket.GotEvent += async (s, e) =>
{
switch (e.Type)
{
@@ -583,7 +585,18 @@ namespace Discord
{
var data = e.Event.ToObject<TextWebSocketEvents.VoiceServerUpdate>(_serializer);
var server = _servers[data.ServerId];
try { RaiseVoiceServerUpdated(server, data.Endpoint); } catch { }
server.VoiceServer = data.Endpoint;
try { RaiseVoiceServerUpdated(server, data.Endpoint); } catch { }

#if !DNXCORE50
if (data.ServerId == _currentVoiceServer)
{
_currentVoiceServer = data.Endpoint;
_currentVoiceToken = data.Token;
await _voiceWebSocket.ConnectAsync(_currentVoiceServer);
await _voiceWebSocket.Login(_currentVoiceServer, UserId, SessionId, _currentVoiceToken);
}
#endif
}
break;

@@ -608,7 +621,8 @@ namespace Discord
}
};
}
#pragma warning restore CS1998 //Restore unused async keyword warning

private async Task SendAsync()
{
var cancelToken = _disconnectToken.Token;


+ 13
- 0
src/Discord.Net/DiscordTextWebSocket.cs View File

@@ -78,5 +78,18 @@ namespace Discord
{
return new TextWebSocketCommands.KeepAlive();
}

public void JoinVoice(string serverId, string channelId)
{
var joinVoice = new TextWebSocketCommands.JoinVoice();
joinVoice.Payload.ServerId = serverId;
joinVoice.Payload.ChannelId = channelId;
QueueMessage(joinVoice);
}
public void LeaveVoice()
{
var joinVoice = new TextWebSocketCommands.JoinVoice();
QueueMessage(joinVoice);
}
}
}

+ 3
- 3
src/Discord.Net/DiscordVoiceWebSocket.cs View File

@@ -37,7 +37,7 @@ namespace Discord
Task.Factory.StartNew(WatcherAsync, cancelToken, TaskCreationOptions.LongRunning, TaskScheduler.Default).Result
}.Concat(base.CreateTasks(cancelToken)).ToArray();
}
public async Task Login(string serverId, string userId, string sessionId)
public async Task Login(string serverId, string userId, string sessionId, string token)
{
var cancelToken = _disconnectToken.Token;

@@ -47,10 +47,10 @@ namespace Discord
string ip = await Http.Get("http://ipinfo.io/ip");

VoiceWebSocketCommands.Login msg = new VoiceWebSocketCommands.Login();
msg.Payload.Token = Http.Token;
msg.Payload.ServerId = serverId;
msg.Payload.UserId = userId;
msg.Payload.SessionId = sessionId;
msg.Payload.Token = token;
msg.Payload.UserId = userId;
await SendMessage(msg, cancelToken);

try


+ 2
- 1
src/Discord.Net/Message.cs View File

@@ -82,7 +82,6 @@ namespace Discord
public DateTime? EditedTimestamp { get; internal set; }
/// <summary> Returns the attachments included in this message. </summary>
public Attachment[] Attachments { get; internal set; }
//TODO: Not Implemented
/// <summary> Returns a collection of all embeded content in this message. </summary>
public Embed[] Embeds { get; internal set; }

@@ -103,6 +102,8 @@ namespace Discord
/// <summary> Returns the author of this message. </summary>
[JsonIgnore]
public User User => _client.GetUser(UserId);
/// <summary> Returns true if the current user created this message. </summary>
public bool IsAuthor => _client.UserId == UserId;

internal Message(string id, string channelId, DiscordClient client)
{


+ 2
- 0
src/Discord.Net/Server.cs View File

@@ -21,6 +21,8 @@ namespace Discord
public DateTime JoinedAt { get; internal set; }
/// <summary> Returns the region for this server (see Regions). </summary>
public string Region { get; internal set; }
/// <summary> Returns the endpoint for this server's voice server. </summary>
internal string VoiceServer { get; set; }

/// <summary> Returns the id of the user that first created this server. </summary>
public string OwnerId { get; internal set; }


Loading…
Cancel
Save