transport

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: 3 Imported by: 0

README

Transport

Package transport defines the transport interface for pipeline input/output and provides implementations: WebSocket, SmallWebRTC, and in-memory (for tests).

Purpose

A Transport supplies frames from the client to the pipeline (Input channel) and receives frames from the pipeline to send to the client (Output channel). The pipeline runner calls Start(ctx) to establish the connection, then reads from Input() and writes to Output() until context is cancelled or the transport is closed.

Exported symbols (root package)

Symbol Type Description
Transport interface Input() <-chan Frame, Output() chan<- Frame, Start(ctx) error, Close() error
Base struct Optional base for implementations; Name, Log (Logger); SetName, GetName, Logf
Logger interface Printf(format string, v ...interface{})

Implementations

Subpackage Type Description
websocket ConnTransport WebSocket connection; frames serialized (JSON or custom) over the wire; read/write goroutines; Upgrade, NewConnTransport, Input, Output, Start, Close, Done, LastActivity
smallwebrtc Transport WebRTC peer connection; inbound RTP/Opus → PCM to Input; TTS PCM → Opus to Output; Config, NewTransport, HandleOffer, Start, Close, Input, Output; CGO for Opus encoder
memory Transport In-memory channels for tests; NewTransport, NewTransportWithBuffer, SendInput, Out; no network

Connection lifecycle

stateDiagram-v2
    [*] --> Idle
    Idle --> Connecting : new transport
    Connecting --> Handshaking : TCP / upgrade or offer
    Handshaking --> Active : Start(ctx) / HandleOffer done
    Active --> Draining : Close() or connection lost
    Draining --> [*] : channels closed
    Active --> Reconnecting : optional (WebSocket reconnect)
    Reconnecting --> Connecting : retry
  • WebSocket: Server upgrades HTTP → WebSocket; ConnTransport starts read/write goroutines; Start returns when ready; Close closes channels and connection.
  • SmallWebRTC: Client sends SDP offer; server calls HandleOffer → SDP answer; Start starts inbound/outbound processing; Close closes peer connection and channels.
  • Memory: Start returns immediately; Close closes input channel (output left open to avoid panic from in-flight sends).

Concurrency

  • Transport interface: Implementations must allow concurrent reads from Input() and writes to Output() from different goroutines; Close is typically idempotent and must not be called concurrently with sends after close.
  • websocket.ConnTransport: Read loop goroutine (client → inCh); write loop goroutine (outCh → client); Close closes channels and connection; Done() signals shutdown.
  • smallwebrtc.Transport: Inbound RTP processed in peer connection callback → inCh; outbound from outCh encoded and sent on track; Close via sync.Once.
  • memory.Transport: Caller goroutines use SendInput; runner reads Input and writes Output; Close closes inCh and closed channel.

Files (root)

File Description
transport.go Transport interface
base.go Base, Logger

Subpackages

Path Description
websocket/ WebSocket transport; reconnect helpers in reconnect.go
smallwebrtc/ WebRTC transport; Opus inbound/outbound (CGO and nocgo)
memory/ In-memory transport for tests
whatsapp/ WhatsApp-specific transport and API

See also

Documentation

Overview

Package transport defines an optional base for transports with common fields (name, logger).

Package transport defines the transport interface for pipeline input/output.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base struct {
	Name string
	// Log can be nil; if set, used for transport-level logging.
	Log Logger
}

Base holds common transport fields. Embed in concrete transport implementations.

func (*Base) GetName

func (b *Base) GetName() string

GetName returns the transport name.

func (*Base) Logf

func (b *Base) Logf(format string, v ...interface{})

Logf logs if Log is set; otherwise no-op. Pass a *log.Logger for Log to use default logging.

func (*Base) SetName

func (b *Base) SetName(name string)

SetName sets the transport name.

type Logger

type Logger interface {
	Printf(format string, v ...interface{})
}

Logger interface for optional transport logging (e.g. *log.Logger).

type Transport

type Transport interface {
	Input() <-chan frames.Frame
	Output() chan<- frames.Frame
	Start(ctx context.Context) error
	Close() error
}

Transport provides frame input and output for a pipeline (e.g. WebSocket client).

Directories

Path Synopsis
Package memory provides an in-memory transport for testing and stress testing.
Package memory provides an in-memory transport for testing and stress testing.
Package smallwebrtc provides a WebRTC transport for Voxray using pion/webrtc.
Package smallwebrtc provides a WebRTC transport for Voxray using pion/webrtc.
Package websocket provides WebSocket transport (server and client) for Voxray.
Package websocket provides WebSocket transport (server and client) for Voxray.
Package whatsapp provides WhatsApp Cloud API client and transport for Voxray.
Package whatsapp provides WhatsApp Cloud API client and transport for Voxray.

Jump to

Keyboard shortcuts

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