Skip to main content

rmux_sdk/web_share/
types.rs

1use rmux_proto::{PaneTargetRef, WebShareListener, WebShareScope};
2
3/// Redacted metadata for an active browser-visible pane or session share.
4#[derive(Debug, Clone, PartialEq, Eq)]
5pub struct WebShareSummary {
6    /// Opaque share id.
7    pub id: String,
8    /// Shared pane or session scope.
9    pub scope: WebShareScope,
10    /// Redacted spectator URL, if available.
11    pub spectator_url_redacted: Option<String>,
12    /// Whether this share has an operator URL.
13    pub operator: bool,
14    /// Whether this share has a spectator URL.
15    pub spectator: bool,
16    /// Active spectator client count.
17    pub active_spectators: u16,
18    /// Active operator client count.
19    pub active_operators: u16,
20    /// Maximum spectator clients allowed, when capped.
21    pub max_spectators: Option<u16>,
22    /// Maximum operator clients allowed, when capped.
23    pub max_operators: Option<u16>,
24    /// Expiration timestamp in UNIX seconds.
25    pub expires_at_unix: Option<u64>,
26    /// Whether the daemon kills the target session when this share expires.
27    pub kill_session_on_expire: bool,
28}
29
30impl WebShareSummary {
31    /// Returns the pane target when this is a single-pane share.
32    #[must_use]
33    pub fn pane_target(&self) -> Option<&PaneTargetRef> {
34        match &self.scope {
35            WebShareScope::Pane(target) => Some(target),
36            WebShareScope::Session(_) => None,
37        }
38    }
39}
40
41impl From<rmux_proto::WebShareSummary> for WebShareSummary {
42    fn from(value: rmux_proto::WebShareSummary) -> Self {
43        Self {
44            id: value.share_id,
45            scope: value.scope,
46            spectator_url_redacted: value.spectator_url,
47            operator: value.operator,
48            spectator: value.spectator,
49            active_spectators: value.active_spectators,
50            active_operators: value.active_operators,
51            max_spectators: value.max_spectators,
52            max_operators: value.max_operators,
53            expires_at_unix: value.expires_at_unix,
54            kill_session_on_expire: value.kill_session_on_expire,
55        }
56    }
57}
58
59/// Web-share listener configuration reported by the daemon.
60#[derive(Debug, Clone, PartialEq, Eq)]
61pub struct WebConfigInfo {
62    /// Listener host.
63    pub host: String,
64    /// Listener port.
65    pub port: u16,
66    /// Origin used by the web-share frontend.
67    pub frontend_origin: String,
68}
69
70impl From<WebShareListener> for WebConfigInfo {
71    fn from(value: WebShareListener) -> Self {
72        Self {
73            host: value.host,
74            port: value.port,
75            frontend_origin: value.frontend_origin,
76        }
77    }
78}