unified

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package unified provides a JSON-RPC 2.0 WebSocket server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientDisconnectHandler

type ClientDisconnectHandler interface {
	OnClientDisconnect(clientID string, subscribedWorkspaces []string)
}

ClientDisconnectHandler handles cleanup when a client disconnects. Called with the client ID and list of workspace IDs they were subscribed to.

type FocusChangeResult

type FocusChangeResult struct {
	WorkspaceID  string   `json:"workspace_id"`
	SessionID    string   `json:"session_id"`
	OtherViewers []string `json:"other_viewers"`
	ViewerCount  int      `json:"viewer_count"`
	Success      bool     `json:"success"`
}

FocusChangeResult is the result of a focus change operation.

type Server

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

Server is a JSON-RPC 2.0 WebSocket server.

func NewServer

func NewServer(host string, port int, dispatcher *handler.Dispatcher, eventHub ports.EventHub) *Server

NewServer creates a new unified server.

func (*Server) Broadcast

func (s *Server) Broadcast(data []byte)

Broadcast sends a message to all connected clients.

func (*Server) ClientCount

func (s *Server) ClientCount() int

ClientCount returns the number of connected clients.

func (*Server) GetAllSessionFocus

func (s *Server) GetAllSessionFocus() map[string]*SessionFocus

GetAllSessionFocus returns all session focus info. Returns a map of client ID to their focus info.

func (*Server) GetClient

func (s *Server) GetClient(id string) *UnifiedClient

GetClient returns a client by ID for sending direct messages.

func (*Server) GetFilteredSubscriber

func (s *Server) GetFilteredSubscriber(clientID string) *hub.FilteredSubscriber

GetFilteredSubscriber returns the filtered subscriber for a client ID. Returns nil if the client doesn't exist.

func (*Server) GetSessionViewers

func (s *Server) GetSessionViewers(workspaceID string) map[string][]string

GetSessionViewers returns a map of session ID to list of client IDs viewing that session. Optionally filter by workspace ID.

func (*Server) HandleWebSocket

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

HandleWebSocket handles WebSocket upgrade requests. This can be used as a handler in HTTP servers for WebSocket upgrades.

func (*Server) RequireAuth

func (s *Server) RequireAuth() bool

RequireAuth returns whether authentication is required.

func (*Server) SetDisconnectHandler

func (s *Server) SetDisconnectHandler(handler ClientDisconnectHandler)

SetDisconnectHandler sets the handler for client disconnect cleanup.

func (*Server) SetRequireSecureTransport

func (s *Server) SetRequireSecureTransport(require bool)

SetRequireSecureTransport enforces WSS for non-local traffic.

func (*Server) SetSecurity

func (s *Server) SetSecurity(tokenManager *security.TokenManager, originChecker *security.OriginChecker, requireAuth bool)

SetSecurity configures security settings for the server.

func (*Server) SetSessionFocus

func (s *Server) SetSessionFocus(clientID, workspaceID, sessionID string) (interface{}, error)

SetSessionFocus updates the session focus for a client and broadcasts join/leave events.

func (*Server) SetStatusProvider

func (s *Server) SetStatusProvider(provider common.StatusProvider)

SetStatusProvider sets the status provider for heartbeats.

func (*Server) SetTrustedProxies

func (s *Server) SetTrustedProxies(trustedProxies []*net.IPNet)

SetTrustedProxies sets trusted reverse-proxy CIDRs.

func (*Server) SetWebSocketRateLimiter

func (s *Server) SetWebSocketRateLimiter(limiter *httpMiddleware.RateLimiter, keyExtractor httpMiddleware.KeyExtractor)

SetWebSocketRateLimiter sets incoming WS message rate limiting for authenticated/unauthenticated sockets.

func (*Server) Start

func (s *Server) Start() error

Start starts the unified server with its own HTTP server. For port consolidation, use StartBackgroundTasks() with the HTTP server's SetWebSocketHandler() instead.

func (*Server) StartBackgroundTasks

func (s *Server) StartBackgroundTasks()

StartBackgroundTasks starts background tasks (heartbeat) without starting the HTTP server. Use this when integrating with an existing HTTP server via SetWebSocketHandler().

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) error

Stop gracefully stops the server.

func (*Server) TokenManager

func (s *Server) TokenManager() *security.TokenManager

TokenManager returns the server's token manager (for pairing endpoints).

type SessionFocus

type SessionFocus struct {
	ClientID    string
	WorkspaceID string
	SessionID   string
	FocusedAt   time.Time
}

SessionFocus represents which session a client is currently focused on.

type UnifiedClient

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

UnifiedClient represents a JSON-RPC 2.0 WebSocket client.

func NewUnifiedClient

func NewUnifiedClient(
	conn *websocket.Conn,
	dispatcher *handler.Dispatcher,
	rateLimiter *httpMiddleware.RateLimiter,
	rateLimitKey string,
	onClose func(id string),
) *UnifiedClient

NewUnifiedClient creates a new unified client.

func (*UnifiedClient) Close

func (c *UnifiedClient) Close() error

Close closes the client connection.

func (*UnifiedClient) Done

func (c *UnifiedClient) Done() <-chan struct{}

Done returns a channel that's closed when the client is done.

func (*UnifiedClient) ID

func (c *UnifiedClient) ID() string

ID returns the client ID.

func (*UnifiedClient) Send

func (c *UnifiedClient) Send(event events.Event) error

Send implements ports.Subscriber - converts events to JSON-RPC notification format.

func (*UnifiedClient) SendRaw

func (c *UnifiedClient) SendRaw(data []byte)

SendRaw queues raw bytes to be sent.

func (*UnifiedClient) SetAuthPayload

func (c *UnifiedClient) SetAuthPayload(payload *security.TokenPayload)

SetAuthPayload stores the auth payload for this client connection.

func (*UnifiedClient) Start

func (c *UnifiedClient) Start()

Start starts the client's read and write loops.

Jump to

Keyboard shortcuts

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