Skip to content

Commit

Permalink
Implement gateway resume url handling (#2203)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Aug 15, 2022
1 parent ed816ac commit a5a0aaf
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public class WebSocketClient extends WebSocketAdapter implements WebSocketListen
protected volatile String sessionId = null;
protected final Object readLock = new Object();
protected Decompressor decompressor;
protected String resumeUrl = null;

protected final ReentrantLock queueLock = new ReentrantLock();
protected final ScheduledExecutorService executor;
Expand Down Expand Up @@ -345,7 +346,7 @@ protected synchronized void connect()
throw new RejectedExecutionException("JDA is shutdown!");
initiating = true;

String url = api.getGatewayUrl()
String url = (resumeUrl != null ? resumeUrl : api.getGatewayUrl())
+ "?encoding=" + encoding.name().toLowerCase()
+ "&v=" + JDAInfo.DISCORD_GATEWAY_VERSION;
if (compression != Compression.NONE)
Expand Down Expand Up @@ -378,6 +379,7 @@ protected synchronized void connect()
}
catch (IOException | WebSocketException e)
{
resumeUrl = null;
api.resetGatewayUrl();
//Completely fail here. We couldn't make the connection.
throw new IllegalStateException(e);
Expand Down Expand Up @@ -738,6 +740,7 @@ protected void sendResume()

protected void invalidate()
{
resumeUrl = null;
sessionId = null;
sentAuthInfo = false;

Expand Down Expand Up @@ -926,6 +929,7 @@ protected void onDispatch(DataObject raw)
// otherwise the audio connection requests that are currently pending might be removed in the process
handlers.get("READY").handle(responseTotal, raw);
sessionId = content.getString("session_id");
resumeUrl = content.getString("resume_gateway_url", null);
break;
case "RESUMED":
reconnectTimeoutS = 2;
Expand Down

0 comments on commit a5a0aaf

Please sign in to comment.