-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Web: Support multiple
.rrd
URLs (#4740)
### What Fixes #4630 New API can be seen here: https://github.com/rerun-io/web-viewer-react-example/blob/main/src/App.tsx ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using newly built examples: [app.rerun.io](https://app.rerun.io/pr/4740/index.html) * Using examples from latest `main` build: [app.rerun.io](https://app.rerun.io/pr/4740/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [app.rerun.io](https://app.rerun.io/pr/4740/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/4740) - [Docs preview](https://rerun.io/preview/165842ec644787f1b959e93fd14071c3ac7b6986/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/165842ec644787f1b959e93fd14071c3ac7b6986/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
- Loading branch information
Showing
9 changed files
with
308 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
use eframe::wasm_bindgen::{self, prelude::*}; | ||
|
||
use std::ops::ControlFlow; | ||
use std::sync::Arc; | ||
|
||
use re_log::ResultExt as _; | ||
|
@@ -80,6 +81,26 @@ impl WebHandle { | |
pub fn panic_callstack(&self) -> Option<String> { | ||
self.runner.panic_summary().map(|s| s.callstack()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn add_receiver(&self, url: &str) { | ||
let Some(mut app) = self.runner.app_mut::<crate::App>() else { | ||
return; | ||
}; | ||
let rx = url_to_receiver(url, app.re_ui.egui_ctx.clone()); | ||
app.add_receiver(rx); | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn remove_receiver(&self, url: &str) { | ||
let Some(mut app) = self.runner.app_mut::<crate::App>() else { | ||
return; | ||
}; | ||
app.msg_receive_set().remove_by_uri(url); | ||
if let Some(store_hub) = app.store_hub.as_mut() { | ||
store_hub.remove_recording_by_uri(url); | ||
} | ||
} | ||
} | ||
|
||
fn create_app( | ||
|
@@ -102,11 +123,6 @@ fn create_app( | |
let re_ui = crate::customize_eframe(cc); | ||
|
||
let egui_ctx = cc.egui_ctx.clone(); | ||
let wake_up_ui_on_msg = Box::new(move || { | ||
// Spend a few more milliseconds decoding incoming messages, | ||
// then trigger a repaint (https://github.com/rerun-io/rerun/issues/963): | ||
egui_ctx.request_repaint_after(std::time::Duration::from_millis(10)); | ||
}); | ||
|
||
let mut app = crate::App::new(build_info, &app_env, startup_options, re_ui, cc.storage); | ||
|
||
|
@@ -126,50 +142,67 @@ fn create_app( | |
None => query_map.get("url").map(String::as_str), | ||
}; | ||
if let Some(url) = url { | ||
let rx = match categorize_uri(url) { | ||
EndpointCategory::HttpRrd(url) => { | ||
re_log_encoding::stream_rrd_from_http::stream_rrd_from_http_to_channel( | ||
url, | ||
Some(wake_up_ui_on_msg), | ||
) | ||
} | ||
EndpointCategory::WebEventListener => { | ||
// Process an rrd when it's posted via `window.postMessage` | ||
let (tx, rx) = re_smart_channel::smart_channel( | ||
re_smart_channel::SmartMessageSource::RrdWebEventCallback, | ||
re_smart_channel::SmartChannelSource::RrdWebEventListener, | ||
); | ||
re_log_encoding::stream_rrd_from_http::stream_rrd_from_event_listener(Arc::new({ | ||
move |msg| { | ||
wake_up_ui_on_msg(); | ||
use re_log_encoding::stream_rrd_from_http::HttpMessage; | ||
match msg { | ||
HttpMessage::LogMsg(msg) => { | ||
tx.send(msg).warn_on_err_once("failed to send message") | ||
} | ||
HttpMessage::Success => { | ||
tx.quit(None).warn_on_err_once("failed to send quit marker") | ||
} | ||
HttpMessage::Failure(err) => tx | ||
.quit(Some(err)) | ||
.warn_on_err_once("failed to send quit marker"), | ||
}; | ||
} | ||
})); | ||
rx | ||
} | ||
EndpointCategory::WebSocket(url) => { | ||
re_data_source::connect_to_ws_url(&url, Some(wake_up_ui_on_msg)).unwrap_or_else( | ||
|err| panic!("Failed to connect to WebSocket server at {url}: {err}"), | ||
) | ||
} | ||
}; | ||
let rx = url_to_receiver(url, egui_ctx.clone()); | ||
app.add_receiver(rx); | ||
} | ||
|
||
app | ||
} | ||
|
||
fn url_to_receiver( | ||
url: &str, | ||
egui_ctx: egui::Context, | ||
) -> re_smart_channel::Receiver<re_log_types::LogMsg> { | ||
let ui_waker = Box::new(move || { | ||
// Spend a few more milliseconds decoding incoming messages, | ||
// then trigger a repaint (https://github.com/rerun-io/rerun/issues/963): | ||
egui_ctx.request_repaint_after(std::time::Duration::from_millis(10)); | ||
}); | ||
match categorize_uri(url) { | ||
EndpointCategory::HttpRrd(url) => { | ||
re_log_encoding::stream_rrd_from_http::stream_rrd_from_http_to_channel( | ||
url, | ||
Some(ui_waker), | ||
) | ||
} | ||
EndpointCategory::WebEventListener => { | ||
// Process an rrd when it's posted via `window.postMessage` | ||
let (tx, rx) = re_smart_channel::smart_channel( | ||
re_smart_channel::SmartMessageSource::RrdWebEventCallback, | ||
re_smart_channel::SmartChannelSource::RrdWebEventListener, | ||
); | ||
re_log_encoding::stream_rrd_from_http::stream_rrd_from_event_listener(Arc::new({ | ||
move |msg| { | ||
ui_waker(); | ||
use re_log_encoding::stream_rrd_from_http::HttpMessage; | ||
match msg { | ||
HttpMessage::LogMsg(msg) => { | ||
if tx.send(msg).is_ok() { | ||
ControlFlow::Continue(()) | ||
} else { | ||
re_log::info!("Failed to send log message to viewer - closing"); | ||
ControlFlow::Break(()) | ||
} | ||
} | ||
HttpMessage::Success => { | ||
tx.quit(None).warn_on_err_once("failed to send quit marker"); | ||
ControlFlow::Break(()) | ||
} | ||
HttpMessage::Failure(err) => { | ||
tx.quit(Some(err)) | ||
.warn_on_err_once("failed to send quit marker"); | ||
ControlFlow::Break(()) | ||
} | ||
} | ||
} | ||
})); | ||
rx | ||
} | ||
EndpointCategory::WebSocket(url) => re_data_source::connect_to_ws_url(&url, Some(ui_waker)) | ||
.unwrap_or_else(|err| panic!("Failed to connect to WebSocket server at {url}: {err}")), | ||
} | ||
} | ||
|
||
/// Used to set the "email" property in the analytics config, | ||
/// in the same way as `rerun analytics email [email protected]`. | ||
/// | ||
|
Oops, something went wrong.