Skip to main content

o_sfu_protocol/
bundle_api.rs

1//! rust payloads for odoo browser bundle state and updates
2//!
3//! callable compatibility methods stay on `SfuClient`
4//! host projection emits these DTOs through the public [`crate::bundle`] facade
5
6use std::collections::BTreeMap;
7
8use serde::{Deserialize, Serialize};
9
10pub use crate::core::ConnectionState as BundleConnectionState;
11use crate::{
12    shared::{JsonPayload, RecordingStateUpdate, UserId, UserInfo},
13    signaling::TrackBinding,
14};
15
16#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
17pub struct BundleStateChange {
18    pub state: BundleConnectionState,
19    #[serde(skip_serializing_if = "Option::is_none")]
20    pub cause: Option<String>,
21}
22
23/// `info_change` payloads use string keys from [`bundle_session_info_key`]
24/// integer and string user ids that stringify to the same key collide, so the
25/// later entry wins
26pub type BundleSessionInfoSnapshotById = BTreeMap<String, UserInfo>;
27
28#[must_use]
29pub fn bundle_session_info_key(user_id: &UserId) -> String {
30    user_id.path_segment().into_owned()
31}
32
33#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
34pub struct BundleBroadcastUpdate {
35    #[serde(rename = "senderId")]
36    pub sender_id: UserId,
37    pub message: JsonPayload,
38}
39
40#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
41pub struct BundleDisconnectUpdate {
42    #[serde(rename = "sessionId")]
43    pub user_id: UserId,
44}
45
46#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
47pub struct BundleRemoteMediaUpdate {
48    pub bindings: Vec<TrackBinding>,
49}
50
51#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
52#[serde(tag = "name", content = "payload")]
53pub enum BundleUpdate {
54    #[serde(rename = "remote_media")]
55    RemoteMedia(BundleRemoteMediaUpdate),
56    #[serde(rename = "broadcast")]
57    Broadcast(BundleBroadcastUpdate),
58    #[serde(rename = "disconnect")]
59    Disconnect(BundleDisconnectUpdate),
60    #[serde(rename = "info_change")]
61    SessionInfoChange(BundleSessionInfoSnapshotById),
62    #[serde(rename = "channel_info_change")]
63    ChannelInfoChange(RecordingStateUpdate),
64}
65
66#[cfg(test)]
67#[path = "bundle_api/TESTS/mod.rs"]
68mod tests;