zoe_client/client/api/
secret.rs

1use super::super::Client;
2use crate::{RelayConnectionStatus, client::ClientSecret};
3use eyeball::Subscriber;
4
5#[cfg(feature = "frb-api")]
6use flutter_rust_bridge::frb;
7
8#[cfg_attr(feature = "frb-api", frb)]
9impl Client {
10    /// Get the current client secret
11    pub fn client_secret(&self) -> ClientSecret {
12        self.client_secret_observable.get()
13    }
14}
15
16#[cfg_attr(feature = "frb-api", frb(ignore))]
17impl Client {
18    /// Subscribe to client secret updates
19    ///
20    /// Third parties can use this to be notified when the client secret changes,
21    /// allowing them to store updated client secrets with the current server configuration.
22    pub fn subscribe_to_client_secret(&self) -> Subscriber<ClientSecret> {
23        self.client_secret_observable.subscribe()
24    }
25
26    /// Update the client secret observable state with current server configuration
27    pub(crate) async fn update_client_secret_state(&self) {
28        // Get only successfully connected servers for persistence in client secret
29        let connected_servers = {
30            let info_map = self.relay_info.read().await;
31            info_map
32                .values()
33                .filter(|info| matches!(info.status, RelayConnectionStatus::Connected { .. }))
34                .map(|info| info.info.relay_address.clone())
35                .collect::<Vec<_>>()
36        };
37
38        // Update client secret with current server configuration
39        let mut updated_client_secret = (*self.client_secret).clone();
40        updated_client_secret.servers = connected_servers;
41
42        self.client_secret_observable.set(updated_client_secret);
43    }
44}