session

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: Apache-2.0 Imports: 17 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const HandshakeInterval = 500 * time.Millisecond
View Source
const HandshakeTimeout = 120 * time.Second

Variables

This section is empty.

Functions

func Handshake

func Handshake(ctx context.Context, lg *log.Logger, sess *Session, sender *tunnel.Sender, in <-chan tunnel.ReceivedFrame, round byte) (string, error)

func InitiatorLabel

func InitiatorLabel(b bool) string

func MakeKeyframePusher

func MakeKeyframePusher(track *webrtc.TrackLocalStaticSample, lg *log.Logger, cooldown time.Duration) func()

func RunKeyframeRefresh

func RunKeyframeRefresh(ctx context.Context, lg *log.Logger, track *webrtc.TrackLocalStaticSample)

func RunKeyframeRefreshFast

func RunKeyframeRefreshFast(ctx context.Context, lg *log.Logger, track *webrtc.TrackLocalStaticSample, interval time.Duration)

func RunOpusSilenceLoop

func RunOpusSilenceLoop(ctx context.Context, lg *log.Logger, track *webrtc.TrackLocalStaticSample)

func SendInitialKeyframes

func SendInitialKeyframes(lg *log.Logger, track *webrtc.TrackLocalStaticSample, n int) error

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 ParsedSlot struct {
	Index         int
	Type          string // "selfView" / "participant" / "participantVideoByMid" / "participantScreenSharingByMid" / "empty"
	ParticipantID string
	Mid           string // populated for *ByMid types
}

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:

  1. 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.
  2. 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

func (s *Session) KnownPeers() map[string]string

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

func (s *Session) RebindSlots(ctx context.Context, key int) error

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

func (s *Session) SetupScreenShare(ctx context.Context) error

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

func (s *Session) WaitForPeer(ctx context.Context, timeout time.Duration) (string, error)

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

func (s *Session) WaitForSubRenegotiation(ctx context.Context, timeout time.Duration) bool

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.

Jump to

Keyboard shortcuts

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