server

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

CRC: crc-BackendSocket.md, crc-ProtocolDetector.md, crc-PacketProtocol.md Spec: deployment.md

CRC: crc-HTTPEndpoint.md Spec: interfaces.md, deployment.md

Package server implements the UI server communication layer. CRC: crc-ServerOutgoingBatcher.md Spec: protocol.md Sequence: seq-frontend-outgoing-batch.md

CRC: crc-PendingResponseQueue.md Spec: deployment.md

CRC: crc-LuaSession.md (Server owns luaSessions map) Spec: deployment.md, interfaces.md Sequence: seq-server-startup.md, seq-session-create-backend.md, seq-lua-session-init.md

Server implements per-session Lua isolation via luaSessions map[string]*lua.LuaSession. It creates/destroys LuaSessions via SessionManager callbacks and implements PathVariableHandler to route HandleFrontendCreate/Update to per-session LuaSession.

Package server implements the UI server communication layer. CRC: crc-Session.md, crc-SessionManager.md Spec: main.md (UI Server Architecture - Frontend Layer), interfaces.md

CRC: crc-SessionManager.md Spec: interfaces.md, protocol.md

CRC: crc-VariableBrowser.md CRC: crc-HTTPEndpoint.md (R58, R63-R77, R82, R83)

Package server implements the UI server communication layer. CRC: crc-WebSocketEndpoint.md Spec: interfaces.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSocketPath

func DefaultSocketPath() string

DefaultSocketPath returns the platform-specific default socket path.

func GenerateSessionID added in v0.16.0

func GenerateSessionID() string

GenerateSessionID creates a unique session identifier.

func RunSvc added in v0.9.0

func RunSvc(s ChanSvc)

Run a service. Close the channel to stop it.

func Svc added in v0.9.0

func Svc(s ChanSvc, code func())

func SvcSync added in v0.9.0

func SvcSync[T any](s ChanSvc, code func() (T, error)) (T, error)

Types

type AfterBatchCallback

type AfterBatchCallback func(sessionID string, userEvent bool)

AfterBatchCallback is called after processing a message batch to trigger change detection. userEvent indicates if the batch was triggered by user interaction (immediate flush needed).

type BackendSocket

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

BackendSocket handles the backend API socket.

func NewBackendSocket

func NewBackendSocket(cfg *config.Config, socketPath string, handler *protocol.Handler, httpHandler *HTTPEndpoint) *BackendSocket

NewBackendSocket creates a new backend socket handler.

func (*BackendSocket) Broadcast

func (bs *BackendSocket) Broadcast(msg *protocol.Message) error

Broadcast sends a message to all connected backends.

func (*BackendSocket) Close

func (bs *BackendSocket) Close() error

Close closes the socket and all connections.

func (*BackendSocket) GetSocketPath

func (bs *BackendSocket) GetSocketPath() string

GetSocketPath returns the socket path.

func (*BackendSocket) Listen

func (bs *BackendSocket) Listen() error

Listen starts listening on the backend socket.

func (*BackendSocket) Log

func (bs *BackendSocket) Log(level int, format string, args ...interface{})

Log logs a message via the config.

type ChanSvc added in v0.9.0

type ChanSvc chan func()

type DebugDataProvider added in v0.9.0

type DebugDataProvider func(sessionID string, diagLevel int) ([]DebugVariable, int64, error)

DebugDataProvider is called to get variable data for the debug page. Returns variables, tracker change count, and error.

type DebugVariable added in v0.9.0

