websocket

package
v4.0.0-alpha.7 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BroadcastMessage

type BroadcastMessage struct {
	UserIDs []uint   // 目标用户ID,nil 表示广播给所有
	Message *Message // 消息内容
	Exclude uint     // 排除的用户ID
}

BroadcastMessage 广播消息

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client WebSocket 客户端

type Message

type Message struct {
	Type      MessageType    `json:"type"`
	Timestamp int64          `json:"timestamp"`
	Data      map[string]any `json:"data,omitempty"`
	Error     string         `json:"error,omitempty"`
}

Message WebSocket 消息

type MessageType

type MessageType string

MessageType 消息类型

const (
	MessageTypeSubscribe          MessageType = "subscribe"
	MessageTypeUnsubscribe        MessageType = "unsubscribe"
	MessageTypeNodeUpdate         MessageType = "node_update"
	MessageTypeUserUpdate         MessageType = "user_update"
	MessageTypeConfigUpdate       MessageType = "config_update"
	MessageTypeSubscriptionUpdate MessageType = "subscription_update"
	MessageTypeHeartbeat          MessageType = "heartbeat"
	MessageTypeError              MessageType = "error"
)

type SubscriptionManager

type SubscriptionManager struct {
	// contains filtered or unexported fields
}

SubscriptionManager 订阅管理器

func NewSubscriptionManager

func NewSubscriptionManager() *SubscriptionManager

NewSubscriptionManager 创建订阅管理器

func (*SubscriptionManager) NotifyConfigUpdate

func (sm *SubscriptionManager) NotifyConfigUpdate(userIDs []uint, configType string)

NotifyConfigUpdate 通知配置更新

func (*SubscriptionManager) NotifyNodeUpdate

func (sm *SubscriptionManager) NotifyNodeUpdate(nodeID uint, changeType string)

NotifyNodeUpdate 通知节点更新

func (*SubscriptionManager) NotifySubscriptionUpdate

func (sm *SubscriptionManager) NotifySubscriptionUpdate(changeType string, groupID *uint)

NotifySubscriptionUpdate 通知订阅更新

func (*SubscriptionManager) NotifyUserUpdate

func (sm *SubscriptionManager) NotifyUserUpdate(userIDs []uint, changeType string)

NotifyUserUpdate 通知用户更新

func (*SubscriptionManager) Run

func (sm *SubscriptionManager) Run()

Run 运行订阅管理器

type WebSocketHandler

type WebSocketHandler struct {
	// contains filtered or unexported fields
}

WebSocketHandler WebSocket 处理器

func NewWebSocketHandler

func NewWebSocketHandler(sm *SubscriptionManager, jwtSecret string) *WebSocketHandler

NewWebSocketHandler 创建 WebSocket 处理器

func (*WebSocketHandler) GetSubscriptionManager

func (h *WebSocketHandler) GetSubscriptionManager() *SubscriptionManager

GetSubscriptionManager 获取订阅管理器

func (*WebSocketHandler) HandleWebSocket

func (h *WebSocketHandler) HandleWebSocket(w http.ResponseWriter, r *http.Request)

HandleWebSocket 处理 WebSocket 连接

Jump to

Keyboard shortcuts

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