webrtc

package
v0.139.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 5 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 DCHandler

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

DCHandler is called when a new DataChannel opens on a peer connection.

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