rtc

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2021 License: Apache-2.0 Imports: 36 Imported by: 3

Documentation

Index

Constants

View Source
const (
	DefaultEmptyTimeout       = 5 * 60 // 5m
	DefaultRoomDepartureGrace = 20
	AudioLevelQuantization    = 8 // ideally power of 2 to minimize float decimal
)

Variables

View Source
var (
	ErrRoomClosed              = errors.New("room has already closed")
	ErrPermissionDenied        = errors.New("no permissions to access the room")
	ErrMaxParticipantsExceeded = errors.New("room has exceeded its max participants")
	ErrAlreadyJoined           = errors.New("a participant with the same identity is already in the room")
	ErrUnexpectedOffer         = errors.New("expected answer SDP, received offer")
	ErrDataChannelUnavailable  = errors.New("data channel is not available")
	ErrCannotSubscribe         = errors.New("participant does not have permission to subscribe")
)

Functions

func ConvertAudioLevel added in v0.9.14

func ConvertAudioLevel(level uint8) float32

convert decibel back to linear

func FixedPointToPercent added in v0.14.0

func FixedPointToPercent(frac uint8) uint32

converts a fixed point number to the number part of %

func FromProtoSessionDescription

func FromProtoSessionDescription(sd *livekit.SessionDescription) webrtc.SessionDescription

func FromProtoTrickle

func FromProtoTrickle(trickle *livekit.TrickleRequest) (webrtc.ICECandidateInit, error)

func IsEOF

func IsEOF(err error) bool

func PackDataTrackLabel

func PackDataTrackLabel(participantId, trackId string, label string) string

func PackStreamID

func PackStreamID(participantId, trackId string) string

func Recover

func Recover()

func RecoverSilent

func RecoverSilent()

func ToProtoParticipants

func ToProtoParticipants(participants []types.Participant) []*livekit.ParticipantInfo

func ToProtoSessionDescription

func ToProtoSessionDescription(sd webrtc.SessionDescription) *livekit.SessionDescription

func ToProtoTrackKind

func ToProtoTrackKind(kind webrtc.RTPCodecType) livekit.TrackType

func ToProtoTrickle

func ToProtoTrickle(candidateInit webrtc.ICECandidateInit) *livekit.TrickleRequest

func UnpackDataTrackLabel

func UnpackDataTrackLabel(packed string) (peerId string, trackId string, label string)

func UnpackStreamID

func UnpackStreamID(packed string) (participantId string, trackId string)

Types

type AudioLevel

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

keeps track of audio level for a participant

func NewAudioLevel

func NewAudioLevel(activeLevel uint8, minPercentile uint8) *AudioLevel

func (*AudioLevel) GetLevel

func (l *AudioLevel) GetLevel() (uint8, bool)

returns current audio level, 0 (loudest) to 127 (silent)

func (*AudioLevel) Observe

func (l *AudioLevel) Observe(level uint8)

Observes a new frame, must be called from the same thread

type MediaTrack

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

MediaTrack represents a WebRTC track that needs to be forwarded Implements the PublishedTrack interface

func NewMediaTrack

func NewMediaTrack(track *webrtc.TrackRemote, params MediaTrackParams) *MediaTrack

func (*MediaTrack) AddReceiver

func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.TrackRemote, twcc *twcc.Responder)

AddReceiver adds a new RTP receiver to the track

func (*MediaTrack) AddSubscriber

func (t *MediaTrack) AddSubscriber(sub types.Participant) error

AddSubscriber subscribes sub to current mediaTrack

func (*MediaTrack) DebugInfo added in v0.10.6

func (t *MediaTrack) DebugInfo() map[string]interface{}

func (*MediaTrack) GetQualityForDimension added in v0.13.7

func (t *MediaTrack) GetQualityForDimension(width, height uint32) livekit.VideoQuality

GetQualityForDimension finds the closest quality to use for desired dimensions affords a 10% tolerance on dimension

func (*MediaTrack) ID

func (t *MediaTrack) ID() string

func (*MediaTrack) IsMuted

func (t *MediaTrack) IsMuted() bool

func (*MediaTrack) IsSubscriber added in v0.9.2

func (t *MediaTrack) IsSubscriber(subId string) bool

func (*MediaTrack) Kind

func (t *MediaTrack) Kind() livekit.TrackType

func (*MediaTrack) Name

func (t *MediaTrack) Name() string

func (*MediaTrack) NumUpTracks added in v0.12.1

func (t *MediaTrack) NumUpTracks() (uint32, uint32)

func (*MediaTrack) OnClose

func (t *MediaTrack) OnClose(f func())

func (*MediaTrack) PublishLossPercentage added in v0.14.0

func (t *MediaTrack) PublishLossPercentage() uint32

func (*MediaTrack) RemoveAllSubscribers

func (t *MediaTrack) RemoveAllSubscribers()

func (*MediaTrack) RemoveSubscriber

func (t *MediaTrack) RemoveSubscriber(participantId string)

RemoveSubscriber removes participant from subscription stop all forwarders to the client

func (*MediaTrack) SdpCid added in v0.13.6

func (t *MediaTrack) SdpCid() string

func (*MediaTrack) SetMuted

func (t *MediaTrack) SetMuted(muted bool)

func (*MediaTrack) SignalCid added in v0.13.6

func (t *MediaTrack) SignalCid() string

func (*MediaTrack) Start

func (t *MediaTrack) Start()

func (*MediaTrack) ToProto added in v0.9.13

func (t *MediaTrack) ToProto() *livekit.TrackInfo

type MediaTrackParams

type MediaTrackParams struct {
	TrackInfo           *livekit.TrackInfo
	SignalCid           string
	SdpCid              string
	ParticipantID       string
	ParticipantIdentity string
	RTCPChan            chan []rtcp.Packet
	BufferFactory       *buffer.Factory
	ReceiverConfig      ReceiverConfig
	AudioConfig         config.AudioConfig
	Telemetry           *telemetry.TelemetryService
	Logger              logger.Logger
}

type PCTransport

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

PCTransport is a wrapper around PeerConnection, with some helper methods

func NewPCTransport

func NewPCTransport(params TransportParams) (*PCTransport, error)

func (*PCTransport) AddICECandidate

func (t *PCTransport) AddICECandidate(candidate webrtc.ICECandidateInit) error

func (*PCTransport) Close

func (t *PCTransport) Close()

func (*PCTransport) CreateAndSendOffer

func (t *PCTransport) CreateAndSendOffer(options *webrtc.OfferOptions) error

func (*PCTransport) Negotiate

func (t *PCTransport) Negotiate()

func (*PCTransport) OnOffer

func (t *PCTransport) OnOffer(f func(sd webrtc.SessionDescription))

OnOffer is called when the PeerConnection starts negotiation and prepares an offer

func (*PCTransport) PeerConnection

func (t *PCTransport) PeerConnection() *webrtc.PeerConnection

func (*PCTransport) SetRemoteDescription

func (t *PCTransport) SetRemoteDescription(sd webrtc.SessionDescription) error

type ParticipantImpl

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

func NewParticipant

func NewParticipant(params ParticipantParams) (*ParticipantImpl, error)

func (*ParticipantImpl) AddICECandidate

func (p *ParticipantImpl) AddICECandidate(candidate webrtc.ICECandidateInit, target livekit.SignalTarget) error

AddICECandidate adds candidates for remote peer

func (*ParticipantImpl) AddSubscribedTrack

func (p *ParticipantImpl) AddSubscribedTrack(subTrack types.SubscribedTrack)

AddSubscribedTrack adds a track to the participant's subscribed list

func (*ParticipantImpl) AddSubscriber

func (p *ParticipantImpl) AddSubscriber(op types.Participant) (int, error)

AddSubscriber subscribes op to all publishedTracks

func (*ParticipantImpl) AddTrack

func (p *ParticipantImpl) AddTrack(req *livekit.AddTrackRequest)

AddTrack is called when client intends to publish track. records track details and lets client know it's ok to proceed

func (*ParticipantImpl) CanPublish

func (p *ParticipantImpl) CanPublish() bool

func (*ParticipantImpl) CanPublishData added in v0.12.2

