actr_runtime/transport/
route_table.rs

1//! PayloadType routing extension
2//!
3//! Provides static routing configuration for PayloadType
4
5use actr_protocol::PayloadType;
6
7/// DataChannel QoS configuration
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
9pub enum DataChannelQoS {
10    /// Signaling: ordered, reliable
11    Signal,
12
13    /// Reliable: reliable transmission
14    Reliable,
15
16    /// Latency-first: allow packet loss
17    LatencyFirst,
18}
19
20/// DataLane type identifier
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22pub enum DataLaneType {
23    /// WebRTC DataChannel (with QoS)
24    WebRtcDataChannel(DataChannelQoS),
25
26    /// WebSocket
27    WebSocket,
28}
29
30/// PayloadType routing extension
31pub trait PayloadTypeExt {
32    /// Get the list of supported DataLane types (ordered by priority)
33    fn data_lane_types(self) -> &'static [DataLaneType];
34}
35
36impl PayloadTypeExt for PayloadType {
37    #[inline]
38    fn data_lane_types(self) -> &'static [DataLaneType] {
39        match self {
40            // RPC_RELIABLE - RpcEnvelope with reliable ordered transmission
41            PayloadType::RpcReliable => &[
42                DataLaneType::WebRtcDataChannel(DataChannelQoS::Reliable),
43                DataLaneType::WebSocket,
44            ],
45
46            // RPC_SIGNAL - RpcEnvelope with high-priority signaling channel
47            PayloadType::RpcSignal => &[
48                DataLaneType::WebRtcDataChannel(DataChannelQoS::Signal),
49                DataLaneType::WebSocket,
50            ],
51
52            // STREAM_RELIABLE - DataStream with reliable ordered transmission
53            PayloadType::StreamReliable => &[
54                DataLaneType::WebRtcDataChannel(DataChannelQoS::Reliable),
55                DataLaneType::WebSocket,
56            ],
57
58            // STREAM_LATENCY_FIRST - DataStream with low latency partial-reliable transmission
59            PayloadType::StreamLatencyFirst => &[
60                DataLaneType::WebRtcDataChannel(DataChannelQoS::LatencyFirst),
61                DataLaneType::WebSocket,
62            ],
63
64            // MEDIA_RTP - Not routed through DataLane, uses MediaFrameRegistry
65            PayloadType::MediaRtp => &[],
66        }
67    }
68}
69
70impl DataLaneType {
71    /// Determine if WebRTC connection is needed for this DataLane Type
72    #[inline]
73    pub fn needs_webrtc(self) -> bool {
74        matches!(self, DataLaneType::WebRtcDataChannel(_))
75    }
76
77    /// Check if this DataLane Type supports WebSocket
78    #[inline]
79    pub fn supports_websocket(self) -> bool {
80        matches!(self, DataLaneType::WebSocket)
81    }
82}