Compare commits
2 commits
0fd33af5fd
...
137d3ede04
Author | SHA1 | Date | |
---|---|---|---|
137d3ede04 | |||
ed79486d73 |
1 changed files with 8 additions and 1 deletions
|
@ -15,6 +15,7 @@ import java.util.Optional;
|
|||
import java.util.Random;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
@ -89,11 +90,15 @@ public final class DiscordListener implements WebSocket.Listener {
|
|||
case 7 -> {
|
||||
logger.info("Reconnect request");
|
||||
this.closeEventQueue.add(new CloseEvent.ResumableCloseEvent(this.resumeGatewayUrl.get(), this.sessionId.get(), lastSeq.get()));
|
||||
webSocket.request(1);
|
||||
return webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "reconnect").thenAccept(WebSocket::abort);
|
||||
}
|
||||
// invalid session
|
||||
case 9 -> {
|
||||
logger.info("Invalid session");
|
||||
this.closeEventQueue.add(new CloseEvent.UnresumableCloseEvent()); // it's technically possible to resume but unlikely -> https://discord.com/developers/docs/events/gateway#resuming
|
||||
webSocket.request(1);
|
||||
return webSocket.sendClose(WebSocket.NORMAL_CLOSURE, "invalid session").thenAccept(WebSocket::abort);
|
||||
}
|
||||
// hello event
|
||||
case 10 -> init(webSocket, event.data());
|
||||
|
@ -151,12 +156,14 @@ public final class DiscordListener implements WebSocket.Listener {
|
|||
final String stringSeq = intSeq != 0 ? String.valueOf(intSeq) : "null";
|
||||
// Send heartbeat
|
||||
logger.debug("Sending heartbeat: {}", stringSeq);
|
||||
webSocket.sendText("{\"op\": 1, \"d\": %s}".formatted(stringSeq), true);
|
||||
webSocket.sendText("{\"op\": 1, \"d\": %s}".formatted(stringSeq), true).get();
|
||||
receivedAck.set(false);
|
||||
TimeUnit.MILLISECONDS.sleep(heartbeatInterval);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
logger.error("Heartbeat interrupted", e);
|
||||
} catch (ExecutionException e) {
|
||||
logger.error("Heartbeat send failed", e);
|
||||
}
|
||||
logger.info("Stopping heartbeat");
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue