Add participant option for data track auto-subscribe. (#4240)
* Add participant option for data track auto-subscribe. Default disabled. * protocol update to use data track auto subscribe setting * deps
This commit is contained in:
@@ -189,6 +189,7 @@ type ParticipantInit struct {
|
||||
Reconnect bool
|
||||
ReconnectReason livekit.ReconnectReason
|
||||
AutoSubscribe bool
|
||||
AutoSubscribeDataTrack *bool
|
||||
Client *livekit.ClientInfo
|
||||
Grants *auth.ClaimGrants
|
||||
Region string
|
||||
@@ -220,6 +221,7 @@ func (pi *ParticipantInit) MarshalLogObject(e zapcore.ObjectEncoder) error {
|
||||
logBoolPtr("Reconnect", &pi.Reconnect)
|
||||
e.AddString("ReconnectReason", pi.ReconnectReason.String())
|
||||
logBoolPtr("AutoSubscribe", &pi.AutoSubscribe)
|
||||
logBoolPtr("AutoSubscribeDataTrack", pi.AutoSubscribeDataTrack)
|
||||
e.AddObject("Client", logger.Proto(utils.ClientInfoWithoutAddress(pi.Client)))
|
||||
e.AddObject("Grants", pi.Grants)
|
||||
e.AddString("Region", pi.Region)
|
||||
@@ -260,6 +262,10 @@ func (pi *ParticipantInit) ToStartSession(roomName livekit.RoomName, connectionI
|
||||
SyncState: pi.SyncState,
|
||||
UseSinglePeerConnection: pi.UseSinglePeerConnection,
|
||||
}
|
||||
if pi.AutoSubscribeDataTrack != nil {
|
||||
autoSubscribeDataTrack := *pi.AutoSubscribeDataTrack
|
||||
ss.AutoSubscribeDataTrack = &autoSubscribeDataTrack
|
||||
}
|
||||
if pi.SubscriberAllowPause != nil {
|
||||
subscriberAllowPause := *pi.SubscriberAllowPause
|
||||
ss.SubscriberAllowPause = &subscriberAllowPause
|
||||
@@ -292,6 +298,10 @@ func ParticipantInitFromStartSession(ss *livekit.StartSession, region string) (*
|
||||
SyncState: ss.SyncState,
|
||||
UseSinglePeerConnection: ss.UseSinglePeerConnection,
|
||||
}
|
||||
if ss.AutoSubscribeDataTrack != nil {
|
||||
autoSubscribeDataTrack := *ss.AutoSubscribeDataTrack
|
||||
pi.AutoSubscribeDataTrack = &autoSubscribeDataTrack
|
||||
}
|
||||
if ss.SubscriberAllowPause != nil {
|
||||
subscriberAllowPause := *ss.SubscriberAllowPause
|
||||
pi.SubscriberAllowPause = &subscriberAllowPause
|
||||
|
||||
+26
-13
@@ -152,7 +152,8 @@ type Room struct {
|
||||
}
|
||||
|
||||
type ParticipantOptions struct {
|
||||
AutoSubscribe bool
|
||||
AutoSubscribe bool
|
||||
AutoSubscribeDataTrack bool
|
||||
}
|
||||
|
||||
type agentDispatch struct {
|
||||
@@ -1004,7 +1005,7 @@ func (r *Room) onSimulateScenario(participant types.LocalParticipant, simulateSc
|
||||
return nil
|
||||
}
|
||||
|
||||
// checks if participant should be autosubscribed to new tracks, assumes lock is already acquired
|
||||
// checks if participant should be auto subscribed to new tracks, assumes lock is already acquired
|
||||
func (r *Room) autoSubscribe(participant types.LocalParticipant) bool {
|
||||
opts := r.participantOpts[participant.Identity()]
|
||||
// default to true if no options are set
|
||||
@@ -1014,6 +1015,16 @@ func (r *Room) autoSubscribe(participant types.LocalParticipant) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// checks if participant should be auto subscribed to new data tracks, assumes lock is already acquired
|
||||
func (r *Room) autoSubscribeDataTrack(participant types.LocalParticipant) bool {
|
||||
opts := r.participantOpts[participant.Identity()]
|
||||
// default to true if no options are set
|
||||
if opts != nil && !opts.AutoSubscribeDataTrack {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (r *Room) createJoinResponseLocked(
|
||||
participant types.LocalParticipant,
|
||||
iceServers []*livekit.ICEServer,
|
||||
@@ -1160,7 +1171,7 @@ func (r *Room) onDataTrackPublished(participant types.Participant, dt types.Data
|
||||
// not fully joined. don't subscribe yet
|
||||
continue
|
||||
}
|
||||
if !r.autoSubscribe(existingParticipant) {
|
||||
if !r.autoSubscribeDataTrack(existingParticipant) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -1461,11 +1472,9 @@ func (r *Room) RemoveParticipant(
|
||||
|
||||
func (r *Room) subscribeToExistingTracks(p types.LocalParticipant, isSync bool) {
|
||||
r.lock.RLock()
|
||||
shouldSubscribe := r.autoSubscribe(p)
|
||||
autoSubscribe := r.autoSubscribe(p)
|
||||
autoSubscribeDataTrack := r.autoSubscribeDataTrack(p)
|
||||
r.lock.RUnlock()
|
||||
if !shouldSubscribe {
|
||||
return
|
||||
}
|
||||
|
||||
var trackIDs []livekit.TrackID
|
||||
for _, op := range r.GetParticipants() {
|
||||
@@ -1475,14 +1484,18 @@ func (r *Room) subscribeToExistingTracks(p types.LocalParticipant, isSync bool)
|
||||
}
|
||||
|
||||
// subscribe to all
|
||||
for _, track := range op.GetPublishedTracks() {
|
||||
trackIDs = append(trackIDs, track.ID())
|
||||
p.SubscribeToTrack(track.ID(), isSync)
|
||||
if autoSubscribe {
|
||||
for _, track := range op.GetPublishedTracks() {
|
||||
trackIDs = append(trackIDs, track.ID())
|
||||
p.SubscribeToTrack(track.ID(), isSync)
|
||||
}
|
||||
}
|
||||
|
||||
for _, track := range op.GetPublishedDataTracks() {
|
||||
trackIDs = append(trackIDs, track.ID())
|
||||
p.SubscribeToDataTrack(track.ID())
|
||||
if autoSubscribeDataTrack {
|
||||
for _, track := range op.GetPublishedDataTracks() {
|
||||
trackIDs = append(trackIDs, track.ID())
|
||||
p.SubscribeToDataTrack(track.ID())
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(trackIDs) > 0 {
|
||||
|
||||
@@ -518,6 +518,9 @@ func (r *RoomManager) StartSession(
|
||||
opts := rtc.ParticipantOptions{
|
||||
AutoSubscribe: pi.AutoSubscribe,
|
||||
}
|
||||
if pi.AutoSubscribeDataTrack != nil {
|
||||
opts.AutoSubscribeDataTrack = *pi.AutoSubscribeDataTrack
|
||||
}
|
||||
iceServers := r.iceServersForParticipant(apiKey, participant, iceConfig.PreferenceSubscriber == livekit.ICECandidateType_ICT_TLS)
|
||||
if err = room.Join(participant, requestSource, &opts, iceServers); err != nil {
|
||||
pLogger.Errorw("could not join room", err)
|
||||
|
||||
@@ -221,7 +221,17 @@ func (s *RTCService) validateInternal(
|
||||
if wrappedJoinRequestBase64 == "" {
|
||||
pi.Reconnect = boolValue(r.FormValue("reconnect"))
|
||||
pi.Client = ParseClientInfo(r)
|
||||
|
||||
pi.AutoSubscribe = true
|
||||
if autoSubscribeParam := r.FormValue("auto_subscribe"); autoSubscribeParam != "" {
|
||||
pi.AutoSubscribe = boolValue(autoSubscribeParam)
|
||||
}
|
||||
|
||||
if autoSubscribeDataTrackParam := r.FormValue("auto_subscribe_data_track"); autoSubscribeDataTrackParam != "" {
|
||||
autoSubscribeDataTrack := boolValue(autoSubscribeDataTrackParam)
|
||||
pi.AutoSubscribeDataTrack = &autoSubscribeDataTrack
|
||||
}
|
||||
|
||||
pi.AdaptiveStream = boolValue(r.FormValue("adaptive_stream"))
|
||||
pi.DisableICELite = boolValue(r.FormValue("disable_ice_lite"))
|
||||
|
||||
@@ -232,12 +242,7 @@ func (s *RTCService) validateInternal(
|
||||
pi.ID = livekit.ParticipantID(r.FormValue("sid"))
|
||||
}
|
||||
|
||||
if autoSubscribe := r.FormValue("auto_subscribe"); autoSubscribe != "" {
|
||||
pi.AutoSubscribe = boolValue(autoSubscribe)
|
||||
}
|
||||
|
||||
subscriberAllowPauseParam := r.FormValue("subscriber_allow_pause")
|
||||
if subscriberAllowPauseParam != "" {
|
||||
if subscriberAllowPauseParam := r.FormValue("subscriber_allow_pause"); subscriberAllowPauseParam != "" {
|
||||
subscriberAllowPause := boolValue(subscriberAllowPauseParam)
|
||||
pi.SubscriberAllowPause = &subscriberAllowPause
|
||||
}
|
||||
@@ -248,6 +253,10 @@ func (s *RTCService) validateInternal(
|
||||
pi.Client = joinRequest.ClientInfo
|
||||
|
||||
pi.AutoSubscribe = joinRequest.GetConnectionSettings().GetAutoSubscribe()
|
||||
|
||||
autoSubscribeDataTrack := joinRequest.GetConnectionSettings().GetAutoSubscribeDataTrack()
|
||||
pi.AutoSubscribeDataTrack = &autoSubscribeDataTrack
|
||||
|
||||
pi.AdaptiveStream = joinRequest.GetConnectionSettings().GetAdaptiveStream()
|
||||
pi.DisableICELite = joinRequest.GetConnectionSettings().GetDisableIceLite()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user