func (p *ParticipantImpl) CanPublishData() bool

func (*ParticipantImpl) CanSubscribe

func (p *ParticipantImpl) CanSubscribe() bool

func (*ParticipantImpl) Close

func (p *ParticipantImpl) Close() error

func (*ParticipantImpl) ConnectedAt

func (p *ParticipantImpl) ConnectedAt() time.Time

func (*ParticipantImpl) DebugInfo added in v0.10.6

func (p *ParticipantImpl) DebugInfo() map[string]interface{}

func (*ParticipantImpl) GetAudioLevel

func (p *ParticipantImpl) GetAudioLevel() (level uint8, active bool)

func (*ParticipantImpl) GetConnectionQuality added in v0.14.0

func (p *ParticipantImpl) GetConnectionQuality() livekit.ConnectionQuality

func (*ParticipantImpl) GetPublishedTrack added in v0.13.7

func (p *ParticipantImpl) GetPublishedTrack(sid string) types.PublishedTrack

func (*ParticipantImpl) GetPublishedTracks

func (p *ParticipantImpl) GetPublishedTracks() []types.PublishedTrack

func (*ParticipantImpl) GetResponseSink

func (p *ParticipantImpl) GetResponseSink() routing.MessageSink

func (*ParticipantImpl) GetSubscribedParticipants added in v0.14.0

func (p *ParticipantImpl) GetSubscribedParticipants() []string

func (*ParticipantImpl) GetSubscribedTrack added in v0.13.7

func (p *ParticipantImpl) GetSubscribedTrack(sid string) types.SubscribedTrack

func (*ParticipantImpl) GetSubscribedTracks

func (p *ParticipantImpl) GetSubscribedTracks() []types.SubscribedTrack

func (*ParticipantImpl) HandleAnswer

func (p *ParticipantImpl) HandleAnswer(sdp webrtc.SessionDescription) error

HandleAnswer handles a client answer response, with subscriber PC, server initiates the offer and client answers

func (*ParticipantImpl) HandleOffer

func (p *ParticipantImpl) HandleOffer(sdp webrtc.SessionDescription) (answer webrtc.SessionDescription, err error)

HandleOffer an offer from remote participant, used when clients make the initial connection

func (*ParticipantImpl) Hidden added in v0.11.1

func (p *ParticipantImpl) Hidden() bool

func (*ParticipantImpl) ICERestart

func (p *ParticipantImpl) ICERestart() error

ICERestart restarts subscriber ICE connections

func (*ParticipantImpl) ID

func (p *ParticipantImpl) ID() string

func (*ParticipantImpl) Identity

func (p *ParticipantImpl) Identity() string

func (*ParticipantImpl) IsReady

func (p *ParticipantImpl) IsReady() bool

func (*ParticipantImpl) IsSubscribedTo added in v0.14.0

func (p *ParticipantImpl) IsSubscribedTo(identity string) bool

func (*ParticipantImpl) Negotiate

func (p *ParticipantImpl) Negotiate()

func (*ParticipantImpl) OnClose

func (p *ParticipantImpl) OnClose(callback func(types.Participant))

func (*ParticipantImpl) OnDataPacket

func (p *ParticipantImpl) OnDataPacket(callback func(types.Participant, *livekit.DataPacket))

func (*ParticipantImpl) OnMetadataUpdate

func (p *ParticipantImpl) OnMetadataUpdate(callback func(types.Participant))

func (*ParticipantImpl) OnStateChange

func (p *ParticipantImpl) OnStateChange(callback func(p types.Participant, oldState livekit.ParticipantInfo_State))

func (*ParticipantImpl) OnTrackPublished

func (p *ParticipantImpl) OnTrackPublished(callback func(types.Participant, types.PublishedTrack))

func (*ParticipantImpl) OnTrackUpdated

func (p *ParticipantImpl) OnTrackUpdated(callback func(types.Participant, types.PublishedTrack))

func (*ParticipantImpl) ProtocolVersion

func (p *ParticipantImpl) ProtocolVersion() types.ProtocolVersion

func (*ParticipantImpl) RTCPChan

func (p *ParticipantImpl) RTCPChan() chan []rtcp.Packet

