Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement gateway resume url handling #2203

Merged
merged 3 commits into from
Aug 15, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
MinnDevelopment marked this conversation as resolved.
Show resolved Hide resolved
DV8FromTheWorld marked this conversation as resolved.
Show resolved Hide resolved
+ "?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