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

1 fix reconnect issue #29

Merged
merged 3 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text eol=lf
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ spotless {
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
encoding 'UTF-8'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import io.vertx.core.Handler;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.WebSocket;
import io.vertx.core.http.WebSocketFrame;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -58,7 +57,6 @@ private void registerHandlers() {
public void handle(WebSocket webSocket) {
webSocket.handler(this::handleMessage);
webSocket.closeHandler(this::handleClose);
webSocket.frameHandler(this::frameHandler);
}

private void handleMessage(Buffer buffer) {
Expand Down Expand Up @@ -88,13 +86,7 @@ private void handleClose(Void unused) {
() -> connectionMediator.getWebSocketManagerProxy().start(connectionMediator));
}

private void frameHandler(WebSocketFrame frame) {
if (frame.isClose()) {
handleClose(frame.closeStatusCode(), frame.closeReason());
}
}

private void handleClose(int status, String reason) {
void handleClose(int status, String reason) {
switch (status) {
case GatewayCloseEventCode.NOT_AUTHENTICATED:
case GatewayCloseEventCode.AUTHENTICATION_FAILED:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.WebSocket;
import io.vertx.core.http.WebSocketConnectOptions;
import io.vertx.core.http.WebSocketFrame;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -53,8 +54,12 @@ public void start(ConnectionMediator connectionMediator) {

this.webSocket = webSocket;

new WebSocketHandler(connectionMediator, retryHandler, discord)
.handle(webSocket);
WebSocketHandler webSocketHandler =
new WebSocketHandler(connectionMediator, retryHandler, discord);

webSocketHandler.handle(webSocket);

webSocket.frameHandler(frame -> frameHandler(frame, webSocketHandler));

if (retryHandler.hasRetried()) {
retryHandler.clear();
Expand All @@ -70,6 +75,12 @@ public void start(ConnectionMediator connectionMediator) {
});
}

private void frameHandler(WebSocketFrame frame, WebSocketHandler webSocketHandler) {
if (frame.isClose()) {
webSocketHandler.handleClose(frame.closeStatusCode(), frame.closeReason());
}
}

public void restart(ConnectionMediator connectionMediator) {
stop();
start(connectionMediator);
Expand Down
Loading