livekit / server-sdk-go

Client and server SDK for Golang
Apache License 2.0
195 stars 86 forks source link

Can I publish the track in Muted? #492

Open ek-170 opened 3 months ago

ek-170 commented 3 months ago

my application need to publish track muted by default. but I cant find option controll muted in TrackPublicationOptions so, I want to add muted option to SDK like below

// localparticipant.go

func (p *LocalParticipant) PublishTrack(track webrtc.TrackLocal, opts *TrackPublicationOptions) (*LocalTrackPublication, error) {
    if opts == nil {
        opts = &TrackPublicationOptions{}
    }
    kind := KindFromRTPType(track.Kind())
    // default sources, since clients generally look for camera/mic
    if opts.Source == livekit.TrackSource_UNKNOWN {
        if kind == TrackKindVideo {
            opts.Source = livekit.TrackSource_CAMERA
        } else if kind == TrackKindAudio {
            opts.Source = livekit.TrackSource_MICROPHONE
        }
    }

    pub := NewLocalTrackPublication(kind, track, *opts, p.engine.client)
    pub.onMuteChanged = p.onTrackMuted

    req := &livekit.AddTrackRequest{
        Cid:        track.ID(),
        Name:       opts.Name,
        Source:     opts.Source,
        Type:       kind.ProtoType(),
        Width:      uint32(opts.VideoWidth),
        Height:     uint32(opts.VideoHeight),
        DisableDtx: opts.DisableDTX,
        Stereo:     opts.Stereo,
        Stream:     opts.Stream,
        Muted:      opts.Muted,     <- add here
    }
    if kind == TrackKindVideo {
        // single layer
        req.Layers = []*livekit.VideoLayer{
            {
                Quality: livekit.VideoQuality_HIGH,
                Width:   uint32(opts.VideoWidth),
                Height:  uint32(opts.VideoHeight),
            },
        }
    }

and, change TrackPublicationOptions

// publication.go

type TrackPublicationOptions struct {
    Name   string
    Source livekit.TrackSource
    // Set dimensions for video
    VideoWidth  int
    VideoHeight int
    // Opus only
    DisableDTX bool
    Stereo     bool
    // which stream the track belongs to, used to group tracks together.
    // if not specified, server will infer it from track source to bundle camera/microphone, screenshare/audio together
    Stream string
    Muted bool    <- add here
}
davidzhao commented 3 months ago

That's not possible currently. The track will need to send a few packets in order to be registered correctly.

ek-170 commented 3 months ago

@davidzhao thank you for your reply. If that's the case, I don't have a choice, I'll try to publish and then mute.