mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-01-13 17:24:05 +00:00
Add WebSocket support for outbounds traffic updates
- Implemented WebSocket connection in xray.html to handle real-time updates for outbounds traffic. - Enhanced xray_traffic_job.go to retrieve and broadcast outbounds traffic updates. - Introduced MessageTypeOutbounds in hub.go for managing outbounds messages. - Added BroadcastOutbounds function in notifier.go to facilitate broadcasting outbounds updates to connected clients.
This commit is contained in:
parent
3fba479bce
commit
3789711bed
4 changed files with 29 additions and 0 deletions
|
|
@ -968,6 +968,17 @@
|
||||||
await this.getXraySetting();
|
await this.getXraySetting();
|
||||||
await this.getXrayResult();
|
await this.getXrayResult();
|
||||||
await this.getOutboundsTraffic();
|
await this.getOutboundsTraffic();
|
||||||
|
|
||||||
|
if (window.wsClient) {
|
||||||
|
window.wsClient.connect();
|
||||||
|
window.wsClient.on('outbounds', (payload) => {
|
||||||
|
if (payload) {
|
||||||
|
this.outboundsTraffic = payload;
|
||||||
|
this.$forceUpdate();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
await PromiseUtil.sleep(800);
|
await PromiseUtil.sleep(800);
|
||||||
this.saveBtnDisable = this.oldXraySetting === this.xraySetting;
|
this.saveBtnDisable = this.oldXraySetting === this.xraySetting;
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,11 @@ func (j *XrayTrafficJob) Run() {
|
||||||
logger.Warning("get all inbounds for websocket failed:", err)
|
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
|
// Broadcast traffic update via WebSocket with accumulated values from database
|
||||||
trafficUpdate := map[string]interface{}{
|
trafficUpdate := map[string]interface{}{
|
||||||
"traffics": traffics,
|
"traffics": traffics,
|
||||||
|
|
@ -79,6 +84,10 @@ func (j *XrayTrafficJob) Run() {
|
||||||
websocket.BroadcastInbounds(updatedInbounds)
|
websocket.BroadcastInbounds(updatedInbounds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if updatedOutbounds != nil {
|
||||||
|
websocket.BroadcastOutbounds(updatedOutbounds)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *XrayTrafficJob) informTrafficToExternalAPI(inboundTraffics []*xray.Traffic, clientTraffics []*xray.ClientTraffic) {
|
func (j *XrayTrafficJob) informTrafficToExternalAPI(inboundTraffics []*xray.Traffic, clientTraffics []*xray.ClientTraffic) {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ const (
|
||||||
MessageTypeInbounds MessageType = "inbounds" // Inbounds list update
|
MessageTypeInbounds MessageType = "inbounds" // Inbounds list update
|
||||||
MessageTypeNotification MessageType = "notification" // System notification
|
MessageTypeNotification MessageType = "notification" // System notification
|
||||||
MessageTypeXrayState MessageType = "xray_state" // Xray state change
|
MessageTypeXrayState MessageType = "xray_state" // Xray state change
|
||||||
|
MessageTypeOutbounds MessageType = "outbounds" // Outbounds list update
|
||||||
)
|
)
|
||||||
|
|
||||||
// Message represents a WebSocket message
|
// Message represents a WebSocket message
|
||||||
|
|
|
||||||
|
|
@ -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
|
// BroadcastNotification broadcasts a system notification to all connected clients
|
||||||
func BroadcastNotification(title, message, level string) {
|
func BroadcastNotification(title, message, level string) {
|
||||||
hub := GetHub()
|
hub := GetHub()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue