server-sdk-go icon indicating copy to clipboard operation
server-sdk-go copied to clipboard

Can I publish the track in Muted?

Open ek-170 opened this issue 1 year ago • 2 comments

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
}

ek-170 avatar Jun 26 '24 05:06 ek-170

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

davidzhao avatar Jun 28 '24 09:06 davidzhao

@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.

ek-170 avatar Jun 28 '24 14:06 ek-170