a ParticipantImpl in the room added a new track, subscribe other participants to it
(participant types.Participant, track types.MediaTrack)
| 1071 | |
| 1072 | // a ParticipantImpl in the room added a new track, subscribe other participants to it |
| 1073 | func (r *Room) onTrackPublished(participant types.Participant, track types.MediaTrack) { |
| 1074 | r.trackManager.AddTrack(track, participant.Identity(), participant.ID()) |
| 1075 | |
| 1076 | // publish participant update, since track state is changed |
| 1077 | r.broadcastParticipantState(participant, broadcastOptions{skipSource: true}) |
| 1078 | |
| 1079 | r.lock.RLock() |
| 1080 | // subscribe all existing participants to this MediaTrack |
| 1081 | for _, existingParticipant := range r.participants { |
| 1082 | if existingParticipant == participant { |
| 1083 | // skip publishing participant |
| 1084 | continue |
| 1085 | } |
| 1086 | if existingParticipant.State() != livekit.ParticipantInfo_ACTIVE { |
| 1087 | // not fully joined. don't subscribe yet |
| 1088 | continue |
| 1089 | } |
| 1090 | if !r.autoSubscribe(existingParticipant) { |
| 1091 | continue |
| 1092 | } |
| 1093 | |
| 1094 | existingParticipant.GetLogger().Debugw( |
| 1095 | "subscribing to new track", |
| 1096 | "publisher", participant.Identity(), |
| 1097 | "publisherID", participant.ID(), |
| 1098 | "trackID", track.ID(), |
| 1099 | ) |
| 1100 | existingParticipant.SubscribeToTrack(track.ID(), false) |
| 1101 | } |
| 1102 | onParticipantChanged := r.onParticipantChanged |
| 1103 | r.lock.RUnlock() |
| 1104 | |
| 1105 | if onParticipantChanged != nil { |
| 1106 | onParticipantChanged(participant) |
| 1107 | } |
| 1108 | |
| 1109 | // launch jobs |
| 1110 | r.lock.Lock() |
| 1111 | hasPublished := r.hasPublished[participant.Identity()] |
| 1112 | r.hasPublished[participant.Identity()] = true |
| 1113 | r.lock.Unlock() |
| 1114 | |
| 1115 | if !hasPublished { |
| 1116 | r.lock.RLock() |
| 1117 | r.launchTargetAgents(slices.Collect(maps.Values(r.agentDispatches)), participant, livekit.JobType_JT_PUBLISHER) |
| 1118 | r.lock.RUnlock() |
| 1119 | if r.internal != nil && r.internal.ParticipantEgress != nil { |
| 1120 | go func() { |
| 1121 | if err := StartParticipantEgress( |
| 1122 | context.Background(), |
| 1123 | r.egressLauncher, |
| 1124 | r.telemetry, |
| 1125 | r.internal.ParticipantEgress, |
| 1126 | participant.Identity(), |
| 1127 | r.Name(), |
| 1128 | r.ID(), |
| 1129 | ); err != nil { |
| 1130 | r.logger.Errorw("failed to launch participant egress", err) |
no test coverage detected