type DebugVariable struct {
	Session        *lua.LuaSession         `json:"-"`
	Tracker        *changetracker.Tracker  `json:"-"`
	Variable       *changetracker.Variable `json:"-"`
	ID             int64                   `json:"id"`
	ParentID       int64                   `json:"parentId"`
	Type           string                  `json:"type,omitempty"`
	GoType         string                  `json:"goType,omitempty"`
	Path           string                  `json:"path,omitempty"`
	Value          any                     `json:"value,omitempty"`
	BaseValue      any                     `json:"baseValue,omitempty"`
	Properties     map[string]string       `json:"properties,omitempty"`
	ChildIDs       []int64                 `json:"childIds,omitempty"`
	Error          string                  `json:"error,omitempty"`
	ComputeTime    string                  `json:"computeTime,omitempty"`
	MaxComputeTime string                  `json:"maxComputeTime,omitempty"`
	Active         bool                    `json:"active"`
	Access         string                  `json:"access,omitempty"`
	Diags          []string                `json:"diags,omitempty"`
	ChangeCount    int64                   `json:"changeCount"`
	Depth          int                     `json:"depth"`
	ElementId      string                  `json:"elementId"`
}

DebugVariable represents a variable for the debug tree view. CRC: crc-HTTPEndpoint.md (R57, R59, R60, R61)

type DisconnectCallback added in v0.9.0

type DisconnectCallback func(sessionID string)

DisconnectCallback is called when a connection disconnects. Used to clear sent-tracking so reconnections resync state.

type HTTPEndpoint

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

HTTPEndpoint handles HTTP requests.

func NewHTTPEndpoint

func NewHTTPEndpoint(sessions *SessionManager, handler *protocol.Handler, wsEndpoint *WebSocketEndpoint) *HTTPEndpoint

NewHTTPEndpoint creates a new HTTP endpoint.

func (*HTTPEndpoint) HandleFunc added in v0.17.3

func (h *HTTPEndpoint) HandleFunc(pattern string, handler http.HandlerFunc)

HandleFunc registers a custom handler on the HTTP mux.

func (*HTTPEndpoint) HandleProtocolCommand

func (h *HTTPEndpoint) HandleProtocolCommand(msg *protocol.Message) (*protocol.Response, error)

HandleProtocolCommand processes CLI protocol commands.

func (*HTTPEndpoint) HandleVariablesJSON added in v0.17.1

func (h *HTTPEndpoint) HandleVariablesJSON(w http.ResponseWriter, r *http.Request, sessionID string)

HandleVariablesJSON returns variable data as JSON. CRC: crc-HTTPEndpoint.md (R57, R62, R80, R81)

func (*HTTPEndpoint) ServeHTTP

func (h *HTTPEndpoint) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

func (*HTTPEndpoint) ServeVariableBrowser added in v0.17.1

func (h *HTTPEndpoint) ServeVariableBrowser(w http.ResponseWriter, r *http.Request)

ServeVariableBrowser serves the embedded variable browser HTML page. CRC: crc-HTTPEndpoint.md (R58)

func (*HTTPEndpoint) SetDebugDataProvider added in v0.9.0

func (h *HTTPEndpoint) SetDebugDataProvider(provider DebugDataProvider)

SetDebugDataProvider sets the callback for getting debug variable data.

func (*HTTPEndpoint) SetEmbeddedSite

func (h *HTTPEndpoint) SetEmbeddedSite(site fs.FS)

SetEmbeddedSite sets the embedded site filesystem.

func (*HTTPEndpoint) SetRootSessionProvider added in v0.9.0

func (h *HTTPEndpoint) SetRootSessionProvider(provider RootSessionProvider)

SetRootSessionProvider sets a provider for the root path "/" session. If the provider returns a session ID, that session is used instead of creating a new one.

func (*HTTPEndpoint) SetStaticDir

func (h *HTTPEndpoint) SetStaticDir(dir string)

SetStaticDir sets a custom directory for static files.

type MessageSender added in v0.16.0

type MessageSender interface {
	Send(connectionID string, msg *protocol.Message) error
	SendBatch(connectionID string, msgs []*protocol.Message) error
	Log(level int, format string, args ...interface{})
}

MessageSender sends protocol messages and logs.

type OutgoingBatcher added in v0.16.0

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

OutgoingBatcher batches outgoing messages for a single session with debouncing. User events trigger immediate flush; non-user events are debounced. Each session has its own batcher instance.

func NewOutgoingBatcher added in v0.16.0

