55 lines
1.6 KiB
Java
55 lines
1.6 KiB
Java
package dev.lions.unionflow.server.service;
|
|
|
|
import io.quarkus.websockets.next.OpenConnections;
|
|
import jakarta.enterprise.context.ApplicationScoped;
|
|
import jakarta.inject.Inject;
|
|
import org.jboss.logging.Logger;
|
|
|
|
/**
|
|
* Service de broadcast WebSocket pour les notifications temps réel du dashboard.
|
|
*/
|
|
@ApplicationScoped
|
|
public class WebSocketBroadcastService {
|
|
|
|
private static final Logger LOG = Logger.getLogger(WebSocketBroadcastService.class);
|
|
|
|
@Inject
|
|
OpenConnections openConnections;
|
|
|
|
/**
|
|
* Broadcast un message à toutes les connexions WebSocket ouvertes.
|
|
*/
|
|
public void broadcast(String message) {
|
|
LOG.debugf("Broadcasting message to %d connections", openConnections.stream().count());
|
|
openConnections.forEach(connection -> connection.sendTextAndAwait(message));
|
|
}
|
|
|
|
/**
|
|
* Broadcast une mise à jour de statistiques.
|
|
*/
|
|
public void broadcastStatsUpdate(String jsonData) {
|
|
broadcast("{\"type\":\"stats_update\",\"data\":" + jsonData + "}");
|
|
}
|
|
|
|
/**
|
|
* Broadcast une nouvelle activité.
|
|
*/
|
|
public void broadcastNewActivity(String jsonData) {
|
|
broadcast("{\"type\":\"new_activity\",\"data\":" + jsonData + "}");
|
|
}
|
|
|
|
/**
|
|
* Broadcast une mise à jour d'événement.
|
|
*/
|
|
public void broadcastEventUpdate(String jsonData) {
|
|
broadcast("{\"type\":\"event_update\",\"data\":" + jsonData + "}");
|
|
}
|
|
|
|
/**
|
|
* Broadcast une notification.
|
|
*/
|
|
public void broadcastNotification(String jsonData) {
|
|
broadcast("{\"type\":\"notification\",\"data\":" + jsonData + "}");
|
|
}
|
|
}
|