Documentation
¶
Overview ¶
Package websocket provides WebSocket hub for real-time updates and notifications.
Package websocket provides WebSocket hub for real-time updates and notifications.
Index ¶
- func BroadcastInbounds(inbounds any)
- func BroadcastNotification(title, message, level string)
- func BroadcastOutbounds(outbounds interface{})
- func BroadcastStatus(status any)
- func BroadcastTraffic(traffic any)
- func BroadcastXrayState(state string, errorMsg string)
- type Client
- type Hub
- type Message
- type MessageType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BroadcastInbounds ¶
func BroadcastInbounds(inbounds any)
BroadcastInbounds broadcasts inbounds list update to all connected clients
func BroadcastNotification ¶
func BroadcastNotification(title, message, level string)
BroadcastNotification broadcasts a system notification to all connected clients
func BroadcastOutbounds ¶
func BroadcastOutbounds(outbounds interface{})
BroadcastOutbounds broadcasts outbounds list update to all connected clients
func BroadcastStatus ¶
func BroadcastStatus(status any)
BroadcastStatus broadcasts server status update to all connected clients
func BroadcastTraffic ¶
func BroadcastTraffic(traffic any)
BroadcastTraffic broadcasts traffic statistics update to all connected clients
func BroadcastXrayState ¶
BroadcastXrayState broadcasts Xray state change to all connected clients
Types ¶
type Client ¶
type Client struct {
ID string
Send chan []byte
Hub *Hub
Topics map[MessageType]bool // Subscribed topics
}
Client represents a WebSocket client connection
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub maintains the set of active clients and broadcasts messages to them
func (*Hub) Broadcast ¶
func (h *Hub) Broadcast(messageType MessageType, payload any)
Broadcast sends a message to all connected clients
func (*Hub) BroadcastToTopic ¶
func (h *Hub) BroadcastToTopic(messageType MessageType, payload any)
BroadcastToTopic sends a message only to clients subscribed to the specific topic
func (*Hub) GetClientCount ¶
GetClientCount returns the number of connected clients
func (*Hub) Unregister ¶
Unregister unregisters a client from the hub
type Message ¶
type Message struct {
Type MessageType `json:"type"`
Payload any `json:"payload"`
Time int64 `json:"time"`
}
Message represents a WebSocket message
type MessageType ¶
type MessageType string
MessageType represents the type of WebSocket message
const ( MessageTypeStatus MessageType = "status" // Server status update MessageTypeTraffic MessageType = "traffic" // Traffic statistics update MessageTypeInbounds MessageType = "inbounds" // Inbounds list update MessageTypeNotification MessageType = "notification" // System notification MessageTypeXrayState MessageType = "xray_state" // Xray state change MessageTypeOutbounds MessageType = "outbounds" // Outbounds list update )