Documentation
¶
Index ¶
- Constants
- Variables
- func CreatePeerConnection(useIceServers bool) (*webrtc.PeerConnection, error)
- func GenerateSessionID() string
- func HandleOffer(w http.ResponseWriter, r *http.Request)
- func HandleWebSocket(w http.ResponseWriter, r *http.Request)
- func SetupAudioTrackHandler(pc *webrtc.PeerConnection)
- type CandidatePayload
- type MockOpusDecoder
- type OpusDecoder
- type RealOpusDecoder
- type SDPExchange
- type SessionManager
- func (sm *SessionManager) CreateSession(id string, useIceServers bool) (*WebRTCSession, error)
- func (sm *SessionManager) GetSession(id string) (*WebRTCSession, bool)
- func (sm *SessionManager) RemoveSession(id string)
- func (sm *SessionManager) SetWebSocket(id string, ws *websocket.Conn) bool
- func (sm *SessionManager) StopCleanup()
- func (sm *SessionManager) UpdateActivity(id string)
- type WebRTCSession
- type WebSocketMessage
Constants ¶
const ( // AudioSampleRate is the sample rate for audio processing AudioSampleRate = 48000 // WebRTC default is 48kHz // AudioChannels is the number of audio channels AudioChannels = 1 // Mono audio for speech recognition // OpusFrameSize is the size of an Opus frame in samples OpusFrameSize = 960 // 20ms at 48kHz // BufferDuration is the duration in seconds to buffer audio before transcription BufferDuration = 3 // Buffer 3 seconds of audio for transcription )
const (
MessageTypeCandidate = "candidate"
)
Message types for WebSocket communication
Variables ¶
var GlobalSessionManager = NewSessionManager()
Initialize a global session manager
var UseIceServers bool
Global variable to store the useIceServers flag
Functions ¶
func CreatePeerConnection ¶
CreatePeerConnection creates and configures a new WebRTC peer connection
func GenerateSessionID ¶
func GenerateSessionID() string
GenerateSessionID creates a new unique session ID
func HandleOffer ¶
func HandleOffer(w http.ResponseWriter, r *http.Request)
HandleOffer handles incoming WebRTC offers from clients
func HandleWebSocket ¶
func HandleWebSocket(w http.ResponseWriter, r *http.Request)
HandleWebSocket handles WebSocket connections for ICE candidate exchange
func SetupAudioTrackHandler ¶
func SetupAudioTrackHandler(pc *webrtc.PeerConnection)
SetupAudioTrackHandler configures the handlers for incoming audio tracks
Types ¶
type CandidatePayload ¶
type CandidatePayload struct { Candidate string `json:"candidate"` // Correct tag format SDPMid string `json:"sdpMid"` // Correct tag format SDPMLineIndex uint16 `json:"sdpMLineIndex"` // Correct tag format UsernameFragment string `json:"usernameFragment"` // Correct tag format }
CandidatePayload represents the structure expected for an ICE candidate payload Matches the structure sent by the browser's `event.candidate.toJSON()`
type MockOpusDecoder ¶
type MockOpusDecoder struct {
// contains filtered or unexported fields
}
MockOpusDecoder provides a fallback implementation for development/testing
func (*MockOpusDecoder) Close ¶
func (d *MockOpusDecoder) Close() error
Close is a no-op for the mock decoder
type OpusDecoder ¶
OpusDecoder interface defines the requirements for an Opus decoder
func NewMockOpusDecoder ¶
func NewMockOpusDecoder() OpusDecoder
NewMockOpusDecoder creates a new mock Opus decoder
func NewOpusDecoder ¶
func NewOpusDecoder(sampleRate int, channels int) (OpusDecoder, error)
NewOpusDecoder creates a new Opus decoder instance The real implementation is in real_opus.go, but the function is declared here so it can be called from the rest of the code
type RealOpusDecoder ¶
type RealOpusDecoder struct {
// contains filtered or unexported fields
}
RealOpusDecoder implements the OpusDecoder interface using libopus
func (*RealOpusDecoder) Close ¶
func (d *RealOpusDecoder) Close() error
Close releases resources used by the decoder
type SDPExchange ¶
type SDPExchange struct { SDP string `json:"sdp"` Type string `json:"type"` // "offer" or "answer" }
SDPExchange represents the SDP offer or answer exchanged between peers
type SessionManager ¶
type SessionManager struct {
// contains filtered or unexported fields
}
SessionManager handles tracking and cleanup of WebRTC sessions
func NewSessionManager ¶
func NewSessionManager() *SessionManager
NewSessionManager creates a new session manager
func (*SessionManager) CreateSession ¶
func (sm *SessionManager) CreateSession(id string, useIceServers bool) (*WebRTCSession, error)
CreateSession creates a new WebRTC session
func (*SessionManager) GetSession ¶
func (sm *SessionManager) GetSession(id string) (*WebRTCSession, bool)
GetSession retrieves a session by ID
func (*SessionManager) RemoveSession ¶
func (sm *SessionManager) RemoveSession(id string)
RemoveSession removes a session and cleans up resources
func (*SessionManager) SetWebSocket ¶
func (sm *SessionManager) SetWebSocket(id string, ws *websocket.Conn) bool
SetWebSocket associates a WebSocket connection with a session
func (*SessionManager) StopCleanup ¶
func (sm *SessionManager) StopCleanup()
StopCleanup gracefully stops the cleanup goroutine
func (*SessionManager) UpdateActivity ¶
func (sm *SessionManager) UpdateActivity(id string)
UpdateActivity updates the last activity timestamp for a session
type WebRTCSession ¶
type WebRTCSession struct { ID string PeerConnection *webrtc.PeerConnection WebSocket *websocket.Conn CreatedAt time.Time LastActivity time.Time // contains filtered or unexported fields }
WebRTCSession represents a WebRTC session with its peer connection and related state
type WebSocketMessage ¶
type WebSocketMessage struct { Type string `json:"type"` // Correct tag format Payload json.RawMessage `json:"payload"` // Correct tag format }
WebSocketMessage represents a generic message sent over WebSocket