server

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxDevices is the maximum number of devices that can be connected simultaneously.
	MaxDevices = 10000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	ID          string
	Name        string
	Conn        *jsonrpc2.Conn
	Sessions    map[string]*Session
	ConnectedAt time.Time
	// contains filtered or unexported fields
}

Device represents a device connected to the server.

func NewDevice

func NewDevice() *Device

NewDevice creates a new Device instance.

func (*Device) AddSession

func (d *Device) AddSession(session *Session)

AddSession adds a session to the device.

func (*Device) GetSession

func (d *Device) GetSession(sessionID string) (*Session, bool)

GetSession returns a session by ID.

func (*Device) RemoveSession

func (d *Device) RemoveSession(sessionID string)

RemoveSession removes a session from the device.

func (*Device) SessionCount

func (d *Device) SessionCount() int

SessionCount returns the number of active sessions.

type Handler

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

Handler implements jsonrpc2.Handler to process device messages.

func NewHandler

func NewHandler(server *Server, device *Device) *Handler

NewHandler creates a new handler for a device.

func (*Handler) Handle

func (h *Handler) Handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2.Request)

type Server

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

Server manages connected devices.

func New

func New() *Server

New creates a new server instance.

func NewWithSecurityKey

func NewWithSecurityKey(securityKey string) *Server

NewWithSecurityKey creates a new server instance with authentication.

func (*Server) AddDevice

func (s *Server) AddDevice(device *Device)

AddDevice adds a device to the server with LRU eviction if limit is reached.

func (*Server) GetDevice

func (s *Server) GetDevice(deviceID string) (*Device, bool)

GetDevice returns a device by ID.

func (*Server) HandleWebSocket

func (s *Server) HandleWebSocket(w http.ResponseWriter, r *http.Request)

HandleWebSocket processes WebSocket connections.

func (*Server) ListDevices

func (s *Server) ListDevices() []string

ListDevices returns the list of connected device IDs.

func (*Server) RemoveDevice

func (s *Server) RemoveDevice(deviceID string)

RemoveDevice removes a device from the server.

func (*Server) Start

func (s *Server) Start(addr string) error

Start starts the HTTP/WebSocket server (insecure).

func (*Server) StartTLS

func (s *Server) StartTLS(addr string, certFile string, keyFile string) error

StartTLS starts the HTTPS/WebSocket server with TLS (secure).

type Session

type Session struct {
	ID         string
	AgentID    string
	ClientConn *jsonrpc2.Conn // Connection to the client that initiated the session
	Input      chan []byte
	Output     chan []byte
	Done       chan struct{}
	// contains filtered or unexported fields
}

Session representa uma sessão interativa com um agente.

func NewSession

func NewSession(id, agentID string) *Session

NewSession cria uma nova sessão.

func NewSessionWithClient

func NewSessionWithClient(id, agentID string, clientConn *jsonrpc2.Conn) *Session

NewSessionWithClient cria uma nova sessão com conexão do client.

Jump to

Keyboard shortcuts

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