Documentation
¶
Overview ¶
Stages 1-6 wiring shared with PoC #1. Gathers everything into a Session the rest of poc2a can pull from (signal client, both peer wrappers, the publisher tracks, the goloom IDs we negotiated).
Index ¶
- Constants
- func Handshake(ctx context.Context, lg *log.Logger, sess *Session, sender *tunnel.Sender, ...) (string, error)
- func InitiatorLabel(b bool) string
- func MakeKeyframePusher(track *webrtc.TrackLocalStaticSample, lg *log.Logger, cooldown time.Duration) func()
- func RunKeyframeRefresh(ctx context.Context, lg *log.Logger, track *webrtc.TrackLocalStaticSample)
- func RunKeyframeRefreshFast(ctx context.Context, lg *log.Logger, track *webrtc.TrackLocalStaticSample, ...)
- func RunOpusSilenceLoop(ctx context.Context, lg *log.Logger, track *webrtc.TrackLocalStaticSample)
- func SendInitialKeyframes(lg *log.Logger, track *webrtc.TrackLocalStaticSample, n int) error
- func StartRTCPLoop(ctx context.Context, lg *log.Logger, tag string, pc *webrtc.PeerConnection, ...)
- type ParsedSlot
- type ParsedSlotsConfig
- type Session
- func (s *Session) Close()
- func (s *Session) DefaultDataChannel() *webrtc.DataChannel
- func (s *Session) KnownPeers() map[string]string
- func (s *Session) NewVideoTracks() <-chan *webrtc.TrackRemote
- func (s *Session) RebindSlots(ctx context.Context, key int) error
- func (s *Session) ResetHandshakeState()
- func (s *Session) ServerHello() *goloom.ServerHello
- func (s *Session) SetupScreenShare(ctx context.Context) error
- func (s *Session) WaitForPeer(ctx context.Context, timeout time.Duration) (string, error)
- func (s *Session) WaitForPeerScreenShareBinding(ctx context.Context, peerID string, timeout time.Duration) (string, error)
- func (s *Session) WaitForSubRenegotiation(ctx context.Context, timeout time.Duration) bool
Constants ¶
const HandshakeInterval = 500 * time.Millisecond
const HandshakeTimeout = 120 * time.Second
Variables ¶
This section is empty.
Functions ¶
func InitiatorLabel ¶
func MakeKeyframePusher ¶
func RunKeyframeRefresh ¶
func RunKeyframeRefreshFast ¶
func RunOpusSilenceLoop ¶
func SendInitialKeyframes ¶
func StartRTCPLoop ¶
func StartRTCPLoop(ctx context.Context, lg *log.Logger, tag string, pc *webrtc.PeerConnection, onPLI func())
startRTCPLoop reads RTCP from every RTPSender on the supplied PC. SFU feedback like PLI / FIR / REMB lands here for our publisher track. Returns immediately; per-sender goroutines run until ctx is done.
onPLI is called (in the read goroutine) whenever a PLI or FIR arrives on the video sender — caller should respond by pushing a fresh keyframe down the same track ASAP so the SFU stops dropping our frames.
Types ¶
type ParsedSlot ¶
type ParsedSlotsConfig ¶
type ParsedSlotsConfig struct {
Key int
Slots []ParsedSlot
}
ParsedSlotsConfig is what SetupScreenShare waits on — it carries the full snapshot so the consumer can pick out the peer's screen-share mid binding.
type Session ¶
type Session struct {
Logger *log.Logger
Conn *api.ConnectionResponse
Client *goloom.Client
Pub *peer.Wrapper
Sub *peer.Wrapper
AudioTrack *webrtc.TrackLocalStaticSample
VideoTrack *webrtc.TrackLocalStaticSample
DisplayAudioTrack *webrtc.TrackLocalStaticSample // populated by SetupScreenShare
DisplayVideoTrack *webrtc.TrackLocalStaticSample // populated by SetupScreenShare
// contains filtered or unexported fields
}
Session holds everything the test phases need after connect.
func SetupSession ¶
func SetupSession(ctx context.Context, lg *log.Logger, meeting, displayName string) (*Session, error)
SetupSession runs Stage 1-4 + creates both PCs, exchanges SDP, waits for connected, sends initial sized setSlots. After it returns the caller can use Session to drive tunnel sender / receiver.
func (*Session) Close ¶
func (s *Session) Close()
Close tears the Telemost session down properly: closes both PeerConnections (so DTLS sends a close_notify and ICE goes "failed" fast on the SFU side) AND closes the signalling WebSocket with a "bye" reason. The SFU drops the participant from the room as soon as the WebSocket goes away — without this step our restart cycles leave "zombie" peers that linger for ~30s on ICE timeout.
Safe to call multiple times. Best-effort: errors are logged, never returned, since at this point the caller is already tearing down.
Close order matters for "no zombie peer" behaviour:
- Close the WebSocket first — that's the signalling channel the SFU uses to track participant presence. Once we send a normal-closure close frame, the SFU drops us from the room immediately, BEFORE waiting for ICE/DTLS timeouts on the media side.
- Then close PeerConnections (DTLS close_notify). ICE state will converge to "closed" on its own; without WS bye first the SFU would keep our peer slot warm for the full ICE timeout (~30s).
func (*Session) DefaultDataChannel ¶
func (s *Session) DefaultDataChannel() *webrtc.DataChannel
func (*Session) KnownPeers ¶
KnownPeers returns participantId -> name for everyone the SFU has told us about (us + others). Caller filters out self.
func (*Session) NewVideoTracks ¶
func (s *Session) NewVideoTracks() <-chan *webrtc.TrackRemote
NewVideoTracks returns a channel that yields every remote video track as it arrives via OnTrack. The channel is buffered (size 8) — under normal conditions the consumer drains immediately so it never blocks the SUB PC callback thread.
func (*Session) RebindSlots ¶
RebindSlots re-sends setSlots to force SFU to re-evaluate participant bindings. Called after both peers have completed SetupScreenShare so the later-renegotiated peer gets proper screen-share binding (not just participant binding to whoever was active when its setSlots first arrived).
func (*Session) ResetHandshakeState ¶
func (s *Session) ResetHandshakeState()
ResetHandshakeState is a no-op placeholder — handshake() is stateless and reads from the merged channel. Any leftover frames from the camera handshake are HELLO/HELLO_ACK frames which will be re-processed correctly (idempotent).
func (*Session) ServerHello ¶
func (s *Session) ServerHello() *goloom.ServerHello
func (*Session) SetupScreenShare ¶
SetupScreenShare adds DISPLAY_AUDIO + DISPLAY_VIDEO transceivers, drives a renegotiation round (publisherSdpOffer pcSeq=1 with all 4 tracks -> publisherSdpAnswer -> SetRemoteDescription), pushes updatePublisherTrackDescription, and finally sends an updated setSlots asking the SFU to forward peer's screen-share. Returns when both transceivers are wired up and the answer is applied. Caller is responsible for waiting on Session.slotsCh for the actual peer-binding (peer may not have renegotiated yet at this point).
pcSeq stays at 1 — same PeerConnection instance, just renegotiation.
func (*Session) WaitForPeer ¶
WaitForPeer blocks until we discover another participant (via updateDescription / upsertDescription). Returns the first non-self participantId. Times out after timeout.
func (*Session) WaitForPeerScreenShareBinding ¶
func (s *Session) WaitForPeerScreenShareBinding(ctx context.Context, peerID string, timeout time.Duration) (string, error)
WaitForPeerScreenShareBinding consumes slotsCh until it sees a slot with participantScreenSharingByMid for peerID. Returns the bound mid (e.g. "video_AA"). Times out after timeout.
func (*Session) WaitForSubRenegotiation ¶
WaitForSubRenegotiation blocks until the subscriber renegotiation loop processes at least one new subscriberSdpOffer. This is the signal that the SFU pushed us new tracks (e.g. the peer's screen-share). Returns true if a renegotiation happened, false on timeout.