diff --git a/crates/torii/grpc/src/client.rs b/crates/torii/grpc/src/client.rs index 4a11e04777..7f34a60209 100644 --- a/crates/torii/grpc/src/client.rs +++ b/crates/torii/grpc/src/client.rs @@ -3,7 +3,7 @@ use std::num::ParseIntError; use futures_util::stream::MapOk; use futures_util::{Stream, StreamExt, TryStreamExt}; -use starknet::core::types::{FromStrError, StateUpdate}; +use starknet::core::types::{FromStrError, StateDiff, StateUpdate}; use starknet_crypto::FieldElement; use crate::proto::world::{ @@ -105,9 +105,9 @@ impl WorldClient { .map_err(Error::Grpc) .map(|res| res.into_inner())?; - Ok(EntityUpdateStreaming(stream.map_ok(Box::new(|res| { - let entity = res.entity.expect("entity must exist"); - entity.try_into().expect("must able to serialize") + Ok(EntityUpdateStreaming(stream.map_ok(Box::new(|res| match res.entity { + Some(entity) => entity.try_into().expect("must able to serialize"), + None => Entity { hashed_keys: FieldElement::ZERO, models: vec![] }, })))) } @@ -144,9 +144,11 @@ impl WorldClient { .map_err(Error::Grpc) .map(|res| res.into_inner())?; - Ok(ModelDiffsStreaming(stream.map_ok(Box::new(|res| { - let update = res.model_update.expect("qed; state update must exist"); - TryInto::::try_into(update).expect("must able to serialize") + Ok(ModelDiffsStreaming(stream.map_ok(Box::new(|res| match res.model_update { + Some(update) => { + TryInto::::try_into(update).expect("must able to serialize") + } + None => empty_state_update(), })))) } } @@ -184,3 +186,19 @@ impl Stream for EntityUpdateStreaming { self.0.poll_next_unpin(cx) } } + +fn empty_state_update() -> StateUpdate { + StateUpdate { + block_hash: FieldElement::ZERO, + new_root: FieldElement::ZERO, + old_root: FieldElement::ZERO, + state_diff: StateDiff { + declared_classes: vec![], + deployed_contracts: vec![], + deprecated_declared_classes: vec![], + nonces: vec![], + replaced_classes: vec![], + storage_diffs: vec![], + }, + } +} diff --git a/crates/torii/grpc/src/server/subscriptions/entity.rs b/crates/torii/grpc/src/server/subscriptions/entity.rs index 1573b5c61f..f9d4ae0d96 100644 --- a/crates/torii/grpc/src/server/subscriptions/entity.rs +++ b/crates/torii/grpc/src/server/subscriptions/entity.rs @@ -20,6 +20,7 @@ use torii_core::types::Entity; use tracing::{error, trace}; use crate::proto; +use crate::proto::world::SubscribeEntityResponse; pub(crate) const LOG_TARGET: &str = "torii::grpc::server::subscriptions::entity"; @@ -43,6 +44,11 @@ impl EntityManager { let id = rand::thread_rng().gen::(); let (sender, receiver) = channel(1); + // NOTE: unlock issue with firefox/safari + // initially send empty stream message to return from + // initial subscribe call + let _ = sender.send(Ok(SubscribeEntityResponse { entity: None })).await; + self.subscribers.write().await.insert( id, EntitiesSubscriber { hashed_keys: hashed_keys.iter().cloned().collect(), sender }, diff --git a/crates/torii/grpc/src/server/subscriptions/event_message.rs b/crates/torii/grpc/src/server/subscriptions/event_message.rs index 736f88c0f9..67cf1cf172 100644 --- a/crates/torii/grpc/src/server/subscriptions/event_message.rs +++ b/crates/torii/grpc/src/server/subscriptions/event_message.rs @@ -20,6 +20,7 @@ use torii_core::types::EventMessage; use tracing::{error, trace}; use crate::proto; +use crate::proto::world::SubscribeEntityResponse; pub(crate) const LOG_TARGET: &str = "torii::grpc::server::subscriptions::event_message"; pub struct EventMessagesSubscriber { @@ -42,6 +43,11 @@ impl EventMessageManager { let id = rand::thread_rng().gen::(); let (sender, receiver) = channel(1); + // NOTE: unlock issue with firefox/safari + // initially send empty stream message to return from + // initial subscribe call + let _ = sender.send(Ok(SubscribeEntityResponse { entity: None })).await; + self.subscribers.write().await.insert( id, EventMessagesSubscriber { hashed_keys: hashed_keys.iter().cloned().collect(), sender }, diff --git a/crates/torii/grpc/src/server/subscriptions/model_diff.rs b/crates/torii/grpc/src/server/subscriptions/model_diff.rs index ad257c719c..8e1f4e80cf 100644 --- a/crates/torii/grpc/src/server/subscriptions/model_diff.rs +++ b/crates/torii/grpc/src/server/subscriptions/model_diff.rs @@ -20,6 +20,7 @@ use tracing::{debug, error, trace}; use super::error::SubscriptionError; use crate::proto; +use crate::proto::world::SubscribeModelsResponse; use crate::types::KeysClause; pub(crate) const LOG_TARGET: &str = "torii::grpc::server::subscriptions::model_diff"; @@ -82,6 +83,11 @@ impl StateDiffManager { .flatten() .collect::>(); + // NOTE: unlock issue with firefox/safari + // initially send empty stream message to return from + // initial subscribe call + let _ = sender.send(Ok(SubscribeModelsResponse { model_update: None })).await; + self.subscribers .write() .await diff --git a/crates/torii/server/src/proxy.rs b/crates/torii/server/src/proxy.rs index df9f4e26f5..23539b5d49 100644 --- a/crates/torii/server/src/proxy.rs +++ b/crates/torii/server/src/proxy.rs @@ -17,7 +17,7 @@ use tower::ServiceBuilder; use tower_http::cors::{AllowOrigin, CorsLayer}; use tracing::error; -const DEFAULT_ALLOW_HEADERS: [&str; 12] = [ +const DEFAULT_ALLOW_HEADERS: [&str; 11] = [ "accept", "origin", "content-type", @@ -27,7 +27,6 @@ const DEFAULT_ALLOW_HEADERS: [&str; 12] = [ "x-grpc-timeout", "x-user-agent", "connection", - "upgrade", "sec-websocket-key", "sec-websocket-version", ];