From c473ddd4ea084746835e228f8e4b87ceb64f32d5 Mon Sep 17 00:00:00 2001 From: Jacob Gelman <3182119+ladvoc@users.noreply.github.com> Date: Thu, 6 Nov 2025 15:43:50 +1100 Subject: [PATCH] Subscribe to tracks in join response --- components/livekit/core/engine.c | 12 +++++++++++- components/livekit/core/engine.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/components/livekit/core/engine.c b/components/livekit/core/engine.c index e0288ac..cafee2e 100644 --- a/components/livekit/core/engine.c +++ b/components/livekit/core/engine.c @@ -153,7 +153,7 @@ static engine_err_t subscribe_tracks(engine_t *eng, livekit_pb_track_info_t *tra return ENGINE_ERR_INVALID_ARG; } if (eng->session.sub_audio_track_sid[0] != '\0') { - return ENGINE_ERR_NONE; + return ENGINE_ERR_MAX_SUB; } for (int i = 0; i < count; i++) { livekit_pb_track_info_t *track = &tracks[i]; @@ -689,6 +689,16 @@ static bool handle_join(engine_t *eng, const livekit_pb_join_response_t *join) ESP_LOGE(TAG, "Failed to establish peer connections"); return false; } + + // 6. Subscribe to remote tracks that have already been published. + for (pb_size_t i = 0; i < join->other_participants_count; i++) { + engine_err_t ret = subscribe_tracks( + eng, + join->other_participants[i].tracks, + join->other_participants[i].tracks_count + ); + if (ret == ENGINE_ERR_MAX_SUB) break; + } return true; } diff --git a/components/livekit/core/engine.h b/components/livekit/core/engine.h index 8916af7..048feb0 100644 --- a/components/livekit/core/engine.h +++ b/components/livekit/core/engine.h @@ -35,6 +35,7 @@ typedef enum { ENGINE_ERR_RTC = -4, ENGINE_ERR_MEDIA = -5, ENGINE_ERR_OTHER = -6, + ENGINE_ERR_MAX_SUB = -7, // No more subscriptions allowed. // TODO: Add more error cases as needed } engine_err_t;