websocket

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ChannelCodeValue = "websocket"

Variables

This section is empty.

Functions

func RegisterWebSocketRoutes

func RegisterWebSocketRoutes(r gin.IRouter, publisher eventbus.Publisher)

RegisterWebSocketRoutes 注册WebSocket路由(便捷函数)

Types

type Connection

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

Connection represents a single WebSocket connection

type Connector

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

Connector handles client WebSocket connections

func NewConnector

func NewConnector(publisher eventbus.Publisher) *Connector

func (*Connector) BroadcastSend

func (c *Connector) BroadcastSend(message ServerMessage)

func (*Connector) ChannelCode

func (c *Connector) ChannelCode() string

func (*Connector) GetAllClientIDs

func (c *Connector) GetAllClientIDs() []string

func (*Connector) GetMessenger

func (c *Connector) GetMessenger() *Messenger

func (*Connector) RegisterRoutes

func (c *Connector) RegisterRoutes(r gin.IRouter)

func (*Connector) SendMessageToClient

func (c *Connector) SendMessageToClient(clientID string, message ServerMessage) bool

type ConnectorInterface

type ConnectorInterface interface {
	GetMessenger() *Messenger
	GetAllClientIDs() []string
	SendMessageToClient(clientID string, message ServerMessage) bool
	BroadcastSend(message ServerMessage)
}

ConnectorInterface defines methods needed from the connector for messaging

type Manager

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

Manager holds a reference to the connector for messaging

func GetManager

func GetManager() *Manager

GetManager returns the default singleton instance of manager

func (*Manager) GetConnectedClients

func (m *Manager) GetConnectedClients() []string

GetConnectedClients returns a list of all connected client IDs

func (*Manager) GetMessenger

func (m *Manager) GetMessenger() *Messenger

GetMessenger returns an interface for sending messages to clients, or nil if not initialized

func (*Manager) IsInitialized

func (m *Manager) IsInitialized() bool

IsInitialized returns true if the manager has been properly initialized

func (*Manager) SendAgentResult

func (m *Manager) SendAgentResult(clientID, taskID, resultType, result string) error

SendAgentResult sends the final result of an agent's work to clients

func (*Manager) SendAgentStatusUpdate

func (m *Manager) SendAgentStatusUpdate(clientID, taskID, status, message string) error

SendAgentStatusUpdate sends an agent status update to clients

func (*Manager) SendAgentStepUpdate

func (m *Manager) SendAgentStepUpdate(clientID, taskID, step, details string) error

SendAgentStepUpdate sends a step-by-step update from an agent during execution

func (*Manager) SendLogMessage

func (m *Manager) SendLogMessage(clientID, taskID, logLevel, message string) error

SendLogMessage sends a detailed log message during agent execution

func (*Manager) SendMessage

func (m *Manager) SendMessage(clientID, msgType string, payload map[string]interface{}) error

SendMessage broadcasts a message to a specific client or all clients

func (*Manager) SetConnector

func (m *Manager) SetConnector(connector ConnectorInterface)

SetConnector sets the connector instance that will be used for messaging

type Message

type Message struct {
	Type    string                 `json:"type"`
	Payload map[string]interface{} `json:"payload"`
	ID      string                 `json:"id,omitempty"`
}

Message represents possible message types from clients

type MessageDestination

type MessageDestination struct {
	ClientID string `json:"client_id"`
	TaskID   string `json:"task_id"`
}

MessageDestination specifies who should receive the message

type Messenger

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

Messenger provides interface to send messages to clients

func (*Messenger) SendAgentResult

func (m *Messenger) SendAgentResult(clientID, taskID, resultType, result string) error

func (*Messenger) SendAgentStatusUpdate

func (m *Messenger) SendAgentStatusUpdate(clientID, taskID, status, message string) error

func (*Messenger) SendAgentStepUpdate

func (m *Messenger) SendAgentStepUpdate(clientID, taskID, step, details string) error

func (*Messenger) SendLogMessage

func (m *Messenger) SendLogMessage(clientID, taskID, logLevel, message string) error

func (*Messenger) SendMessage

func (m *Messenger) SendMessage(dest MessageDestination, msgType string, payload map[string]interface{}) error

type ServerMessage

type ServerMessage struct {
	Type      string                 `json:"type"`
	Payload   map[string]interface{} `json:"payload"`
	ID        string                 `json:"id,omitempty"`
	Timestamp time.Time              `json:"timestamp"`
}

ServerMessage represents possible message types sent to clients

Jump to

Keyboard shortcuts

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