| @@ -39,5 +39,20 @@ namespace Discord.API.Models | |||||
| public string GameId; | 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; | public string ServerId; | ||||
| [JsonProperty(PropertyName = "endpoint")] | [JsonProperty(PropertyName = "endpoint")] | ||||
| public string Endpoint; | public string Endpoint; | ||||
| [JsonProperty(PropertyName = "token")] | |||||
| public string Token; | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -30,7 +30,7 @@ namespace Discord | |||||
| #if !DNXCORE50 | #if !DNXCORE50 | ||||
| private readonly DiscordVoiceWebSocket _voiceWebSocket; | private readonly DiscordVoiceWebSocket _voiceWebSocket; | ||||
| private string _currentVoiceServer; | |||||
| private string _currentVoiceServer, _currentVoiceToken; | |||||
| #endif | #endif | ||||
| /// <summary> Returns the User object for the current logged in user. </summary> | /// <summary> Returns the User object for the current logged in user. </summary> | ||||
| @@ -320,7 +320,8 @@ namespace Discord | |||||
| { | { | ||||
| await Task.Delay(_config.ReconnectDelay); | await Task.Delay(_config.ReconnectDelay); | ||||
| await _voiceWebSocket.ConnectAsync(Endpoints.WebSocket_Hub); | await _voiceWebSocket.ConnectAsync(Endpoints.WebSocket_Hub); | ||||
| await _voiceWebSocket.Login(_currentVoiceServer, UserId, SessionId); | |||||
| if (_currentVoiceServer != null) | |||||
| await _voiceWebSocket.Login(_currentVoiceServer, UserId, SessionId, _currentVoiceToken); | |||||
| break; | break; | ||||
| } | } | ||||
| catch (Exception ex) | catch (Exception ex) | ||||
| @@ -334,7 +335,8 @@ namespace Discord | |||||
| _voiceWebSocket.OnDebugMessage += (s, e) => RaiseOnVoiceDebugMessage(e.Message); | _voiceWebSocket.OnDebugMessage += (s, e) => RaiseOnVoiceDebugMessage(e.Message); | ||||
| #endif | #endif | ||||
| _webSocket.GotEvent += (s, e) => | |||||
| #pragma warning disable CS1998 //Disable unused async keyword warning | |||||
| _webSocket.GotEvent += async (s, e) => | |||||
| { | { | ||||
| switch (e.Type) | switch (e.Type) | ||||
| { | { | ||||
| @@ -583,7 +585,18 @@ namespace Discord | |||||
| { | { | ||||
| var data = e.Event.ToObject<TextWebSocketEvents.VoiceServerUpdate>(_serializer); | var data = e.Event.ToObject<TextWebSocketEvents.VoiceServerUpdate>(_serializer); | ||||
| var server = _servers[data.ServerId]; | 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; | break; | ||||
| @@ -608,7 +621,8 @@ namespace Discord | |||||
| } | } | ||||
| }; | }; | ||||
| } | } | ||||
| #pragma warning restore CS1998 //Restore unused async keyword warning | |||||
| private async Task SendAsync() | private async Task SendAsync() | ||||
| { | { | ||||
| var cancelToken = _disconnectToken.Token; | var cancelToken = _disconnectToken.Token; | ||||
| @@ -78,5 +78,18 @@ namespace Discord | |||||
| { | { | ||||
| return new TextWebSocketCommands.KeepAlive(); | 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 | Task.Factory.StartNew(WatcherAsync, cancelToken, TaskCreationOptions.LongRunning, TaskScheduler.Default).Result | ||||
| }.Concat(base.CreateTasks(cancelToken)).ToArray(); | }.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; | var cancelToken = _disconnectToken.Token; | ||||
| @@ -47,10 +47,10 @@ namespace Discord | |||||
| string ip = await Http.Get("http://ipinfo.io/ip"); | string ip = await Http.Get("http://ipinfo.io/ip"); | ||||
| VoiceWebSocketCommands.Login msg = new VoiceWebSocketCommands.Login(); | VoiceWebSocketCommands.Login msg = new VoiceWebSocketCommands.Login(); | ||||
| msg.Payload.Token = Http.Token; | |||||
| msg.Payload.ServerId = serverId; | msg.Payload.ServerId = serverId; | ||||
| msg.Payload.UserId = userId; | |||||
| msg.Payload.SessionId = sessionId; | msg.Payload.SessionId = sessionId; | ||||
| msg.Payload.Token = token; | |||||
| msg.Payload.UserId = userId; | |||||
| await SendMessage(msg, cancelToken); | await SendMessage(msg, cancelToken); | ||||
| try | try | ||||
| @@ -82,7 +82,6 @@ namespace Discord | |||||
| public DateTime? EditedTimestamp { get; internal set; } | public DateTime? EditedTimestamp { get; internal set; } | ||||
| /// <summary> Returns the attachments included in this message. </summary> | /// <summary> Returns the attachments included in this message. </summary> | ||||
| public Attachment[] Attachments { get; internal set; } | public Attachment[] Attachments { get; internal set; } | ||||
| //TODO: Not Implemented | |||||
| /// <summary> Returns a collection of all embeded content in this message. </summary> | /// <summary> Returns a collection of all embeded content in this message. </summary> | ||||
| public Embed[] Embeds { get; internal set; } | public Embed[] Embeds { get; internal set; } | ||||
| @@ -103,6 +102,8 @@ namespace Discord | |||||
| /// <summary> Returns the author of this message. </summary> | /// <summary> Returns the author of this message. </summary> | ||||
| [JsonIgnore] | [JsonIgnore] | ||||
| public User User => _client.GetUser(UserId); | 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) | internal Message(string id, string channelId, DiscordClient client) | ||||
| { | { | ||||
| @@ -21,6 +21,8 @@ namespace Discord | |||||
| public DateTime JoinedAt { get; internal set; } | public DateTime JoinedAt { get; internal set; } | ||||
| /// <summary> Returns the region for this server (see Regions). </summary> | /// <summary> Returns the region for this server (see Regions). </summary> | ||||
| public string Region { get; internal set; } | 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> | /// <summary> Returns the id of the user that first created this server. </summary> | ||||
| public string OwnerId { get; internal set; } | public string OwnerId { get; internal set; } | ||||