Documentation
¶
Overview ¶
Package unified provides a JSON-RPC 2.0 WebSocket server.
Index ¶
- type ClientDisconnectHandler
- type FocusChangeResult
- type Server
- func (s *Server) Broadcast(data []byte)
- func (s *Server) ClientCount() int
- func (s *Server) GetAllSessionFocus() map[string]*SessionFocus
- func (s *Server) GetClient(id string) *UnifiedClient
- func (s *Server) GetFilteredSubscriber(clientID string) *hub.FilteredSubscriber
- func (s *Server) GetSessionViewers(workspaceID string) map[string][]string
- func (s *Server) HandleWebSocket(w http.ResponseWriter, r *http.Request)
- func (s *Server) RequireAuth() bool
- func (s *Server) SetDisconnectHandler(handler ClientDisconnectHandler)
- func (s *Server) SetRequireSecureTransport(require bool)
- func (s *Server) SetSecurity(tokenManager *security.TokenManager, originChecker *security.OriginChecker, ...)
- func (s *Server) SetSessionFocus(clientID, workspaceID, sessionID string) (interface{}, error)
- func (s *Server) SetStatusProvider(provider common.StatusProvider)
- func (s *Server) SetTrustedProxies(trustedProxies []*net.IPNet)
- func (s *Server) SetWebSocketRateLimiter(limiter *httpMiddleware.RateLimiter, keyExtractor httpMiddleware.KeyExtractor)
- func (s *Server) Start() error
- func (s *Server) StartBackgroundTasks()
- func (s *Server) Stop(ctx context.Context) error
- func (s *Server) TokenManager() *security.TokenManager
- type SessionFocus
- type UnifiedClient
- func (c *UnifiedClient) Close() error
- func (c *UnifiedClient) Done() <-chan struct{}
- func (c *UnifiedClient) ID() string
- func (c *UnifiedClient) Send(event events.Event) error
- func (c *UnifiedClient) SendRaw(data []byte)
- func (c *UnifiedClient) SetAuthPayload(payload *security.TokenPayload)
- func (c *UnifiedClient) Start()
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) ClientCount ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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) 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) 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.