websocket

package
v2.8.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

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

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

func BroadcastXrayState(state string, errorMsg string)

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 GetHub

func GetHub() *Hub

GetHub returns the global WebSocket hub instance

func NewHub

func NewHub() *Hub

NewHub creates a new WebSocket hub

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

func (h *Hub) GetClientCount() int

GetClientCount returns the number of connected clients

func (*Hub) Register

func (h *Hub) Register(client *Client)

Register registers a new client with the hub

func (*Hub) Run

func (h *Hub) Run()

Run starts the hub's main loop

func (*Hub) Stop

func (h *Hub) Stop()

Stop gracefully stops the hub and closes all connections

func (*Hub) Unregister

func (h *Hub) Unregister(client *Client)

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
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL