chore: added docstrings to public APIs (#746)
This commit is contained in:
@@ -49,6 +49,7 @@ type ParticipantCallback struct {
|
||||
OnTranscriptionReceived func(transcriptionSegments []*TranscriptionSegment, p Participant, publication TrackPublication)
|
||||
}
|
||||
|
||||
// NewParticipantCallback creates a new ParticipantCallback with default no-op handlers.
|
||||
func NewParticipantCallback() *ParticipantCallback {
|
||||
return &ParticipantCallback{
|
||||
OnLocalTrackPublished: func(publication *LocalTrackPublication, lp *LocalParticipant) {},
|
||||
@@ -71,6 +72,7 @@ func NewParticipantCallback() *ParticipantCallback {
|
||||
}
|
||||
}
|
||||
|
||||
// Merge copies non-nil callback functions from other to this callback.
|
||||
func (cb *ParticipantCallback) Merge(other *ParticipantCallback) {
|
||||
if other.OnLocalTrackPublished != nil {
|
||||
cb.OnLocalTrackPublished = other.OnLocalTrackPublished
|
||||
@@ -135,6 +137,7 @@ const (
|
||||
OtherReason DisconnectionReason = "other reasons"
|
||||
)
|
||||
|
||||
// GetDisconnectionReason converts a protocol disconnect reason to a DisconnectionReason.
|
||||
func GetDisconnectionReason(reason livekit.DisconnectReason) DisconnectionReason {
|
||||
// TODO: SDK should forward the original reason and provide helpers like IsRequestedLeave.
|
||||
r := OtherReason
|
||||
@@ -173,6 +176,7 @@ type RoomCallback struct {
|
||||
ParticipantCallback
|
||||
}
|
||||
|
||||
// NewRoomCallback creates a new RoomCallback with default no-op handlers.
|
||||
func NewRoomCallback() *RoomCallback {
|
||||
pc := NewParticipantCallback()
|
||||
return &RoomCallback{
|
||||
@@ -191,6 +195,7 @@ func NewRoomCallback() *RoomCallback {
|
||||
}
|
||||
}
|
||||
|
||||
// Merge copies non-nil callback functions from other to this callback.
|
||||
func (cb *RoomCallback) Merge(other *RoomCallback) {
|
||||
if other == nil {
|
||||
return
|
||||
|
||||
7
data.go
7
data.go
@@ -22,7 +22,7 @@ var (
|
||||
_ DataPacket = (*livekit.ChatMessage)(nil) // implemented in the protocol package
|
||||
)
|
||||
|
||||
// UserData is a custom user data that can be sent via WebRTC.
|
||||
// UserData creates a UserDataPacket with opaque bytes that can be sent via WebRTC.
|
||||
func UserData(data []byte) *UserDataPacket {
|
||||
return &UserDataPacket{Payload: data}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ type UserDataPacket struct {
|
||||
Topic string // optional
|
||||
}
|
||||
|
||||
// ToProto implements DataPacket.
|
||||
// ToProto converts the UserDataPacket to a protobuf DataPacket.
|
||||
func (p *UserDataPacket) ToProto() *livekit.DataPacket {
|
||||
var topic *string
|
||||
if p.Topic != "" {
|
||||
@@ -48,6 +48,7 @@ func (p *UserDataPacket) ToProto() *livekit.DataPacket {
|
||||
}
|
||||
|
||||
// ChatMessage creates a chat message that can be sent via WebRTC.
|
||||
// If timestamp is zero, current time will be used.
|
||||
func ChatMessage(ts time.Time, text string) *livekit.ChatMessage {
|
||||
if ts.IsZero() {
|
||||
ts = time.Now()
|
||||
@@ -89,6 +90,8 @@ func WithDataPublishReliable(reliable bool) DataPublishOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithDataPublishDestination sets specific participant identities to send data to.
|
||||
// If not set, data will be sent to all participants.
|
||||
func WithDataPublishDestination(identities []string) DataPublishOption {
|
||||
return func(o *dataPublishOptions) {
|
||||
o.DestinationIdentities = identities
|
||||
|
||||
@@ -53,6 +53,8 @@ func newLocalParticipant(engine *RTCEngine, roomcallback *RoomCallback, serverIn
|
||||
}
|
||||
}
|
||||
|
||||
// PublishTrack publishes a local track to the room.
|
||||
// The track will be available to other participants in the room.
|
||||
func (p *LocalParticipant) PublishTrack(track webrtc.TrackLocal, opts *TrackPublicationOptions) (*LocalTrackPublication, error) {
|
||||
if opts == nil {
|
||||
opts = &TrackPublicationOptions{}
|
||||
@@ -139,7 +141,8 @@ func (p *LocalParticipant) PublishTrack(track webrtc.TrackLocal, opts *TrackPubl
|
||||
return pub, nil
|
||||
}
|
||||
|
||||
// PublishSimulcastTrack publishes up to three layers to the server
|
||||
// PublishSimulcastTrack publishes a simulcast track with up to three quality layers to the server.
|
||||
// This allows the server to dynamically switch between different quality levels based on network conditions.
|
||||
func (p *LocalParticipant) PublishSimulcastTrack(tracks []*LocalTrack, opts *TrackPublicationOptions) (*LocalTrackPublication, error) {
|
||||
if len(tracks) == 0 {
|
||||
return nil, nil
|
||||
@@ -370,6 +373,7 @@ func (p *LocalParticipant) PublishDataPacket(pck DataPacket, opts ...DataPublish
|
||||
return p.engine.publishDataPacket(dataPacket, kind)
|
||||
}
|
||||
|
||||
// UnpublishTrack stops publishing a track and removes it from the room.
|
||||
func (p *LocalParticipant) UnpublishTrack(sid string) error {
|
||||
obj, loaded := p.tracks.LoadAndDelete(sid)
|
||||
if !loaded {
|
||||
@@ -408,8 +412,8 @@ func (p *LocalParticipant) UnpublishTrack(sid string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// GetSubscriberPeerConnection is a power-user API that gives access to the underlying subscriber peer connection
|
||||
// subscribed tracks are received using this PeerConnection
|
||||
// GetSubscriberPeerConnection is a power-user API that gives access to the underlying subscriber peer connection.
|
||||
// Subscribed tracks are received using this PeerConnection.
|
||||
func (p *LocalParticipant) GetSubscriberPeerConnection() *webrtc.PeerConnection {
|
||||
if subscriber, ok := p.engine.Subscriber(); ok {
|
||||
return subscriber.PeerConnection()
|
||||
@@ -417,8 +421,8 @@ func (p *LocalParticipant) GetSubscriberPeerConnection() *webrtc.PeerConnection
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetPublisherPeerConnection is a power-user API that gives access to the underlying publisher peer connection
|
||||
// local tracks are published to server via this PeerConnection
|
||||
// GetPublisherPeerConnection is a power-user API that gives access to the underlying publisher peer connection.
|
||||
// Local tracks are published to server via this PeerConnection.
|
||||
func (p *LocalParticipant) GetPublisherPeerConnection() *webrtc.PeerConnection {
|
||||
if publisher, ok := p.engine.Publisher(); ok {
|
||||
return publisher.PeerConnection()
|
||||
@@ -427,7 +431,7 @@ func (p *LocalParticipant) GetPublisherPeerConnection() *webrtc.PeerConnection {
|
||||
}
|
||||
|
||||
// SetName sets the name of the current participant.
|
||||
// updates will be performed only if the participant has canUpdateOwnMetadata grant
|
||||
// Updates will be performed only if the participant has canUpdateOwnMetadata grant.
|
||||
func (p *LocalParticipant) SetName(name string) {
|
||||
_ = p.engine.SendUpdateParticipantMetadata(&livekit.UpdateParticipantMetadata{
|
||||
Name: name,
|
||||
@@ -483,7 +487,7 @@ func (p *LocalParticipant) onTrackMuted(pub *LocalTrackPublication, muted bool)
|
||||
}
|
||||
}
|
||||
|
||||
// Control who can subscribe to LocalParticipant's published tracks.
|
||||
// SetSubscriptionPermission controls who can subscribe to LocalParticipant's published tracks.
|
||||
//
|
||||
// By default, all participants can subscribe. This allows fine-grained control over
|
||||
// who is able to subscribe at a participant and track level.
|
||||
@@ -559,9 +563,8 @@ func (p *LocalParticipant) HandleIncomingRpcResponse(requestId string, payload *
|
||||
}
|
||||
}
|
||||
|
||||
// Initiate an RPC call to a remote participant
|
||||
// - @param params - For parameters for initiating the RPC call, see PerformRpcParams
|
||||
// - @returns A string payload or an error
|
||||
// PerformRpc initiates an RPC call to a remote participant.
|
||||
// Returns the response payload or an error if the call fails or times out.
|
||||
func (p *LocalParticipant) PerformRpc(params PerformRpcParams) (*string, error) {
|
||||
responseTimeout := 10000 * time.Millisecond
|
||||
if params.ResponseTimeout != nil {
|
||||
@@ -707,8 +710,8 @@ func (p *LocalParticipant) StreamText(options StreamTextOptions) *TextStreamWrit
|
||||
return writer
|
||||
}
|
||||
|
||||
// SendText creates a new text stream writer with the provided options.
|
||||
// It will return a TextStreamInfo that can be used to get metadata about the stream.
|
||||
// SendText sends a text message as a stream to other participants.
|
||||
// Returns TextStreamInfo that can be used to get metadata about the stream.
|
||||
func (p *LocalParticipant) SendText(text string, options StreamTextOptions) *TextStreamInfo {
|
||||
if options.TotalSize == 0 {
|
||||
textInBytes := []byte(text)
|
||||
@@ -830,9 +833,9 @@ func (p *LocalParticipant) StreamBytes(options StreamBytesOptions) *ByteStreamWr
|
||||
return writer
|
||||
}
|
||||
|
||||
// SendFile sends a file to the remote participant as a byte stream with the provided options.
|
||||
// It will return a ByteStreamInfo that can be used to get metadata about the stream.
|
||||
// Error is returned if the file cannot be read.
|
||||
// SendFile sends a file to other participants as a byte stream.
|
||||
// Returns ByteStreamInfo that can be used to get metadata about the stream.
|
||||
// Returns an error if the file cannot be read.
|
||||
func (p *LocalParticipant) SendFile(filePath string, options StreamBytesOptions) (*ByteStreamInfo, error) {
|
||||
if options.TotalSize == 0 {
|
||||
fileInfo, err := os.Stat(filePath)
|
||||
|
||||
@@ -92,7 +92,7 @@ type LocalTrackOptions func(s *LocalTrack)
|
||||
type LocalSampleTrackOptions = LocalTrackOptions
|
||||
|
||||
// WithSimulcast marks the current track for simulcasting.
|
||||
// In order to use simulcast, simulcastID must be identical across all layers
|
||||
// In order to use simulcast, simulcastID must be identical across all layers.
|
||||
func WithSimulcast(simulcastID string, layer *livekit.VideoLayer) LocalTrackOptions {
|
||||
return func(s *LocalTrack) {
|
||||
s.videoLayer = layer
|
||||
@@ -100,6 +100,7 @@ func WithSimulcast(simulcastID string, layer *livekit.VideoLayer) LocalTrackOpti
|
||||
}
|
||||
}
|
||||
|
||||
// WithRTCPHandler sets a callback to receive RTCP packets for the track.
|
||||
func WithRTCPHandler(cb func(rtcp.Packet)) LocalTrackOptions {
|
||||
return func(s *LocalTrack) {
|
||||
s.onRTCP = cb
|
||||
@@ -140,11 +141,12 @@ func NewLocalSampleTrack(c webrtc.RTPCodecCapability, opts ...LocalTrackOptions)
|
||||
return NewLocalTrack(c, opts...)
|
||||
}
|
||||
|
||||
// SetLogger overrides default logger.
|
||||
// SetLogger overrides default logger for this track.
|
||||
func (s *LocalTrack) SetLogger(l protoLogger.Logger) {
|
||||
s.log = l
|
||||
}
|
||||
|
||||
// SetTransceiver sets the RTP transceiver for this track.
|
||||
func (s *LocalTrack) SetTransceiver(transceiver *webrtc.RTPTransceiver) {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
@@ -152,32 +154,33 @@ func (s *LocalTrack) SetTransceiver(transceiver *webrtc.RTPTransceiver) {
|
||||
s.transceiver = transceiver
|
||||
}
|
||||
|
||||
// ID is the unique identifier for this Track. This should be unique for the
|
||||
// ID returns the unique identifier for this Track. This should be unique for the
|
||||
// stream, but doesn't have to globally unique. A common example would be 'audio' or 'video'
|
||||
// and StreamID would be 'desktop' or 'webcam'
|
||||
// and StreamID would be 'desktop' or 'webcam'.
|
||||
func (s *LocalTrack) ID() string { return s.rtpTrack.ID() }
|
||||
|
||||
// RID is the RTP stream identifier.
|
||||
// RID returns the RTP stream identifier.
|
||||
func (s *LocalTrack) RID() string {
|
||||
return s.rtpTrack.RID()
|
||||
}
|
||||
|
||||
// StreamID is the group this track belongs too. This must be unique
|
||||
// StreamID returns the group this track belongs to. This must be unique.
|
||||
func (s *LocalTrack) StreamID() string { return s.rtpTrack.StreamID() }
|
||||
|
||||
// Kind controls if this TrackLocal is audio or video
|
||||
// Kind returns whether this TrackLocal is audio or video.
|
||||
func (s *LocalTrack) Kind() webrtc.RTPCodecType { return s.rtpTrack.Kind() }
|
||||
|
||||
// Codec gets the Codec of the track
|
||||
// Codec returns the codec capability of the track.
|
||||
func (s *LocalTrack) Codec() webrtc.RTPCodecCapability {
|
||||
return s.rtpTrack.Codec()
|
||||
}
|
||||
|
||||
// IsBound returns whether the track is currently bound to a peer connection.
|
||||
func (s *LocalTrack) IsBound() bool {
|
||||
return s.bound.Load()
|
||||
}
|
||||
|
||||
// Bind is an interface for TrackLocal, not for external consumption
|
||||
// Bind is an interface for TrackLocal, not for external consumption.
|
||||
func (s *LocalTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters, error) {
|
||||
codec, err := s.rtpTrack.Bind(t)
|
||||
if err != nil {
|
||||
@@ -235,7 +238,7 @@ func (s *LocalTrack) Bind(t webrtc.TrackLocalContext) (webrtc.RTPCodecParameters
|
||||
return codec, err
|
||||
}
|
||||
|
||||
// Unbind is an interface for TrackLocal, not for external consumption
|
||||
// Unbind is an interface for TrackLocal, not for external consumption.
|
||||
func (s *LocalTrack) Unbind(t webrtc.TrackLocalContext) error {
|
||||
s.lock.Lock()
|
||||
provider := s.provider
|
||||
@@ -262,6 +265,8 @@ func (s *LocalTrack) Unbind(t webrtc.TrackLocalContext) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// StartWrite starts writing samples from the provided SampleProvider.
|
||||
// The onComplete callback is called when writing finishes.
|
||||
func (s *LocalTrack) StartWrite(provider SampleProvider, onComplete func()) error {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
@@ -288,20 +293,21 @@ func (s *LocalTrack) StartWrite(provider SampleProvider, onComplete func()) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
// OnBind sets a callback to be called when the track has been negotiated for publishing and bound to a peer connection
|
||||
// OnBind sets a callback to be called when the track has been negotiated for publishing and bound to a peer connection.
|
||||
func (s *LocalTrack) OnBind(f func()) {
|
||||
s.lock.Lock()
|
||||
s.onBind = f
|
||||
s.lock.Unlock()
|
||||
}
|
||||
|
||||
// OnUnbind sets a callback to be called after the track is removed from a peer connection
|
||||
// OnUnbind sets a callback to be called after the track is removed from a peer connection.
|
||||
func (s *LocalTrack) OnUnbind(f func()) {
|
||||
s.lock.Lock()
|
||||
s.onUnbind = f
|
||||
s.lock.Unlock()
|
||||
}
|
||||
|
||||
// WriteRTP writes an RTP packet to the track with optional sample write options.
|
||||
func (s *LocalTrack) WriteRTP(p *rtp.Packet, opts *SampleWriteOptions) error {
|
||||
s.lock.RLock()
|
||||
transceiver := s.transceiver
|
||||
@@ -340,6 +346,8 @@ func (s *LocalTrack) WriteRTP(p *rtp.Packet, opts *SampleWriteOptions) error {
|
||||
return s.rtpTrack.WriteRTP(p)
|
||||
}
|
||||
|
||||
// WriteSample writes a media sample to the track with optional write options.
|
||||
// This handles timing, RTP packetization, and sample ordering automatically.
|
||||
func (s *LocalTrack) WriteSample(sample media.Sample, opts *SampleWriteOptions) error {
|
||||
s.lock.Lock()
|
||||
if s.packetizer == nil {
|
||||
@@ -487,6 +495,7 @@ func (s *LocalTrack) WriteSample(sample media.Sample, opts *SampleWriteOptions)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close stops the track and cleans up resources.
|
||||
func (s *LocalTrack) Close() error {
|
||||
s.lock.Lock()
|
||||
cancelWrite := s.cancelWrite
|
||||
@@ -501,6 +510,7 @@ func (s *LocalTrack) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// SSRC returns the Synchronization Source identifier for this track.
|
||||
func (s *LocalTrack) SSRC() webrtc.SSRC {
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
@@ -150,6 +150,8 @@ type RemoteTrackPublication struct {
|
||||
videoQuality *livekit.VideoQuality
|
||||
}
|
||||
|
||||
// TrackRemote returns the underlying webrtc.TrackRemote if available.
|
||||
// Returns nil if the track is not subscribed
|
||||
func (p *RemoteTrackPublication) TrackRemote() *webrtc.TrackRemote {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
@@ -159,12 +161,15 @@ func (p *RemoteTrackPublication) TrackRemote() *webrtc.TrackRemote {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Receiver returns the RTP receiver associated with this track publication.
|
||||
func (p *RemoteTrackPublication) Receiver() *webrtc.RTPReceiver {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
return p.receiver
|
||||
}
|
||||
|
||||
// SetSubscribed subscribes or unsubscribes from this track.
|
||||
// When subscribed, track data will be received from the server.
|
||||
func (p *RemoteTrackPublication) SetSubscribed(subscribed bool) error {
|
||||
return p.engine.SendUpdateSubscription(
|
||||
&livekit.UpdateSubscription{
|
||||
@@ -179,12 +184,16 @@ func (p *RemoteTrackPublication) SetSubscribed(subscribed bool) error {
|
||||
)
|
||||
}
|
||||
|
||||
// IsEnabled returns whether the track is enabled (not disabled).
|
||||
// Disabled tracks will not receive media data even when subscribed.
|
||||
func (p *RemoteTrackPublication) IsEnabled() bool {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
return !p.disabled
|
||||
}
|
||||
|
||||
// SetEnabled enables or disables the track.
|
||||
// When disabled, the track will not receive media data even when subscribed.
|
||||
func (p *RemoteTrackPublication) SetEnabled(enabled bool) {
|
||||
p.lock.Lock()
|
||||
p.disabled = !enabled
|
||||
@@ -193,6 +202,8 @@ func (p *RemoteTrackPublication) SetEnabled(enabled bool) {
|
||||
p.updateSettings()
|
||||
}
|
||||
|
||||
// SetVideoDimensions sets the preferred video dimensions to receive.
|
||||
// This is a hint to the server about what resolution to send.
|
||||
func (p *RemoteTrackPublication) SetVideoDimensions(width uint32, height uint32) {
|
||||
p.lock.Lock()
|
||||
p.videoWidth = &width
|
||||
@@ -202,6 +213,7 @@ func (p *RemoteTrackPublication) SetVideoDimensions(width uint32, height uint32)
|
||||
p.updateSettings()
|
||||
}
|
||||
|
||||
// SetVideoQuality sets the preferred video quality to receive.
|
||||
func (p *RemoteTrackPublication) SetVideoQuality(quality livekit.VideoQuality) error {
|
||||
if quality == livekit.VideoQuality_OFF {
|
||||
return errors.New("cannot set video quality to OFF")
|
||||
@@ -214,6 +226,7 @@ func (p *RemoteTrackPublication) SetVideoQuality(quality livekit.VideoQuality) e
|
||||
return nil
|
||||
}
|
||||
|
||||
// OnRTCP sets a callback to receive RTCP packets for this track.
|
||||
func (p *RemoteTrackPublication) OnRTCP(cb func(rtcp.Packet)) {
|
||||
p.lock.Lock()
|
||||
p.onRTCP = cb
|
||||
@@ -312,6 +325,8 @@ func (p *LocalTrackPublication) TrackLocal() webrtc.TrackLocal {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetSimulcastTrack returns the simulcast track for a specific quality level.
|
||||
// Returns nil if simulcast is not enabled or the quality level doesn't exist.
|
||||
func (p *LocalTrackPublication) GetSimulcastTrack(quality livekit.VideoQuality) *LocalTrack {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
@@ -321,10 +336,14 @@ func (p *LocalTrackPublication) GetSimulcastTrack(quality livekit.VideoQuality)
|
||||
return p.simulcastTracks[quality]
|
||||
}
|
||||
|
||||
// SetMuted mutes or unmutes the track.
|
||||
// When muted, no media data will be sent to other participants.
|
||||
func (p *LocalTrackPublication) SetMuted(muted bool) {
|
||||
p.setMuted(muted, false)
|
||||
}
|
||||
|
||||
// SimulateDisconnection simulates a network disconnection for testing purposes.
|
||||
// If duration is 0, the disconnection persists until manually reconnected.
|
||||
func (p *LocalTrackPublication) SimulateDisconnection(duration time.Duration) {
|
||||
if track := p.track; track != nil {
|
||||
switch t := track.(type) {
|
||||
@@ -393,6 +412,8 @@ func (p *LocalTrackPublication) setSender(sender *webrtc.RTPSender, consumeRTCP
|
||||
}()
|
||||
}
|
||||
|
||||
// CloseTrack closes the underlying track and all simulcast tracks.
|
||||
// This should be called when the track is no longer needed.
|
||||
func (p *LocalTrackPublication) CloseTrack() {
|
||||
for _, st := range p.simulcastTracks {
|
||||
st.Close()
|
||||
|
||||
53
room.go
53
room.go
@@ -99,14 +99,16 @@ type ConnectInfo struct {
|
||||
|
||||
type ConnectOption func(*signalling.ConnectParams)
|
||||
|
||||
// WithAutoSubscribe sets whether the participant should automatically subscribe to tracks.
|
||||
// Default is true.
|
||||
func WithAutoSubscribe(val bool) ConnectOption {
|
||||
return func(p *signalling.ConnectParams) {
|
||||
p.AutoSubscribe = val
|
||||
}
|
||||
}
|
||||
|
||||
// Retransmit buffer size to reponse to nack request,
|
||||
// must be one of: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768
|
||||
// WithRetransmitBufferSize sets the retransmit buffer size to respond to NACK requests.
|
||||
// Must be one of: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768.
|
||||
func WithRetransmitBufferSize(val uint16) ConnectOption {
|
||||
return func(p *signalling.ConnectParams) {
|
||||
p.RetransmitBufferSize = val
|
||||
@@ -121,30 +123,36 @@ func WithPacer(pacer pacer.Factory) ConnectOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithInterceptors sets custom RTP interceptors for the connection.
|
||||
func WithInterceptors(interceptors []interceptor.Factory) ConnectOption {
|
||||
return func(p *signalling.ConnectParams) {
|
||||
p.Interceptors = interceptors
|
||||
}
|
||||
}
|
||||
|
||||
// WithICETransportPolicy sets the ICE transport policy (UDP, Relay, etc.).
|
||||
func WithICETransportPolicy(iceTransportPolicy webrtc.ICETransportPolicy) ConnectOption {
|
||||
return func(p *signalling.ConnectParams) {
|
||||
p.ICETransportPolicy = iceTransportPolicy
|
||||
}
|
||||
}
|
||||
|
||||
// WithDisableRegionDiscovery disables automatic region discovery for LiveKit Cloud.
|
||||
func WithDisableRegionDiscovery() ConnectOption {
|
||||
return func(p *signalling.ConnectParams) {
|
||||
p.DisableRegionDiscovery = true
|
||||
}
|
||||
}
|
||||
|
||||
// WithMetadata sets custom metadata for the participant.
|
||||
func WithMetadata(metadata string) ConnectOption {
|
||||
return func(p *signalling.ConnectParams) {
|
||||
p.Metadata = metadata
|
||||
}
|
||||
}
|
||||
|
||||
// WithExtraAttributes sets additional key-value attributes for the participant.
|
||||
// Empty string values will be ignored.
|
||||
func WithExtraAttributes(attrs map[string]string) ConnectOption {
|
||||
return func(p *signalling.ConnectParams) {
|
||||
if len(attrs) != 0 && p.Attributes == nil {
|
||||
@@ -248,6 +256,8 @@ func (r *Room) Name() string {
|
||||
return r.name
|
||||
}
|
||||
|
||||
// SID returns the unique session ID of the room.
|
||||
// This will block until session ID is available, which could take up to 2s after joining the room.
|
||||
func (r *Room) SID() string {
|
||||
<-r.sidReady
|
||||
r.lock.RLock()
|
||||
@@ -351,15 +361,18 @@ func (r *Room) JoinWithToken(url, token string, opts ...ConnectOption) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Disconnect leaves the room, indicating the client initiated the disconnect.
|
||||
func (r *Room) Disconnect() {
|
||||
r.DisconnectWithReason(livekit.DisconnectReason_UNKNOWN_REASON)
|
||||
r.DisconnectWithReason(livekit.DisconnectReason_CLIENT_INITIATED)
|
||||
}
|
||||
|
||||
// DisconnectWithReason leaves the room with a specific disconnect reason.
|
||||
func (r *Room) DisconnectWithReason(reason livekit.DisconnectReason) {
|
||||
_ = r.engine.SendLeaveWithReason(reason)
|
||||
r.cleanup()
|
||||
}
|
||||
|
||||
// ConnectionState returns the current connection state of the room.
|
||||
func (r *Room) ConnectionState() ConnectionState {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
@@ -428,6 +441,9 @@ func (r *Room) clearParticipantDefers(sid livekit.ParticipantID, pi *livekit.Par
|
||||
}
|
||||
}
|
||||
|
||||
// GetParticipantByIdentity returns a remote participant by their identity.
|
||||
// Returns nil if not found.
|
||||
// Note: this represents the current view from the local participant's perspective
|
||||
func (r *Room) GetParticipantByIdentity(identity string) *RemoteParticipant {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
@@ -435,6 +451,9 @@ func (r *Room) GetParticipantByIdentity(identity string) *RemoteParticipant {
|
||||
return r.remoteParticipants[livekit.ParticipantIdentity(identity)]
|
||||
}
|
||||
|
||||
// GetParticipantBySID returns a remote participant by their session ID.
|
||||
// Returns nil if not found.
|
||||
// Note: this represents the current view from the local participant's perspective
|
||||
func (r *Room) GetParticipantBySID(sid string) *RemoteParticipant {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
@@ -445,6 +464,9 @@ func (r *Room) GetParticipantBySID(sid string) *RemoteParticipant {
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetRemoteParticipants returns all remote participants in the room as seen by the local participant
|
||||
// Note: this does not represent the exact state from the server's view. To get all participants that
|
||||
// exists on the server, use [RoomServiceClient.ListParticipants] instead.
|
||||
func (r *Room) GetRemoteParticipants() []*RemoteParticipant {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
@@ -456,6 +478,8 @@ func (r *Room) GetRemoteParticipants() []*RemoteParticipant {
|
||||
return participants
|
||||
}
|
||||
|
||||
// ActiveSpeakers returns a list of currently active speakers.
|
||||
// Speakers are ordered by audio level (loudest first).
|
||||
func (r *Room) ActiveSpeakers() []Participant {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
@@ -468,12 +492,14 @@ func (r *Room) Metadata() string {
|
||||
return r.metadata
|
||||
}
|
||||
|
||||
// ServerInfo returns information about the LiveKit server.
|
||||
func (r *Room) ServerInfo() *livekit.ServerInfo {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
return proto.Clone(r.serverInfo).(*livekit.ServerInfo)
|
||||
}
|
||||
|
||||
// SifTrailer returns the SIF (Server Injected Frames) trailer data used by E2EE
|
||||
func (r *Room) SifTrailer() []byte {
|
||||
r.lock.RLock()
|
||||
defer r.lock.RUnlock()
|
||||
@@ -612,6 +638,8 @@ func (r *Room) setSid(sid string, allowEmpty bool) {
|
||||
r.lock.Unlock()
|
||||
}
|
||||
|
||||
// Simulate triggers various test scenarios for debugging and testing purposes.
|
||||
// This is primarily used for development and testing.
|
||||
func (r *Room) Simulate(scenario SimulateScenario) {
|
||||
r.engine.Simulate(scenario)
|
||||
}
|
||||
@@ -654,15 +682,14 @@ func (r *Room) RegisterRpcMethod(method string, handler RpcHandlerFunc) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unregisters a previously registered RPC method.
|
||||
// - @param method - The name of the RPC method to unregister
|
||||
// UnregisterRpcMethod unregisters a previously registered RPC method.
|
||||
func (r *Room) UnregisterRpcMethod(method string) {
|
||||
r.rpcHandlers.Delete(method)
|
||||
}
|
||||
|
||||
// Registers a handler for a text stream.
|
||||
// It will be called when a text stream is received for the given topic.
|
||||
// The handler will be called with the stream reader and the participant identity that sent the stream.
|
||||
// RegisterTextStreamHandler registers a handler for incoming text streams on a specific topic.
|
||||
// The handler will be called when a text stream is received for the given topic.
|
||||
// It returns an error if a handler is already registered for this topic.
|
||||
func (r *Room) RegisterTextStreamHandler(topic string, handler TextStreamHandler) error {
|
||||
if _, loaded := r.textStreamHandlers.LoadOrStore(topic, handler); loaded {
|
||||
return fmt.Errorf("text stream handler already registered for topic: %s", topic)
|
||||
@@ -670,14 +697,14 @@ func (r *Room) RegisterTextStreamHandler(topic string, handler TextStreamHandler
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unregisters a handler for a text stream.
|
||||
// UnregisterTextStreamHandler removes a previously registered text stream handler.
|
||||
func (r *Room) UnregisterTextStreamHandler(topic string) {
|
||||
r.textStreamHandlers.Delete(topic)
|
||||
}
|
||||
|
||||
// Registers a handler for a byte stream.
|
||||
// It will be called when a byte stream is received for the given topic.
|
||||
// The handler will be called with the stream reader and the participant identity that sent the stream.
|
||||
// RegisterByteStreamHandler registers a handler for incoming byte streams on a specific topic.
|
||||
// The handler will be called when a byte stream is received for the given topic.
|
||||
// It returns an error if a handler is already registered for this topic.
|
||||
func (r *Room) RegisterByteStreamHandler(topic string, handler ByteStreamHandler) error {
|
||||
if _, loaded := r.byteStreamHandlers.LoadOrStore(topic, handler); loaded {
|
||||
return fmt.Errorf("byte stream handler already registered for topic: %s", topic)
|
||||
@@ -685,7 +712,7 @@ func (r *Room) RegisterByteStreamHandler(topic string, handler ByteStreamHandler
|
||||
return nil
|
||||
}
|
||||
|
||||
// Unregisters a handler for a byte stream.
|
||||
// UnregisterByteStreamHandler removes a previously registered byte stream handler.
|
||||
func (r *Room) UnregisterByteStreamHandler(topic string) {
|
||||
r.byteStreamHandlers.Delete(topic)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user