diff --git a/crates/torii/client/src/client/mod.rs b/crates/torii/client/src/client/mod.rs index a87415bb95..3d4bd4ec73 100644 --- a/crates/torii/client/src/client/mod.rs +++ b/crates/torii/client/src/client/mod.rs @@ -158,6 +158,13 @@ impl Client { Ok(stream) } + /// Unsuscribe to entities updates of a World. + pub async fn unsubscribe_entities(&self, ids: Vec) -> Result<(), Error> { + let mut grpc_client = self.inner.write().await; + grpc_client.unsubscribe_entities(ids).await?; + Ok(()) + } + /// A direct stream to grpc subscribe event messages pub async fn on_event_message_updated( &self, @@ -168,6 +175,13 @@ impl Client { Ok(stream) } + /// Unsuscribe to event messages updates of a World. + pub async fn unsubscribe_event_messages(&self, ids: Vec) -> Result<(), Error> { + let mut grpc_client = self.inner.write().await; + grpc_client.unsubscribe_event_messages(ids).await?; + Ok(()) + } + /// Returns the value of a model. /// /// This function will only return `None`, if `model` doesn't exist. If there is no model with diff --git a/crates/torii/grpc/src/client.rs b/crates/torii/grpc/src/client.rs index b71f767a84..d62c53ae8a 100644 --- a/crates/torii/grpc/src/client.rs +++ b/crates/torii/grpc/src/client.rs @@ -114,6 +114,19 @@ impl WorldClient { })))) } + /// Unsuscribe to entities updates of a World. + pub async fn unsubscribe_entities( + &mut self, + hashed_keys: Vec, + ) -> Result<(), Error> { + let hashed_keys = hashed_keys.iter().map(|hashed| hashed.to_bytes_be().to_vec()).collect(); + self.inner + .unsubscribe_entities(SubscribeEntitiesRequest { hashed_keys }) + .await + .map_err(Error::Grpc) + .map(|_| ()) + } + /// Subscribe to event messages of a World. pub async fn subscribe_event_messages( &mut self, @@ -133,6 +146,19 @@ impl WorldClient { })))) } + /// Unsuscribe to event messages of a World. + pub async fn unsubscribe_event_messages( + &mut self, + hashed_keys: Vec, + ) -> Result<(), Error> { + let hashed_keys = hashed_keys.iter().map(|hashed| hashed.to_bytes_be().to_vec()).collect(); + self.inner + .unsubscribe_event_messages(SubscribeEntitiesRequest { hashed_keys }) + .await + .map_err(Error::Grpc) + .map(|_| ()) + } + /// Subscribe to the model diff for a set of models of a World. pub async fn subscribe_model_diffs( &mut self,