func (*ParticipantImpl) RemoveSubscribedTrack

func (p *ParticipantImpl) RemoveSubscribedTrack(subTrack types.SubscribedTrack)

RemoveSubscribedTrack removes a track to the participant's subscribed list

func (*ParticipantImpl) RemoveSubscriber

func (p *ParticipantImpl) RemoveSubscriber(participantId string)

func (*ParticipantImpl) SendConnectionQualityUpdate added in v0.14.0

func (p *ParticipantImpl) SendConnectionQualityUpdate(update *livekit.ConnectionQualityUpdate) error

func (*ParticipantImpl) SendDataPacket

func (p *ParticipantImpl) SendDataPacket(dp *livekit.DataPacket) error

func (*ParticipantImpl) SendJoinResponse

func (p *ParticipantImpl) SendJoinResponse(roomInfo *livekit.Room, otherParticipants []types.Participant, iceServers []*livekit.ICEServer) error

func (*ParticipantImpl) SendParticipantUpdate

func (p *ParticipantImpl) SendParticipantUpdate(participantsToUpdate []*livekit.ParticipantInfo, updatedAt time.Time) error

func (*ParticipantImpl) SendRoomUpdate added in v0.13.1

func (p *ParticipantImpl) SendRoomUpdate(room *livekit.Room) error

func (*ParticipantImpl) SendSpeakerUpdate added in v0.13.0

func (p *ParticipantImpl) SendSpeakerUpdate(speakers []*livekit.SpeakerInfo) error

SendSpeakerUpdate notifies participant changes to speakers. only send members that have changed since last update

func (*ParticipantImpl) SetMetadata

func (p *ParticipantImpl) SetMetadata(metadata string)

SetMetadata attaches metadata to the participant

func (*ParticipantImpl) SetPermission

func (p *ParticipantImpl) SetPermission(permission *livekit.ParticipantPermission)

func (*ParticipantImpl) SetResponseSink

func (p *ParticipantImpl) SetResponseSink(sink routing.MessageSink)

func (*ParticipantImpl) SetTrackMuted

func (p *ParticipantImpl) SetTrackMuted(trackId string, muted bool, fromAdmin bool)

func (*ParticipantImpl) Start

func (p *ParticipantImpl) Start()

func (*ParticipantImpl) State

func (*ParticipantImpl) SubscriberMediaEngine

func (p *ParticipantImpl) SubscriberMediaEngine() *webrtc.MediaEngine

func (*ParticipantImpl) SubscriberPC

func (p *ParticipantImpl) SubscriberPC() *webrtc.PeerConnection

func (*ParticipantImpl) ToProto

func (p *ParticipantImpl) ToProto() *livekit.ParticipantInfo

type ParticipantOptions added in v0.9.4

type ParticipantOptions struct {
	AutoSubscribe bool
}

type ParticipantParams

type ParticipantParams struct {
	Identity        string
	Config          *WebRTCConfig
	Sink            routing.MessageSink
	AudioConfig     config.AudioConfig
	ProtocolVersion types.ProtocolVersion
	Telemetry       *telemetry.TelemetryService
	ThrottleConfig  config.PLIThrottleConfig
	EnabledCodecs   []*livekit.Codec
	Hidden          bool
	Logger          logger.Logger
}

type ReceiverConfig

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

type Room

type Room struct {
	Room   *livekit.Room
	Logger logger.Logger
	// contains filtered or unexported fields
}

func NewRoom

func NewRoom(room *livekit.Room, config WebRTCConfig, audioConfig *config.AudioConfig, telemetry *telemetry.TelemetryService) *Room

func (*Room) Close

func (r *Room) Close()

func (*Room) CloseIfEmpty

func (r *Room) CloseIfEmpty()

CloseIfEmpty closes the room if all participants had left, or it's still empty past timeout

func (*Room) DebugInfo added in v0.10.6

func (r *Room) DebugInfo() map[string]interface{}

func (*Room) FirstJoinedAt

func (r *Room) FirstJoinedAt() int64

func (*Room) GetActiveSpeakers

func (r *Room) GetActiveSpeakers() []*livekit.SpeakerInfo