func NewOutgoingBatcher(sender MessageSender) *OutgoingBatcher

NewOutgoingBatcher creates a batcher with the given message sender.

func (*OutgoingBatcher) Clear added in v0.16.0

func (b *OutgoingBatcher) Clear()

Clear removes all pending messages and stops the timer. Called when session is destroyed.

func (*OutgoingBatcher) EnsureDebounceStarted added in v0.16.0

func (b *OutgoingBatcher) EnsureDebounceStarted()

EnsureDebounceStarted ensures the debounce timer is running. Called before processing to run debounce concurrently with processing. If timer already running, does nothing (preserves existing deadline).

func (*OutgoingBatcher) FlushNow added in v0.16.0

func (b *OutgoingBatcher) FlushNow()

FlushNow immediately sends all pending messages.

func (*OutgoingBatcher) PendingCount added in v0.16.0

func (b *OutgoingBatcher) PendingCount() int

PendingCount returns the number of pending updates (for testing).

func (*OutgoingBatcher) Queue added in v0.16.0

func (b *OutgoingBatcher) Queue(msg *protocol.Message, watchers []string)

Queue adds a message to the pending queue and starts debounce timer. watchers is the list of connection IDs to send this message to.

type PendingQueueManager

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

PendingQueueManager manages pending queues per connection.

func NewPendingQueueManager

func NewPendingQueueManager() *PendingQueueManager

NewPendingQueueManager creates a new pending queue manager.

func (*PendingQueueManager) Enqueue

func (m *PendingQueueManager) Enqueue(connectionID string, msg *protocol.Message)

Enqueue implements protocol.PendingQueuer interface.

func (*PendingQueueManager) EnqueueTo

func (m *PendingQueueManager) EnqueueTo(msg *protocol.Message, connectionIDs []string)

EnqueueTo enqueues a message to specific connections.

func (*PendingQueueManager) EnqueueToAll

func (m *PendingQueueManager) EnqueueToAll(msg *protocol.Message)

EnqueueToAll enqueues a message to all queues.

func (*PendingQueueManager) GetQueue

func (m *PendingQueueManager) GetQueue(connectionID string) *PendingResponseQueue

GetQueue returns the queue for a connection, creating if needed.

func (*PendingQueueManager) Poll

func (m *PendingQueueManager) Poll(connectionID string, wait time.Duration) []*protocol.Message

Poll implements protocol.PendingQueuer interface.

func (*PendingQueueManager) RemoveQueue

func (m *PendingQueueManager) RemoveQueue(connectionID string)

RemoveQueue removes a connection's queue.

type PendingResponseQueue

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

PendingResponseQueue accumulates push messages for polling clients.

func NewPendingResponseQueue

func NewPendingResponseQueue() *PendingResponseQueue

NewPendingResponseQueue creates a new pending response queue.

func (*PendingResponseQueue) Drain

func (q *PendingResponseQueue) Drain() []*protocol.Message

Drain returns all pending messages and clears the queue.

func (*PendingResponseQueue) Enqueue

func (q *PendingResponseQueue) Enqueue(msg *protocol.Message)

Enqueue adds a message to the pending queue. Valid message types: update, error, destroy

func (*PendingResponseQueue) IsEmpty

func (q *PendingResponseQueue) IsEmpty() bool

IsEmpty checks if the queue has pending messages.

func (*PendingResponseQueue) Len

func (q *PendingResponseQueue) Len() int

Len returns the number of pending messages.

func (*PendingResponseQueue) Poll

Poll returns pending messages, optionally waiting for availability. If wait is 0, returns immediately. Otherwise waits up to the duration.

type RootSessionProvider added in v0.9.0

type RootSessionProvider func() string

RootSessionProvider returns the session ID to use for the root path "/". If it returns an empty string, the default behavior (create new session and redirect) is used. If it returns a session ID, index.html is served with a session cookie set.

type Server

type Server struct {
	HttpEndpoint *HTTPEndpoint
	// contains filtered or unexported fields
}

Server is the main UI server. CRC: crc-Server.md

