Skip to content
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

A Rerun Viewer session now matches 1:1 to a Rerun TCP server #6951

Merged
merged 3 commits into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 32 additions & 16 deletions crates/top/rerun/src/commands/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ fn run_impl(
) -> anyhow::Result<()> {
#[cfg(feature = "native_viewer")]
let profiler = run_profiler(&args);
let mut is_another_viewer_running = false;

#[cfg(feature = "native_viewer")]
let startup_options = {
Expand Down Expand Up @@ -655,20 +656,7 @@ fn run_impl(
};

// Where do we get the data from?
let rx: Vec<Receiver<LogMsg>> = if args.url_or_paths.is_empty() {
#[cfg(feature = "server")]
{
let server_options = re_sdk_comms::ServerOptions {
max_latency_sec: parse_max_latency(args.drop_at_latency.as_ref()),
quiet: false,
};
let rx = re_sdk_comms::serve(&args.bind, args.port, server_options)?;
vec![rx]
}

#[cfg(not(feature = "server"))]
vec![]
} else {
let rx: Vec<Receiver<LogMsg>> = {
let data_sources = args
.url_or_paths
.iter()
Expand Down Expand Up @@ -697,10 +685,35 @@ fn run_impl(
}
}

data_sources
let mut rxs = data_sources
.into_iter()
.map(|data_source| data_source.stream(None))
.collect::<Result<Vec<_>, _>>()?
.collect::<Result<Vec<_>, _>>()?;

#[cfg(feature = "server")]
{
// Check if there is already a viewer running and if so, send the data to it.
use std::net::TcpStream;
let connect_addr = std::net::SocketAddr::new("127.0.0.1".parse().unwrap(), args.port);
if TcpStream::connect_timeout(&connect_addr, std::time::Duration::from_secs(1)).is_ok()
{
re_log::info!(
addr = %connect_addr,
"A process is already listening at this address. Assuming it's a Rerun Viewer."
);
is_another_viewer_running = true;
} else {
let server_options = re_sdk_comms::ServerOptions {
max_latency_sec: parse_max_latency(args.drop_at_latency.as_ref()),
quiet: false,
};
let tcp_listener: Receiver<LogMsg> =
re_sdk_comms::serve(&args.bind, args.port, server_options)?;
rxs.push(tcp_listener);
}
}

rxs
};

// Now what do we do with the data?
Expand Down Expand Up @@ -772,6 +785,9 @@ fn run_impl(

return Ok(());
}
} else if is_another_viewer_running {
re_log::info!("Another viewer is already running, streaming data to it.");
Ok(())
} else {
#[cfg(feature = "native_viewer")]
return re_viewer::run_native_app(
Expand Down
Loading