actr_runtime/transport/
wire_handle.rs1use super::error::NetworkResult;
7use super::lane::DataLane;
8use actr_protocol::PayloadType;
9
10pub use crate::wire::webrtc::WebRtcConnection;
12pub use crate::wire::websocket::WebSocketConnection;
13
14#[derive(Clone, Debug)]
21pub enum WireHandle {
22 WebSocket(WebSocketConnection),
24
25 WebRTC(WebRtcConnection),
27}
28
29impl WireHandle {
30 #[inline]
32 pub fn connection_type(&self) -> &'static str {
33 match self {
34 WireHandle::WebSocket(_) => "WebSocket",
35 WireHandle::WebRTC(_) => "WebRTC",
36 }
37 }
38
39 #[inline]
41 pub fn priority(&self) -> u8 {
42 match self {
43 WireHandle::WebSocket(_) => 0,
44 WireHandle::WebRTC(_) => 1, }
46 }
47
48 #[inline]
50 pub async fn connect(&self) -> NetworkResult<()> {
51 match self {
52 WireHandle::WebSocket(ws) => ws.connect().await,
53 WireHandle::WebRTC(rtc) => rtc.connect().await,
54 }
55 }
56
57 #[inline]
59 pub fn is_connected(&self) -> bool {
60 match self {
61 WireHandle::WebSocket(ws) => ws.is_connected(),
62 WireHandle::WebRTC(rtc) => rtc.is_connected(),
63 }
64 }
65
66 #[inline]
68 pub async fn close(&self) -> NetworkResult<()> {
69 match self {
70 WireHandle::WebSocket(ws) => ws.close().await,
71 WireHandle::WebRTC(rtc) => rtc.close().await,
72 }
73 }
74
75 #[inline]
77 pub async fn get_lane(&self, payload_type: PayloadType) -> NetworkResult<DataLane> {
78 match self {
79 WireHandle::WebSocket(ws) => ws.get_lane(payload_type).await,
80 WireHandle::WebRTC(rtc) => rtc.get_lane(payload_type).await,
81 }
82 }
83
84 #[inline]
86 pub async fn create_lane(&self, payload_type: PayloadType) -> NetworkResult<DataLane> {
87 self.get_lane(payload_type).await
88 }
89
90 #[inline]
92 pub fn as_webrtc(&self) -> Option<&WebRtcConnection> {
93 match self {
94 WireHandle::WebRTC(rtc) => Some(rtc),
95 _ => None,
96 }
97 }
98
99 #[inline]
101 pub fn as_websocket(&self) -> Option<&WebSocketConnection> {
102 match self {
103 WireHandle::WebSocket(ws) => Some(ws),
104 _ => None,
105 }
106 }
107
108 #[inline]
110 pub async fn invalidate_lane(&self, payload_type: PayloadType) {
111 if let WireHandle::WebRTC(rtc) = self {
112 rtc.invalidate_lane(payload_type).await;
113 }
114 }
115}
116
117#[derive(Debug, Clone)]
119pub enum WireStatus {
120 Connecting,
122
123 Ready(WireHandle),
125
126 Failed,
128}