func New

func New(cfg *config.Config) *Server

New creates a new server with the given configuration.

func (*Server) AfterBatch

func (s *Server) AfterBatch(internalSessionID string, userEvent bool)

AfterBatch triggers Lua change detection after processing a message batch. internalSessionID is the full UUID session ID (used in URLs/WebSocket bindings). userEvent indicates if the batch was triggered by user interaction (immediate flush needed). This method looks up the vended ID and calls the Lua session's AfterBatch, then queues detected changes to the outgoing batcher. CRC: crc-Server.md Sequence: seq-relay-message.md, seq-backend-refresh.md, seq-frontend-outgoing-batch.md

func (*Server) CreateLuaBackendForSession

func (s *Server) CreateLuaBackendForSession(vendedID string, sess *Session) error

CreateLuaBackendForSession creates a LuaBackend and LuaSession for a new frontend session. vendedID is the compact integer ID (e.g., "1", "2") for backend communication. Each frontend session gets its own isolated Lua state and OutgoingBatcher. CRC: crc-LuaBackend.md Sequence: seq-session-create-backend.md

func (*Server) DestroyLuaBackendForSession

func (s *Server) DestroyLuaBackendForSession(vendedID string, sess *Session)

DestroyLuaBackendForSession destroys a session's LuaBackend and LuaSession. vendedID is the compact integer ID (e.g., "1", "2") for backend communication.

func (*Server) ExecuteInSession added in v0.9.0

func (s *Server) ExecuteInSession(vendedID string, fn func() (interface{}, error)) (interface{}, error)

ExecuteInSession executes code within a session's context. This queues through the session's executor to serialize with WebSocket operations. AfterBatch is called after execution to detect and push any changes. Also sets up the Lua session context so session:getApp() etc. work. vendedID is the compact session ID ("1", "2", etc.)

func (*Server) ExecuteInSessionAsync added in v0.19.0

func (s *Server) ExecuteInSessionAsync(vendedID string, fn func() (interface{}, error))

ExecuteInSessionAsync is a fire-and-forget variant of ExecuteInSession. It queues execution through ChanSvc without blocking the caller. Used by session timers (setImmediate/setTimeout/setInterval) to avoid deadlock when Lua code schedules deferred execution from within the executor. CRC: crc-LuaSession.md Seq: seq-session-timer.md

func (*Server) GetHandler

func (s *Server) GetHandler() *protocol.Handler

GetHandler returns the protocol handler.

func (*Server) GetLuaSession added in v0.9.0

func (s *Server) GetLuaSession(vendedID string) *lua.LuaSession

GetLuaSession returns a Lua session by vended ID (for testing/advanced use).

func (*Server) GetSessionIDs added in v0.9.0

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

GetSessionIDs returns all active vended session IDs. Implements viewdef.SessionPusher.

func (*Server) GetSessions

func (s *Server) GetSessions() *SessionManager

GetSessions returns the session manager.

func (*Server) GetViewdefManager added in v0.9.0

func (s *Server) GetViewdefManager() *viewdef.ViewdefManager

GetViewdefManager returns the viewdef manager.

func (*Server) HandleFrontendCreate added in v0.9.0

func (s *Server) HandleFrontendCreate(sessionID string, id int64, parentID int64, properties map[string]string) error

HandleFrontendCreate implements PathVariableHandler. It delegates to the per-session LuaSession. Spec: protocol.md - create(id, parentId, value, properties, nowatch?, unbound?)

func (*Server) HandleFrontendUpdate added in v0.9.0

func (s *Server) HandleFrontendUpdate(sessionID string, varID int64, value json.RawMessage, properties map[string]string) error

HandleFrontendUpdate implements PathVariableHandler. It delegates to the per-session LuaSession.

func (*Server) PushViewdefs added in v0.9.0

func (s *Server) PushViewdefs(vendedID string, viewdefs map[string]string)

