diff --git a/web/html/xray.html b/web/html/xray.html
index 1cbde31a..186156ff 100644
--- a/web/html/xray.html
+++ b/web/html/xray.html
@@ -968,6 +968,17 @@
await this.getXraySetting();
await this.getXrayResult();
await this.getOutboundsTraffic();
+
+ if (window.wsClient) {
+ window.wsClient.connect();
+ window.wsClient.on('outbounds', (payload) => {
+ if (payload) {
+ this.outboundsTraffic = payload;
+ this.$forceUpdate();
+ }
+ });
+ }
+
while (true) {
await PromiseUtil.sleep(800);
this.saveBtnDisable = this.oldXraySetting === this.xraySetting;
diff --git a/web/job/xray_traffic_job.go b/web/job/xray_traffic_job.go
index e7b1b5c0..33a432b5 100644
--- a/web/job/xray_traffic_job.go
+++ b/web/job/xray_traffic_job.go
@@ -65,6 +65,11 @@ func (j *XrayTrafficJob) Run() {
logger.Warning("get all inbounds for websocket failed:", err)
}
+ updatedOutbounds, err := j.outboundService.GetOutboundsTraffic()
+ if err != nil {
+ logger.Warning("get all outbounds for websocket failed:", err)
+ }
+
// Broadcast traffic update via WebSocket with accumulated values from database
trafficUpdate := map[string]interface{}{
"traffics": traffics,
@@ -79,6 +84,10 @@ func (j *XrayTrafficJob) Run() {
websocket.BroadcastInbounds(updatedInbounds)
}
+ if updatedOutbounds != nil {
+ websocket.BroadcastOutbounds(updatedOutbounds)
+ }
+
}
func (j *XrayTrafficJob) informTrafficToExternalAPI(inboundTraffics []*xray.Traffic, clientTraffics []*xray.ClientTraffic) {
diff --git a/web/websocket/hub.go b/web/websocket/hub.go
index 187ebb6f..7ee93405 100644
--- a/web/websocket/hub.go
+++ b/web/websocket/hub.go
@@ -20,6 +20,7 @@ const (
MessageTypeInbounds MessageType = "inbounds" // Inbounds list update
MessageTypeNotification MessageType = "notification" // System notification
MessageTypeXrayState MessageType = "xray_state" // Xray state change
+ MessageTypeOutbounds MessageType = "outbounds" // Outbounds list update
)
// Message represents a WebSocket message
diff --git a/web/websocket/notifier.go b/web/websocket/notifier.go
index cedf56f2..416adaff 100644
--- a/web/websocket/notifier.go
+++ b/web/websocket/notifier.go
@@ -48,6 +48,14 @@ func BroadcastInbounds(inbounds interface{}) {
}
}
+// BroadcastOutbounds broadcasts outbounds list update to all connected clients
+func BroadcastOutbounds(outbounds interface{}) {
+ hub := GetHub()
+ if hub != nil {
+ hub.Broadcast(MessageTypeOutbounds, outbounds)
+ }
+}
+
// BroadcastNotification broadcasts a system notification to all connected clients
func BroadcastNotification(title, message, level string) {
hub := GetHub()