More voice prep work
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,6 +112,8 @@ namespace Discord.API.Models
|
||||
public string ServerId;
|
||||
[JsonProperty(PropertyName = "endpoint")]
|
||||
public string Endpoint;
|
||||
[JsonProperty(PropertyName = "token")]
|
||||
public string Token;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user