diff --git a/src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java b/src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java index 8f2290d08f..72b36021bd 100644 --- a/src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java +++ b/src/main/java/net/dv8tion/jda/internal/requests/WebSocketClient.java @@ -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; @@ -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) @@ -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); @@ -738,6 +740,7 @@ protected void sendResume() protected void invalidate() { + resumeUrl = null; sessionId = null; sentAuthInfo = false; @@ -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;