func (*Room) GetBufferFactor added in v0.9.11

func (r *Room) GetBufferFactor() *buffer.Factory

func (*Room) GetParticipant

func (r *Room) GetParticipant(identity string) types.Participant

func (*Room) GetParticipants

func (r *Room) GetParticipants() []types.Participant

func (*Room) IsClosed added in v0.13.7

func (r *Room) IsClosed() bool

func (*Room) Join

func (r *Room) Join(participant types.Participant, opts *ParticipantOptions, iceServers []*livekit.ICEServer) error

func (*Room) LastLeftAt

func (r *Room) LastLeftAt() int64

func (*Room) OnClose

func (r *Room) OnClose(f func())

func (*Room) OnMetadataUpdate added in v0.13.1

func (r *Room) OnMetadataUpdate(f func(metadata string))

func (*Room) OnParticipantChanged

func (r *Room) OnParticipantChanged(f func(participant types.Participant))

func (*Room) RemoveParticipant

func (r *Room) RemoveParticipant(identity string)

func (*Room) ResumeParticipant added in v0.13.7

func (r *Room) ResumeParticipant(p types.Participant, responseSink routing.MessageSink) error

func (*Room) SendDataPacket added in v0.12.2

func (r *Room) SendDataPacket(up *livekit.UserPacket, kind livekit.DataPacket_Kind)

func (*Room) SetMetadata added in v0.13.1

func (r *Room) SetMetadata(metadata string)

func (*Room) UpdateSubscriptions

func (r *Room) UpdateSubscriptions(participant types.Participant, trackIds []string, subscribe bool) error

type SubscribedTrack

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

func NewSubscribedTrack

func NewSubscribedTrack(publisherIdentity string, dt *sfu.DownTrack) *SubscribedTrack

func (*SubscribedTrack) DownTrack

func (t *SubscribedTrack) DownTrack() *sfu.DownTrack

func (*SubscribedTrack) ID

func (t *SubscribedTrack) ID() string

func (*SubscribedTrack) IsMuted

func (t *SubscribedTrack) IsMuted() bool

has subscriber indicated it wants to mute this track

func (*SubscribedTrack) PublisherIdentity added in v0.13.7

func (t *SubscribedTrack) PublisherIdentity() string

func (*SubscribedTrack) SetPublisherMuted

func (t *SubscribedTrack) SetPublisherMuted(muted bool)

func (*SubscribedTrack) SubscribeLossPercentage added in v0.14.0

func (t *SubscribedTrack) SubscribeLossPercentage() uint32

func (*SubscribedTrack) UpdateSubscriberSettings added in v0.9.14

func (t *SubscribedTrack) UpdateSubscriberSettings(enabled bool, quality livekit.VideoQuality)

type TransportParams

type TransportParams struct {
	ParticipantID       string
	ParticipantIdentity string
	Target              livekit.SignalTarget
	Config              *WebRTCConfig
	Telemetry           *telemetry.TelemetryService
	EnabledCodecs       []*livekit.Codec
	Logger              logger.Logger
}

type WebRTCConfig

type WebRTCConfig struct {
	Configuration  webrtc.Configuration
	SettingEngine  webrtc.SettingEngine
	Receiver       ReceiverConfig
	BufferFactory  *buffer.Factory
	UDPMux         ice.UDPMux
	UDPMuxConn     *net.UDPConn
	TCPMuxListener *net.TCPListener
}

func NewWebRTCConfig

func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, error)

func (*WebRTCConfig) SetBufferFactory added in v0.9.11

func (c *WebRTCConfig) SetBufferFactory(factory *buffer.Factory)

type WrappedReceiver

type WrappedReceiver struct {
	sfu.Receiver
	// contains filtered or unexported fields
}

func NewWrappedReceiver

func NewWrappedReceiver(receiver sfu.Receiver, trackId string, streamId string) WrappedReceiver

func (WrappedReceiver) StreamID

func (r WrappedReceiver) StreamID() string

func (WrappedReceiver) TrackID

func (r WrappedReceiver) TrackID() string

Directories

Path Synopsis
typesfakes
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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