websocket

package
v1.4.8 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2025 License: EPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MessageTypeStdin      uint8 = 0
	MessageTypeStdout     uint8 = 1
	MessageTypeStderr     uint8 = 2
	MessageTypeControl    uint8 = 3
	MessageTypeClose      uint8 = 4
	MessageTypeActivation uint8 = 5
)

Message types for WebSocket communication

View Source
const (
	DefaultPingInterval    = 30000       // 30 seconds
	DefaultPongTimeout     = 10000       // 10 seconds
	DefaultMaxPayload      = 1024 * 1024 // 1MB
	DefaultSessionTimeout  = 300000      // 5 minutes
	DefaultCleanupInterval = 60000       // 1 minute
	DefaultMaxConnections  = 10
)

WebSocket configuration constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client represents a WebSocket client

func NewClient

func NewClient(microserviceUUID string) *Client

NewClient creates a new WebSocket client

func (*Client) Close

func (c *Client) Close() error

Close closes the WebSocket connection

func (*Client) Connect

func (c *Client) Connect(url string, headers http.Header) error

Connect establishes a WebSocket connection to the server

func (*Client) GetDone

func (c *Client) GetDone() <-chan struct{}

GetDone returns the done channel

func (*Client) GetError

func (c *Client) GetError() error

GetError returns the last error that occurred

func (*Client) GetExecID

func (c *Client) GetExecID() string

GetExecID returns the current execution ID

func (*Client) GetMicroserviceUUID

func (c *Client) GetMicroserviceUUID() string

GetMicroserviceUUID returns the microservice UUID

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected checks if the client is connected

func (*Client) IsNormalClosure added in v1.4.4

func (c *Client) IsNormalClosure(err error) bool

IsNormalClosure checks if the error represents a normal session closure

func (*Client) ReadMessage

func (c *Client) ReadMessage() (*Message, error)

ReadMessage reads a message from the server

func (*Client) SendMessage

func (c *Client) SendMessage(msg *Message) error

SendMessage sends a message to the server

func (*Client) SetExecID

func (c *Client) SetExecID(execID string)

SetExecID sets the execution ID for the client

type Message

type Message struct {
	Type             uint8  `msgpack:"type"`
	Data             []byte `msgpack:"data"`
	MicroserviceUUID string `msgpack:"microserviceUuid"`
	ExecID           string `msgpack:"execId"`
	Timestamp        int64  `msgpack:"timestamp"`
}

Message represents a WebSocket message with type and payload

func Decode

func Decode(data []byte) (*Message, error)

Decode decodes a MessagePack message into a Message struct

func NewMessage

func NewMessage(msgType uint8, payload []byte, microserviceUUID string, execID string) *Message

NewMessage creates a new Message with the given type and payload

func (*Message) Encode

func (m *Message) Encode() ([]byte, error)

Encode encodes the message into MessagePack format

func (*Message) IsActivationMessage

func (m *Message) IsActivationMessage() bool

IsActivationMessage checks if the message is an activation message

func (*Message) IsCloseMessage

func (m *Message) IsCloseMessage() bool

IsCloseMessage checks if the message is a close message

func (*Message) IsControlMessage

func (m *Message) IsControlMessage() bool

IsControlMessage checks if the message is a control message

func (*Message) IsStderrMessage

func (m *Message) IsStderrMessage() bool

IsStderrMessage checks if the message is a stderr message

func (*Message) IsStdinMessage

func (m *Message) IsStdinMessage() bool

IsStdinMessage checks if the message is a stdin message

func (*Message) IsStdoutMessage

func (m *Message) IsStdoutMessage() bool

IsStdoutMessage checks if the message is a stdout message

type Session

type Session struct {
	ExecID           string
	MicroserviceUUID string
	LastActivity     time.Time
	// contains filtered or unexported fields
}

Session represents a WebSocket session between a user and an agent

func NewSession

func NewSession(execID, microserviceUUID string) *Session

NewSession creates a new Session with the given execID and microserviceUUID

func (*Session) IsExpired

func (s *Session) IsExpired(timeout time.Duration) bool

IsExpired checks if the session has expired based on the timeout

func (*Session) UpdateActivity

func (s *Session) UpdateActivity()

UpdateActivity updates the last activity timestamp

type SessionManager

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

SessionManager manages WebSocket sessions

func NewSessionManager

func NewSessionManager() *SessionManager

NewSessionManager creates a new SessionManager

func (*SessionManager) AddSession

func (sm *SessionManager) AddSession(session *Session)

AddSession adds a new session to the manager

func (*SessionManager) CleanupExpiredSessions

func (sm *SessionManager) CleanupExpiredSessions(timeout time.Duration)

CleanupExpiredSessions removes all expired sessions

func (*SessionManager) GetActiveSessions

func (sm *SessionManager) GetActiveSessions() int

GetActiveSessions returns the number of active sessions

func (*SessionManager) GetSession

func (sm *SessionManager) GetSession(execID string) *Session

GetSession retrieves a session by its execID

func (*SessionManager) RemoveSession

func (sm *SessionManager) RemoveSession(execID string)

RemoveSession removes a session by its execID

Jump to

Keyboard shortcuts

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