server

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 16, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package server provides transport servers (e.g. WebSocket, SmallWebRTC) for Voxray.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartServers

func StartServers(ctx context.Context, cfg *config.Config, onTransport func(ctx context.Context, tr transport.Transport), sessionRegistry *SessionRegistry, pipelineStore *PipelineStore, transcriptFetcher transcripts.Fetcher) error

StartServers starts the HTTP server that serves the WebSocket endpoint at /ws and, when transport is smallwebrtc or both, the WebRTC signaling endpoint at POST /webrtc/offer. The onTransport callback is run in a new goroutine for each new connection. sessionRegistry, pipelineStore, and transcriptFetcher are optional (may be nil) and passed to handlers for future API routes. If cfg is nil, StartServers returns nil without starting anything. The server runs until ctx is canceled.

func StartServersWithListener

func StartServersWithListener(ctx context.Context, listener net.Listener, cfg *config.Config, onTransport func(ctx context.Context, tr transport.Transport), sessionRegistry *SessionRegistry, pipelineStore *PipelineStore, transcriptFetcher transcripts.Fetcher) error

StartServersWithListener starts the same HTTP stack as StartServers but uses the provided listener (e.g. from net.Listen("tcp", ":0")). The caller owns the listener and must close it when done. Useful for tests that need a dynamic port. sessionRegistry, pipelineStore, and transcriptFetcher may be nil. If cfg is nil, returns nil without starting.

func WebrtcOfferDoc

func WebrtcOfferDoc()

WebrtcOfferDoc documents the WebRTC offer HTTP endpoint for Swagger. POST /webrtc/offer accepts a JSON body with an "offer" (SDP offer string), creates a new WebRTC transport, and returns an SDP answer. The endpoint returns 400 for invalid or missing offer, 405 for non-POST, and 503 when the server cannot complete the connection (e.g. Opus encoder unavailable). Each request gets its own transport; onTransport is invoked in a new goroutine.

@Summary Submit WebRTC offer @Description Accepts a WebRTC SDP offer and returns an SDP answer. Available when transport is smallwebrtc or both. @Tags webrtc @Accept json @Produce json @Param body body object true "JSON body with 'offer' (SDP offer string)" @Success 200 {object} webrtcOfferResponse @Failure 400 {string} string "Invalid offer or handling failed" @Failure 405 {string} string "Method not allowed" @Router /webrtc/offer [post] Versioned path: /api/v1/webrtc/offer (BasePath /api/v1).

Types

type IdempotencyStore

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

IdempotencyStore caches responses by idempotency key (e.g. for POST /start). Safe for concurrent use.

func NewIdempotencyStore

func NewIdempotencyStore(ttl time.Duration) *IdempotencyStore

NewIdempotencyStore returns a store with the given TTL (e.g. 24*time.Hour). Entries are not proactively cleaned; they are ignored once expired.

type PipelineStore

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

PipelineStore stores pipeline (or runner) references by session ID for API access. THREAD SAFETY: mu protects m; Put/Delete are writers; Get is reader; safe for concurrent use from multiple goroutines.

func NewPipelineStore

func NewPipelineStore() *PipelineStore

NewPipelineStore returns a new in-memory pipeline store.

func (*PipelineStore) Delete

func (s *PipelineStore) Delete(sessionID string)

Delete removes the session ID from the store.

func (*PipelineStore) Get

func (s *PipelineStore) Get(sessionID string) (interface{}, bool)

Get returns the value for the session ID, and true if found.

func (*PipelineStore) Put

func (s *PipelineStore) Put(sessionID string, value interface{})

Put stores a value for the session ID.

type SessionMeta

type SessionMeta struct {
	SessionID string
	CreatedAt time.Time
}

SessionMeta holds metadata for a registered session.

type SessionRegistry

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

SessionRegistry is an in-memory registry of active sessions with optional cancel. THREAD SAFETY: mu protects sess; Register/Unregister are single-writer per key; Get (via internal lookup) may run concurrently with other readers.

func NewSessionRegistry

func NewSessionRegistry() *SessionRegistry

NewSessionRegistry returns a new in-memory session registry.

func (*SessionRegistry) Register

func (r *SessionRegistry) Register(sessionID string, meta SessionMeta, cancel func())

Register adds a session to the registry.

func (*SessionRegistry) Unregister

func (r *SessionRegistry) Unregister(sessionID string)

Unregister removes a session from the registry.

Jump to

Keyboard shortcuts

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