Skip to content

Commit 1de3229

Browse files
authored
Subscribe to tracks in join response (#52)
1 parent 5817f90 commit 1de3229

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

components/livekit/core/engine.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static engine_err_t subscribe_tracks(engine_t *eng, livekit_pb_track_info_t *tra
153153
return ENGINE_ERR_INVALID_ARG;
154154
}
155155
if (eng->session.sub_audio_track_sid[0] != '\0') {
156-
return ENGINE_ERR_NONE;
156+
return ENGINE_ERR_MAX_SUB;
157157
}
158158
for (int i = 0; i < count; i++) {
159159
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)
689689
ESP_LOGE(TAG, "Failed to establish peer connections");
690690
return false;
691691
}
692+
693+
// 6. Subscribe to remote tracks that have already been published.
694+
for (pb_size_t i = 0; i < join->other_participants_count; i++) {
695+
engine_err_t ret = subscribe_tracks(
696+
eng,
697+
join->other_participants[i].tracks,
698+
join->other_participants[i].tracks_count
699+
);
700+
if (ret == ENGINE_ERR_MAX_SUB) break;
701+
}
692702
return true;
693703
}
694704

components/livekit/core/engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ typedef enum {
3535
ENGINE_ERR_RTC = -4,
3636
ENGINE_ERR_MEDIA = -5,
3737
ENGINE_ERR_OTHER = -6,
38+
ENGINE_ERR_MAX_SUB = -7, // No more subscriptions allowed.
3839
// TODO: Add more error cases as needed
3940
} engine_err_t;
4041

0 commit comments

Comments
 (0)