diff --git a/crates/network/src/web/client.rs b/crates/network/src/web/client.rs index 24c871ee35..7478479d6a 100644 --- a/crates/network/src/web/client.rs +++ b/crates/network/src/web/client.rs @@ -45,6 +45,7 @@ pub struct GameClientView { /// The url to connect to pub url: String, pub user_id: String, + pub fail_on_version_mismatch: bool, pub systems_and_resources: Cb (SystemGroup, Entity) + Sync + Send>, /// Invoked when the game client is loaded /// @@ -60,6 +61,7 @@ impl ElementComponent for GameClientView { let Self { url, user_id, + fail_on_version_mismatch, systems_and_resources, on_loaded, create_rpc_registry, @@ -122,6 +124,7 @@ impl ElementComponent for GameClientView { conn, &assets, user_id, + fail_on_version_mismatch, move |assets, user_id| { let (systems, resources) = systems_and_resources(); @@ -253,6 +256,7 @@ async fn handle_connection( mut conn: Connection, assets: &AssetCache, user_id: String, + fail_on_version_mismatch: bool, mut on_loaded: impl FnMut(&AssetCache, &str) -> anyhow::Result<(SharedClientGameState, CleanupFunc)>, control_rx: flume::Receiver, proxy_rx: flume::Receiver, @@ -289,7 +293,7 @@ async fn handle_connection( while client.is_pending() { tracing::info!("Waiting for server to accept connection and send server info"); if let Some(frame) = push_recv.next().await { - client.process_push(&assets, true, frame?)?; + client.process_push(&assets, fail_on_version_mismatch, frame?)?; } } @@ -321,7 +325,7 @@ async fn handle_connection( while let ClientProtoState::Connected(connected) = &mut client { tokio::select! { Some(frame) = push_recv.next() => { - client.process_push(&assets, true, frame?)?; + client.process_push(&assets, fail_on_version_mismatch, frame?)?; } Some(message) = proxy_rx.next() => { diff --git a/web/client/src/app.rs b/web/client/src/app.rs index 4041f7cb6c..d8cec49628 100644 --- a/web/client/src/app.rs +++ b/web/client/src/app.rs @@ -9,12 +9,13 @@ use ambient_ui_native::cb; use std::collections::HashMap; #[element_component] -pub fn MainApp(_hooks: &mut Hooks, server_url: String) -> Element { +pub fn MainApp(_hooks: &mut Hooks, server_url: String, fail_on_version_mismatch: bool) -> Element { tracing::info!("Connecting to {server_url:?}"); GameClientView { url: server_url, user_id: ambient_client_shared::util::random_username(), + fail_on_version_mismatch, systems_and_resources: cb(|| { let mut resources = Entity::new(); diff --git a/web/client/src/lib.rs b/web/client/src/lib.rs index 755002445b..a770ae77e9 100644 --- a/web/client/src/lib.rs +++ b/web/client/src/lib.rs @@ -1,4 +1,7 @@ -use std::sync::OnceLock; +use std::sync::{ + atomic::{AtomicBool, Ordering}, + OnceLock, +}; use ambient_app::App; use ambient_cameras::UICamera; @@ -33,9 +36,12 @@ static APP_CONTROL: OnceLock> = OnceLock::new(); pub struct Settings { pub enable_logging: bool, pub enable_panic_hook: bool, + pub allow_version_mismatch: Option, pub log_filter: Option, } +static ALLOW_VERSION_MISMATCH: AtomicBool = AtomicBool::new(false); + /// Initialize ambient #[wasm_bindgen] pub fn init(settings: JsValue) -> Result<(), JsValue> { @@ -63,6 +69,10 @@ pub fn init(settings: JsValue) -> Result<(), JsValue> { ambient_sys::set_panic_hook(); } + if let Some(allow_version_mismatch) = settings.allow_version_mismatch { + ALLOW_VERSION_MISMATCH.store(allow_version_mismatch, Ordering::SeqCst); + } + tracing::info!("Hello, Wasm!"); ambient_ecs::init_components(); @@ -123,7 +133,10 @@ async fn run(target: Option, server_url: String) -> anyhow Group(vec![ UICamera.el().with(active_camera(), 0.), ambient_client_shared::player::PlayerRawInputHandler.el(), - WindowSized::el([MainApp::el(server_url)]), + WindowSized::el([MainApp::el( + server_url, + !ALLOW_VERSION_MISMATCH.load(Ordering::SeqCst), + )]), ]) .el() .spawn_interactive(world); diff --git a/web/dioxus_example/src/main.rs b/web/dioxus_example/src/main.rs index 1a7354d4f3..5d04f9b643 100644 --- a/web/dioxus_example/src/main.rs +++ b/web/dioxus_example/src/main.rs @@ -10,6 +10,7 @@ fn main() { enable_logging: true, enable_panic_hook: true, log_filter: None, + allow_version_mismatch: Some(true), }) .unwrap(), ) diff --git a/web/www/src/main.ts b/web/www/src/main.ts index d7c6585936..a298e9ce59 100644 --- a/web/www/src/main.ts +++ b/web/www/src/main.ts @@ -82,7 +82,12 @@ import("ambient_web") return; } - ambient.init({ enableLogging: true, enablePanicHook : true, logFilter: "debug" }); + ambient.init({ + enableLogging: true, + enablePanicHook: true, + logFilter: "debug", + allowVersionMismatch: true, + }); let target = window.document.getElementById("instance-container"); @@ -92,8 +97,18 @@ import("ambient_web") } const urlParams = new URLSearchParams(window.location.search); - const package_id = urlParams.get('package'); - const url = package_id && `https://api.ambient.run/servers/ensure-running?package_id=${package_id}` || "https://127.0.0.1:9000"; + const packageId = urlParams.get('package'); + const context = urlParams.get('context'); + + let params = new URLSearchParams(); + if (packageId) { + params.set('package_id', packageId); + } + if (context) { + params.set('context', context); + } + + const url = params.size != 0 && `https://api.ambient.run/servers/ensure-running?${params.toString()}` || "https://127.0.0.1:9000"; console.log(`Connecting to ${url}`)