PushViewdefs pushes updated viewdefs to a session. This triggers AfterBatch to detect and send the changes. Implements viewdef.SessionPusher. CRC: crc-ViewdefStore.md Sequence: seq-viewdef-hotload.md

func (*Server) SetRootSessionProvider added in v0.9.0

func (s *Server) SetRootSessionProvider(provider RootSessionProvider)

SetRootSessionProvider sets a provider for the root path "/" session. If the provider returns a session ID, that session is used instead of creating a new one. This allows MCP-style servers to serve an existing session at "/" without redirect.

func (*Server) SetSiteFS

func (s *Server) SetSiteFS(siteFS fs.FS)

SetSiteFS sets a custom filesystem for serving static files.

func (*Server) Shutdown

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

Shutdown gracefully shuts down the server.

func (*Server) Start

func (s *Server) Start() error

Start starts the server.

func (*Server) StartAsync added in v0.9.0

func (s *Server) StartAsync(port int) (string, error)

StartAsync starts the HTTP server in a goroutine and returns the URL. Use this for MCP mode where the server runs alongside stdio MCP.

func (*Server) StartCleanupWorker

func (s *Server) StartCleanupWorker(interval time.Duration)

StartCleanupWorker starts a background worker to clean up inactive sessions.

type Session added in v0.16.0

type Session struct {
	ID            string
	AppVariableID int64 // Variable 1 - root app variable
	// contains filtered or unexported fields
}

Session represents a single user session. Session is part of the frontend layer - it routes messages to backend. CRC: crc-Session.md

func NewSession added in v0.16.0

func NewSession(id string) *Session

NewSession creates a new session with the given ID.

func (*Session) AddConnection added in v0.16.0

func (s *Session) AddConnection(connectionID string)

AddConnection registers a new connection to this session.

func (*Session) EnsureDebounceStarted added in v0.16.0

func (s *Session) EnsureDebounceStarted()

EnsureDebounceStarted starts the batcher's debounce timer if not already running. Called before processing incoming messages so timer runs concurrently with processing.

func (*Session) GetAppVariableID added in v0.16.0

func (s *Session) GetAppVariableID() int64

GetAppVariableID returns the root variable ID.

func (*Session) GetBackend added in v0.16.0

func (s *Session) GetBackend() backend.Backend

GetBackend returns the backend instance for this session.

func (*Session) GetBatcher added in v0.16.0

func (s *Session) GetBatcher() *OutgoingBatcher

GetBatcher returns the session's outgoing message batcher.

func (*Session) GetConnectionCount added in v0.16.0

func (s *Session) GetConnectionCount() int

GetConnectionCount returns the number of active connections.

func (*Session) GetConnections added in v0.16.0

func (s *Session) GetConnections() []string

GetConnections returns a copy of the connection IDs.

func (*Session) GetCreatedAt added in v0.16.0

func (s *Session) GetCreatedAt() time.Time

GetCreatedAt returns the session creation time.

func (*Session) GetID added in v0.16.0

func (s *Session) GetID() string

GetID returns the session ID.

func (*Session) GetLastActivity added in v0.16.0

func (s *Session) GetLastActivity() time.Time

GetLastActivity returns the last activity time.

func (*Session) IsActive added in v0.16.0

func (s *Session) IsActive() bool

IsActive checks if the session has any connections.

func (*Session) RemoveConnection added in v0.16.0

func (s *Session) RemoveConnection(connectionID string) bool

RemoveConnection unregisters a connection from this session. Calls backend.UnwatchAll to clean up watches for this connection. Returns true if this was the last frontend connection. CRC: crc-Session.md

func (*Session) SetAppVariableID added in v0.16.0

func (s *Session) SetAppVariableID(id int64)

SetAppVariableID sets the root variable ID.

func (*Session) SetBackend added in v0.16.0

func (s *Session) SetBackend(b backend.Backend)

SetBackend sets the backend instance for this session.

func (*Session) SetBatcher added in v0.16.0

func (s *Session) SetBatcher(b *OutgoingBatcher)

SetBatcher sets the session's outgoing message batcher.

