Browse Source

Request gateway v4, support reconnects

pull/44/head
RogueException 9 years ago
parent
commit
24e71f7c1a
7 changed files with 17 additions and 29 deletions
  1. +2
    -2
      src/Discord.Net.Net45/Discord.Net.csproj
  2. +0
    -2
      src/Discord.Net/API/Client/GatewaySocket/Commands/Identify.cs
  3. +6
    -0
      src/Discord.Net/API/Client/GatewaySocket/Events/Reconnect.cs
  4. +0
    -10
      src/Discord.Net/API/Client/GatewaySocket/Events/Redirect.cs
  5. +1
    -1
      src/Discord.Net/API/Client/GatewaySocket/OpCodes.cs
  6. +5
    -5
      src/Discord.Net/API/Client/Rest/Gateway.cs
  7. +3
    -9
      src/Discord.Net/Net/WebSockets/GatewaySocket.cs

+ 2
- 2
src/Discord.Net.Net45/Discord.Net.csproj View File

@@ -199,8 +199,8 @@
<Compile Include="..\Discord.Net\API\Client\GatewaySocket\Events\Ready.cs">
<Link>API\Client\GatewaySocket\Events\Ready.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\GatewaySocket\Events\Redirect.cs">
<Link>API\Client\GatewaySocket\Events\Redirect.cs</Link>
<Compile Include="..\Discord.Net\API\Client\GatewaySocket\Events\Reconnect.cs">
<Link>API\Client\GatewaySocket\Events\Reconnect.cs</Link>
</Compile>
<Compile Include="..\Discord.Net\API\Client\GatewaySocket\Events\Resumed.cs">
<Link>API\Client\GatewaySocket\Events\Resumed.cs</Link>


+ 0
- 2
src/Discord.Net/API/Client/GatewaySocket/Commands/Identify.cs View File

@@ -10,8 +10,6 @@ namespace Discord.API.Client.GatewaySocket
object IWebSocketMessage.Payload => this;
bool IWebSocketMessage.IsPrivate => false;

[JsonProperty("v")]
public int Version { get; set; }
[JsonProperty("token")]
public string Token { get; set; }
[JsonProperty("properties")]


+ 6
- 0
src/Discord.Net/API/Client/GatewaySocket/Events/Reconnect.cs View File

@@ -0,0 +1,6 @@
using Newtonsoft.Json;

namespace Discord.API.Client.GatewaySocket
{
public class ReconnectEvent { }
}

+ 0
- 10
src/Discord.Net/API/Client/GatewaySocket/Events/Redirect.cs View File

@@ -1,10 +0,0 @@
using Newtonsoft.Json;

namespace Discord.API.Client.GatewaySocket
{
public class RedirectEvent
{
[JsonProperty("url")]
public string Url { get; set; }
}
}

+ 1
- 1
src/Discord.Net/API/Client/GatewaySocket/OpCodes.cs View File

@@ -17,7 +17,7 @@
/// <summary> C→S - Used to resume a connection after a redirect occurs. </summary>
Resume = 6,
/// <summary> C←S - Used to notify a client that they must reconnect to another gateway. </summary>
Redirect = 7,
Reconnect = 7,
/// <summary> C→S - Used to request all members that were withheld by large_threshold </summary>
RequestGuildMembers = 8
}


+ 5
- 5
src/Discord.Net/API/Client/Rest/Gateway.cs View File

@@ -6,13 +6,13 @@ namespace Discord.API.Client.Rest
public class GatewayRequest : IRestRequest<GatewayResponse>
{
string IRestRequest.Method => "GET";
string IRestRequest.Endpoint => $"gateway";
string IRestRequest.Endpoint => $"gateway?encoding=json&v=4";
object IRestRequest.Payload => null;
}
public class GatewayResponse
{
[JsonProperty("url")]
public string Url { get; set; }
{
[JsonProperty("url")]
public string Url { get; set; }
}
}

+ 3
- 9
src/Discord.Net/Net/WebSockets/GatewaySocket.cs View File

@@ -131,15 +131,10 @@ namespace Discord.Net.WebSockets
}
}
break;
case OpCodes.Redirect:
case OpCodes.Reconnect:
{
var payload = (msg.Payload as JToken).ToObject<RedirectEvent>(_serializer);
if (payload.Url != null)
{
Host = payload.Url;
Logger.Info("Redirected to " + payload.Url);
await Reconnect().ConfigureAwait(false);
}
var payload = (msg.Payload as JToken).ToObject<ReconnectEvent>(_serializer);
await Reconnect().ConfigureAwait(false);
}
break;
default:
@@ -159,7 +154,6 @@ namespace Discord.Net.WebSockets
};
var msg = new IdentifyCommand()
{
Version = 3,
Token = token,
Properties = props,
LargeThreshold = _config.LargeThreshold,


Loading…
Cancel
Save