Compare commits
2 commits
352eaa3e47
...
0fd33af5fd
Author | SHA1 | Date | |
---|---|---|---|
0fd33af5fd | |||
7b0f88808d |
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