func (*Session) Touch added in v0.16.0

func (s *Session) Touch()

Touch updates the lastActivity timestamp.

type SessionCreatedCallback added in v0.16.0

type SessionCreatedCallback func(vendedID string, session *Session) error

SessionCreatedCallback is called when a new session is created. Receives the vended session ID (compact integer string) and the session object.

type SessionDestroyedCallback added in v0.16.0

type SessionDestroyedCallback func(vendedID string, session *Session)

SessionDestroyedCallback is called when a session is destroyed. Receives the vended session ID (compact integer string) and the session object.

type SessionManager added in v0.16.0

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

SessionManager manages all sessions.

func NewSessionManager added in v0.16.0

func NewSessionManager(sessionTimeout time.Duration) *SessionManager

NewSessionManager creates a new session manager.

func (*SessionManager) CleanupInactiveSessions added in v0.16.0

func (m *SessionManager) CleanupInactiveSessions() int

CleanupInactiveSessions removes sessions with no activity past the timeout.

func (*SessionManager) Count added in v0.16.0

func (m *SessionManager) Count() int

Count returns the number of sessions.

func (*SessionManager) CreateSession added in v0.16.0

func (m *SessionManager) CreateSession() (*Session, string, error)

CreateSession generates a new session ID and initializes the session. Returns the session and its vended ID (compact integer string for backend communication). Note: Variable 1 (app variable) is NOT created here. It's created by: - Lua main.lua calling session:createAppVariable() (Lua-only mode) - External backend via protocol (backend-only mode)

func (*SessionManager) DestroySession added in v0.16.0

func (m *SessionManager) DestroySession(id string) error

DestroySession cleans up a session and all its resources.

func (*SessionManager) Get added in v0.16.0

func (m *SessionManager) Get(id string) *Session

Get retrieves a session by ID. Returns nil if not found.

func (*SessionManager) GetAllSessions added in v0.16.0

func (m *SessionManager) GetAllSessions() []*Session

GetAllSessions returns all sessions.

func (*SessionManager) GetInternalID added in v0.16.0

func (m *SessionManager) GetInternalID(vendedID string) string

GetInternalID returns the internal session ID for a vended ID. Returns empty string if session not found.

func (*SessionManager) GetSession added in v0.16.0

func (m *SessionManager) GetSession(id string) (*Session, bool)

GetSession retrieves a session by ID.

func (*SessionManager) GetVendedID added in v0.16.0

func (m *SessionManager) GetVendedID(internalID string) string

GetVendedID returns the vended ID for an internal session ID. Returns empty string if session not found.

func (*SessionManager) RegisterURLPath added in v0.16.0

func (m *SessionManager) RegisterURLPath(sessionID, path string, variableID int64) error

RegisterURLPath associates a URL path with a presenter variable for a session.

func (*SessionManager) ResolveURLPath added in v0.16.0

func (m *SessionManager) ResolveURLPath(sessionID, path string) (int64, bool)

ResolveURLPath finds the presenter variable for a URL path in a session.

func (*SessionManager) SessionExists added in v0.16.0

func (m *SessionManager) SessionExists(id string) bool

SessionExists checks if a session ID is valid.

func (*SessionManager) SetOnSessionCreated added in v0.16.0

func (m *SessionManager) SetOnSessionCreated(callback SessionCreatedCallback)

SetOnSessionCreated sets a callback called when a session is created.

func (*SessionManager) SetOnSessionDestroyed added in v0.16.0

func (m *SessionManager) SetOnSessionDestroyed(callback SessionDestroyedCallback)

SetOnSessionDestroyed sets a callback called when a session is destroyed.

type WebSocketEndpoint

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

WebSocketEndpoint handles WebSocket connections.

func NewWebSocketEndpoint

func NewWebSocketEndpoint(cfg *config.Config, sessions *SessionManager, handler *protocol.Handler) *WebSocketEndpoint

NewWebSocketEndpoint creates a new WebSocket endpoint.

func (*WebSocketEndpoint) Broadcast

