Repository navigation
(WIP) Handle track republish after full-reconnect #271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,7 +20,10 @@ | |
| #include "ffi_client.h" | ||
| #include "livekit/audio_stream.h" | ||
| #include "livekit/e2ee.h" | ||
| #include "livekit/local_audio_track.h" | ||
| #include "livekit/local_participant.h" | ||
| #include "livekit/local_track_publication.h" | ||
| #include "livekit/local_video_track.h" | ||
| #include "livekit/remote_audio_track.h" | ||
| #include "livekit/remote_data_track.h" | ||
| #include "livekit/remote_participant.h" | ||
|
|
@@ -47,6 +50,33 @@ | |
|
|
||
| namespace { | ||
|
|
||
| std::shared_ptr<LocalTrackPublication> localTrackPublication(const std::shared_ptr<Track>& track) { | ||
| if (!track) { | ||
| return nullptr; | ||
| } | ||
| if (auto video = std::dynamic_pointer_cast<LocalVideoTrack>(track)) { | ||
| return video->publication(); | ||
| } | ||
| if (auto audio = std::dynamic_pointer_cast<LocalAudioTrack>(track)) { | ||
| return audio->publication(); | ||
| } | ||
| return nullptr; | ||
| } | ||
|
|
||
| void updateLocalTrackPublicationInfo(LocalTrackPublication& publication, const proto::TrackPublicationInfo& info) { | ||
| publication.sid_ = info.sid(); | ||
|
Check failure on line 67 in src/room.cpp
|
||
| publication.name_ = info.name(); | ||
|
Check failure on line 68 in src/room.cpp
|
||
| publication.kind_ = fromProto(info.kind()); | ||
|
Check failure on line 69 in src/room.cpp
|
||
| publication.source_ = fromProto(info.source()); | ||
|
Check failure on line 70 in src/room.cpp
|
||
| publication.simulcasted_ = info.simulcasted(); | ||
|
Check failure on line 71 in src/room.cpp
|
||
| publication.width_ = info.width(); | ||
|
Check failure on line 72 in src/room.cpp
|
||
| publication.height_ = info.height(); | ||
|
Check failure on line 73 in src/room.cpp
|
||
| publication.mime_type_ = info.mime_type(); | ||
|
Check failure on line 74 in src/room.cpp
|
||
| publication.muted_ = info.muted(); | ||
|
Check failure on line 75 in src/room.cpp
|
||
| publication.encryption_type_ = static_cast<EncryptionType>(info.encryption_type()); | ||
|
Check failure on line 76 in src/room.cpp
|
||
| publication.audio_features_ = convertAudioFeatures(info.audio_features()); | ||
| } | ||
|
|
||
| std::shared_ptr<livekit::RemoteParticipant> createRemoteParticipant(const proto::OwnedParticipant& owned) { | ||
| const auto& pinfo = owned.info(); | ||
| std::unordered_map<std::string, std::string> attrs; | ||
|
|
@@ -593,6 +623,38 @@ | |
| } | ||
| break; | ||
| } | ||
| case proto::RoomEvent::kLocalTrackRepublished: { | ||
| const std::scoped_lock<std::mutex> guard(lock_); | ||
| if (!local_participant_) { | ||
| LK_LOG_ERROR("kLocalTrackRepublished: local_participant_ is nullptr"); | ||
| break; | ||
| } | ||
| const auto& ltr = re.local_track_republished(); | ||
| const std::string& previous_sid = ltr.previous_sid(); | ||
|
|
||
| auto& published = local_participant_->published_tracks_by_sid_; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: variable name for the data type, maybe |
||
| auto it = published.find(previous_sid); | ||
| if (it == published.end()) { | ||
| LK_LOG_WARN("local_track_republished for unknown previous sid: {}", previous_sid); | ||
| break; | ||
| } | ||
| auto track = it->second.lock(); | ||
| if (!track) { | ||
| published.erase(it); | ||
| LK_LOG_WARN("local_track_republished for expired previous sid: {}", previous_sid); | ||
| break; | ||
| } | ||
| auto publication = localTrackPublication(track); | ||
| if (!publication) { | ||
| LK_LOG_WARN("local_track_republished missing publication for sid: {}", previous_sid); | ||
| break; | ||
| } | ||
|
Comment on lines
+636
to
+651
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In these cases do we just lose the track entirely given the |
||
| updateLocalTrackPublicationInfo(*publication, ltr.info()); | ||
| published.erase(it); | ||
| published[publication->sid()] = track; | ||
| track->setPublication(publication); | ||
| break; | ||
| } | ||
| case proto::RoomEvent::kLocalTrackSubscribed: { | ||
| LocalTrackSubscribedEvent ev; | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Copyright 2026 LiveKit | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <livekit/livekit.h> | ||
|
|
||
| #include <memory> | ||
| #include <mutex> | ||
| #include <stdexcept> | ||
|
|
||
| #include "ffi_client.h" | ||
| #include "room.pb.h" | ||
|
|
||
| namespace livekit { | ||
|
|
||
| struct RoomTestAccess { | ||
| static int listenerId(const Room& room) { | ||
| const std::scoped_lock<std::mutex> guard(room.lock_); | ||
| return room.listener_id_; | ||
| } | ||
|
|
||
| static void simulateScenario(Room& room, proto::SimulateScenarioKind scenario) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Do we need this? |
||
| std::shared_ptr<FfiHandle> handle; | ||
| { | ||
| const std::scoped_lock<std::mutex> guard(room.lock_); | ||
| handle = room.room_handle_; | ||
| } | ||
| if (!handle) { | ||
| throw std::runtime_error("cannot simulate scenario for a disconnected room"); | ||
| } | ||
| FfiClient::instance().simulateScenarioAsync(handle->get(), static_cast<int>(scenario)).get(); | ||
| } | ||
| }; | ||
|
|
||
| } // namespace livekit | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: variable name, maybe
local_track_repub