feat: add return of table state
This commit is contained in:
@@ -51,6 +51,9 @@ public class CompetitionWS {
|
||||
@Inject
|
||||
RTeam rTeam;
|
||||
|
||||
@Inject
|
||||
RState rState;
|
||||
|
||||
@Inject
|
||||
SecurityCtx securityCtx;
|
||||
|
||||
@@ -95,6 +98,7 @@ public class CompetitionWS {
|
||||
getWSReceiverMethods(RRegister.class, rRegister);
|
||||
getWSReceiverMethods(RCard.class, rCard);
|
||||
getWSReceiverMethods(RTeam.class, rTeam);
|
||||
getWSReceiverMethods(RState.class, rState);
|
||||
|
||||
executor = notifyExecutor;
|
||||
}
|
||||
@@ -141,6 +145,7 @@ public class CompetitionWS {
|
||||
LOGGER.debugf("Active connections: %d", connection.getOpenConnections().size());
|
||||
|
||||
waitingResponse.remove(connection);
|
||||
rState.removeConnection(connection);
|
||||
}
|
||||
|
||||
private MessageOut makeReply(MessageIn message, Object data) {
|
||||
@@ -230,6 +235,30 @@ public class CompetitionWS {
|
||||
});
|
||||
}
|
||||
|
||||
public static void sendNotifyState(WebSocketConnection connection, String code, Object data) {
|
||||
String uuid = connection.pathParam("uuid");
|
||||
|
||||
List<Uni<Void>> queue = new ArrayList<>();
|
||||
queue.add(Uni.createFrom().voidItem()); // For avoid empty queue
|
||||
|
||||
connection.getOpenConnections().forEach(c -> {
|
||||
Boolean s = c.userData().get(UserData.TypedKey.forBoolean("needState"));
|
||||
if (uuid.equals(c.pathParam("uuid")) && s != null && s) {
|
||||
queue.add(c.sendText(new MessageOut(UUID.randomUUID(), code, MessageType.NOTIFY, data)));
|
||||
}
|
||||
});
|
||||
|
||||
Uni.join().all(queue)
|
||||
.andCollectFailures()
|
||||
.runSubscriptionOn(executor)
|
||||
.subscribeAsCompletionStage()
|
||||
.whenComplete((v, t) -> {
|
||||
if (t != null) {
|
||||
LOGGER.error("Error sending ws_out message", t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@OnError
|
||||
Uni<Void> error(WebSocketConnection connection, ForbiddenException t) {
|
||||
return connection.close(CloseReason.INTERNAL_SERVER_ERROR);
|
||||
|
||||
Reference in New Issue
Block a user