[fix] prevent screen capture without connected peers

This commit is contained in:
dijunkun
2026-08-19 15:51:37 +08:00
parent 5d0453fff3
commit 3be283238c
2 changed files with 35 additions and 5 deletions
@@ -335,7 +335,7 @@ int ScreenCapturerSckImpl::SwitchTo(int monitor_index) {
}
int ScreenCapturerSckImpl::ResetToInitialMonitor() {
int target = initial_monitor_index_;
const int target = initial_monitor_index_;
if (display_info_list_.empty()) return -1;
auto display_it = display_id_map_.find(target);
if (display_it == display_id_map_.end()) {
@@ -343,13 +343,20 @@ int ScreenCapturerSckImpl::ResetToInitialMonitor() {
return -1;
}
CGDirectDisplayID target_display = display_it->second;
if (current_display_ == target_display) return 0;
const CGDirectDisplayID target_display = display_it->second;
bool should_reconfigure = false;
{
std::lock_guard<std::mutex> lock(lock_);
if (current_display_ == target_display) return 0;
current_display_ = target_display;
should_reconfigure = stream_ != nil;
}
// Resetting session state must not create a capture stream. Preserve the
// selected monitor for the next Start(), and only reconfigure an active one.
if (should_reconfigure) {
StartOrReconfigureCapturer();
}
StartOrReconfigureCapturer();
return 0;
}