server

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package server maneja las conexiones WebSocket y el encolamiento de trabajos.

Package server maneja las conexiones WebSocket y el encolamiento de trabajos.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientRegistry

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

ClientRegistry manages connected WebSocket clients thread-safely

func NewClientRegistry

func NewClientRegistry() *ClientRegistry

NewClientRegistry creates a new client registry

func (*ClientRegistry) Add

func (r *ClientRegistry) Add(conn *websocket.Conn)

Add registers a new client connection

func (*ClientRegistry) Broadcast

func (r *ClientRegistry) Broadcast(fn func(*websocket.Conn) error)

Broadcast sends a message to all connected clients

func (*ClientRegistry) Contains

func (r *ClientRegistry) Contains(conn *websocket.Conn) bool

Contains checks if a client is registered

func (*ClientRegistry) Count

func (r *ClientRegistry) Count() int

Count returns the number of connected clients

func (*ClientRegistry) ForEach

func (r *ClientRegistry) ForEach(fn func(*websocket.Conn))

ForEach executes a function for each connected client

func (*ClientRegistry) Remove

func (r *ClientRegistry) Remove(conn *websocket.Conn)

Remove unregisters a client connection

type Config

type Config struct {
	QueueSize int
}

Config holds server configuration

type Message

type Message struct {
	Tipo  string          `json:"tipo"`
	ID    string          `json:"id,omitempty"`
	Datos json.RawMessage `json:"datos,omitempty"`
}

Message represents incoming WebSocket message

type PrintJob

type PrintJob struct {
	ID         string          `json:"id"`
	ClientConn *websocket.Conn `json:"-"`
	Document   json.RawMessage `json:"datos"`
	ReceivedAt time.Time       `json:"received_at"`
}

PrintJob represents a queued print request

type PrinterLister

type PrinterLister interface {
	GetPrinters(forceRefresh bool) ([]connection.PrinterDetail, error)
	GetSummary() printer.Summary
}

type Response

type Response struct {
	Tipo     string `json:"tipo"`
	ID       string `json:"id,omitempty"`
	Status   string `json:"status,omitempty"`
	Mensaje  string `json:"mensaje,omitempty"`
	Current  int    `json:"current,omitempty"`
	Capacity int    `json:"capacity,omitempty"`
}

Response represents outgoing WebSocket message

type Server

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

Server manages WebSocket connections and job queue

func NewServer

func NewServer(cfg Config, discovery PrinterLister) *Server

NewServer creates a new WebSocket server

func (*Server) HandleWebSocket

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

HandleWebSocket handles WebSocket connections

func (*Server) JobQueue

func (s *Server) JobQueue() <-chan *PrintJob

JobQueue returns the job queue channel (for worker consumption)

func (*Server) NotifyClient

func (s *Server) NotifyClient(conn *websocket.Conn, response Response) error

NotifyClient sends a result back to a specific client

func (*Server) QueueStatus

func (s *Server) QueueStatus() (current, capacity int)

QueueStatus returns current and max queue size

func (*Server) Shutdown

func (s *Server) Shutdown()

Shutdown gracefully shuts down the server

Jump to

Keyboard shortcuts

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