webrtc

package
v0.149.4 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalSDP

func MarshalSDP(sdp string) []byte

MarshalSDP encodes an SDP payload to JSON bytes.

Types

type ControlClient added in v0.145.0

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

ControlClient is the initiating half of Wingthing's direct MCP transport. Signaling is performed by the caller; operation payloads use the DataChannel.

func NewControlClient added in v0.145.0

func NewControlClient(actor string, iceServers []webrtc.ICEServer) (*ControlClient, error)

NewControlClient creates a host/LAN-capable peer unless ICE servers are supplied by the selected wing's advertised connection metadata.

func (*ControlClient) AcceptAnswer added in v0.145.0

func (c *ControlClient) AcceptAnswer(sdp string) error

AcceptAnswer completes signaling with the selected wing.

func (*ControlClient) Call added in v0.145.0

func (c *ControlClient) Call(ctx context.Context, tool string, arguments json.RawMessage) (map[string]any, bool, error)

Call sends one control operation and waits for its correlated response.

func (*ControlClient) Close added in v0.145.0

func (c *ControlClient) Close() error

Close releases the peer connection and all of its data channels.

func (*ControlClient) Closed added in v0.145.0

func (c *ControlClient) Closed() bool

Closed reports whether the transport has permanently failed or been closed. Callers may use this to evict a cached client, but must not automatically replay a mutating request whose response may have been lost.

func (*ControlClient) Offer added in v0.145.0

func (c *ControlClient) Offer(ctx context.Context) (string, error)

Offer returns a complete SDP offer, including gathered ICE candidates.

func (*ControlClient) WaitReady added in v0.145.0

func (c *ControlClient) WaitReady(ctx context.Context) error

WaitReady waits for the direct data channel to open.

type DCHandler

type DCHandler func(senderPub, sessionID string, identity PeerIdentity, dc *webrtc.DataChannel)

DCHandler is called as soon as a remote DataChannel is announced, before it opens. Identity is the coordinator-authenticated identity captured by this exact offer; it must not be looked up later by a reusable sender key because several simultaneous offers can share that key. Handlers must install OnMessage callbacks synchronously so the first message cannot race setup.

type PeerIdentity

type PeerIdentity struct {
	UserID   string
	Email    string
	OrgRole  string
	Passkeys []string
}

PeerIdentity holds the relay-injected identity for a sender.

type PeerManager

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

PeerManager manages per-sender WebRTC peer connections.

func NewPeerManager

func NewPeerManager(iceServers []webrtc.ICEServer) *PeerManager

NewPeerManager creates a PeerManager with the given ICE servers. Pass nil for host-only ICE (same-LAN only).

func (*PeerManager) Close

func (pm *PeerManager) Close()

Close shuts down all peer connections.

func (*PeerManager) GetDC

func (pm *PeerManager) GetDC(senderPub, sessionID string) *webrtc.DataChannel

GetDC returns the DataChannel for a given sender and session. Returns nil if no matching DC exists.

func (*PeerManager) GetPeerIdentity

func (pm *PeerManager) GetPeerIdentity(senderPub string) (PeerIdentity, bool)

GetPeerIdentity returns the cached identity for a sender.

func (*PeerManager) HandleOffer

func (pm *PeerManager) HandleOffer(senderPub, userID, email, orgRole string, passkeys []string, sdpOffer string) (string, error)

HandleOffer processes a WebRTC offer from a browser, creating a PeerConnection and returning the answer SDP. Identity is cached from the relay-injected signaling.

func (*PeerManager) OnDC

func (pm *PeerManager) OnDC(handler DCHandler)

OnDC registers a callback for new DataChannels.

type SDPPayload

type SDPPayload struct {
	SDP string `json:"sdp"`
}

SDPPayload is the JSON structure for webrtc.offer/answer tunnel payloads.

type SwappableWriter

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

SwappableWriter manages atomic switching between relay WS and DataChannel writes. It wraps a relay write function and can be migrated to/from a DataChannel.

func NewSwappableWriter

func NewSwappableWriter(relayWrite WriteFn) *SwappableWriter

NewSwappableWriter creates a SwappableWriter backed by the relay write function.

func (*SwappableWriter) FallbackToRelay

func (sw *SwappableWriter) FallbackToRelay(sessionID string) error

FallbackToRelay atomically switches output back to the relay WS. Sends a pty.fallback message via relay so the browser knows.

func (*SwappableWriter) MigrateToDC

func (sw *SwappableWriter) MigrateToDC(sessionID string, dc *webrtc.DataChannel) error

MigrateToDC atomically switches output to a DataChannel. It sends a pty.migrated message via the relay (last WS message for this session) and swaps the write function.

func (*SwappableWriter) Mode

func (sw *SwappableWriter) Mode() string

Mode returns the current transport mode ("relay" or "p2p").

func (*SwappableWriter) Write

func (sw *SwappableWriter) Write(v any) error

Write sends a message via the current active transport. Lock is held through the write call to prevent migration mid-write.

type WriteFn

type WriteFn func(v any) error

WriteFn sends a message over a transport (relay WS or DataChannel).

Jump to

Keyboard shortcuts

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