func (ws *WebSocketEndpoint) Broadcast(sessionID string, msg *protocol.Message) error

Broadcast sends a message to all connections in a session.

func (*WebSocketEndpoint) ExecuteInSession added in v0.9.0

func (ws *WebSocketEndpoint) ExecuteInSession(sessionID string, fn func() (interface{}, error)) (interface{}, error)

ExecuteInSession executes a function within a session's executor. This serializes the execution with WebSocket message processing for the session. AfterBatch is called after execution to detect and push any changes, but only if there are active browser connections to receive the updates. Returns the result and any error from the function.

func (*WebSocketEndpoint) ExecuteInSessionAsync added in v0.19.0

func (ws *WebSocketEndpoint) ExecuteInSessionAsync(sessionID string, fn func() (interface{}, error))

ExecuteInSessionAsync is a fire-and-forget variant of ExecuteInSession. It queues execution through ChanSvc using Svc (async) instead of SvcSync (blocking). AfterBatch is called after execution to detect and push any changes. CRC: crc-LuaSession.md Seq: seq-session-timer.md

func (*WebSocketEndpoint) GenerateReconnectToken

func (ws *WebSocketEndpoint) GenerateReconnectToken(sessionID string) string

GenerateReconnectToken creates a token for validating reconnection.

func (*WebSocketEndpoint) GetSessionID

func (ws *WebSocketEndpoint) GetSessionID(connectionID string) (string, bool)

GetSessionID returns the session ID for a connection.

func (*WebSocketEndpoint) GetSessionIDForConnection

func (ws *WebSocketEndpoint) GetSessionIDForConnection(connectionID string) string

GetSessionIDForConnection returns the session ID for a connection. Returns empty string if connection is not found.

func (*WebSocketEndpoint) HandleWebSocket

func (ws *WebSocketEndpoint) HandleWebSocket(w http.ResponseWriter, r *http.Request, sessionID string)

HandleWebSocket handles incoming WebSocket connections.

func (*WebSocketEndpoint) HasConnectionsForSession added in v0.9.0

func (ws *WebSocketEndpoint) HasConnectionsForSession(sessionID string) bool

HasConnectionsForSession returns true if the session has any active connections.

func (*WebSocketEndpoint) IsConnected

func (ws *WebSocketEndpoint) IsConnected(connectionID string) bool

IsConnected checks if a connection is active.

func (*WebSocketEndpoint) IsSessionReconnectable

func (ws *WebSocketEndpoint) IsSessionReconnectable(sessionID string) bool

IsSessionReconnectable checks if a session can be rejoined. A session can be rejoined if it exists and hasn't timed out.

func (*WebSocketEndpoint) Log

func (ws *WebSocketEndpoint) Log(level int, format string, args ...interface{})

Log logs a message via the config.

func (*WebSocketEndpoint) Send

func (ws *WebSocketEndpoint) Send(connectionID string, msg *protocol.Message) error

Send sends a message to a specific connection.

func (*WebSocketEndpoint) SendBatch added in v0.16.0

func (ws *WebSocketEndpoint) SendBatch(connectionID string, msgs []*protocol.Message) error

SendBatch sends multiple messages as a JSON array to a specific connection. Spec: protocol.md - Server sends batched messages as JSON arrays

func (*WebSocketEndpoint) SetAfterBatch

func (ws *WebSocketEndpoint) SetAfterBatch(callback AfterBatchCallback)

SetAfterBatch sets the callback for change detection after message processing.

func (*WebSocketEndpoint) SetOnDisconnect added in v0.9.0

func (ws *WebSocketEndpoint) SetOnDisconnect(callback DisconnectCallback)

SetOnDisconnect sets the callback for when a connection disconnects. This is used to clear sent-tracking so page refreshes resync all state.

func (*WebSocketEndpoint) ValidateReconnectToken

func (ws *WebSocketEndpoint) ValidateReconnectToken(sessionID, token string) bool

ValidateReconnectToken validates a reconnection token.

Jump to

Keyboard shortcuts

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