mod data_stream_activity;
mod host_gate;
mod peer_gate;
pub use host_gate::HostGate;
pub use peer_gate::PeerGate;
use actr_framework::{Bytes, MediaSample};
use actr_protocol::{ActorResult, ActrError, ActrId, PayloadType, RpcEnvelope};
use std::sync::Arc;
#[derive(Clone)]
pub(crate) enum Gate {
Host(Arc<HostGate>),
Peer(Arc<PeerGate>),
}
impl Gate {
pub(crate) async fn send_request_with_type(
&self,
target_id: &ActrId,
payload_type: PayloadType,
envelope: RpcEnvelope,
) -> ActorResult<Bytes> {
match self {
Gate::Host(gate) => {
gate.send_request_with_type(target_id, payload_type, None, envelope)
.await
}
Gate::Peer(gate) => {
gate.send_request_with_type(target_id, payload_type, envelope)
.await
}
}
}
pub(crate) async fn send_message_with_type(
&self,
target: &ActrId,
payload_type: PayloadType,
envelope: RpcEnvelope,
) -> ActorResult<()> {
match self {
Gate::Host(gate) => {
gate.send_message_with_type(target, payload_type, None, envelope)
.await
}
Gate::Peer(gate) => {
gate.send_message_with_type(target, payload_type, envelope)
.await
}
}
}
pub(crate) async fn send_media_sample(
&self,
target: &ActrId,
track_id: &str,
sample: MediaSample,
) -> ActorResult<()> {
match self {
Gate::Host(_gate) => {
Err(ActrError::NotImplemented(
"MediaTrack is only supported for remote actors via WebRTC".to_string(),
))
}
Gate::Peer(gate) => gate.send_media_sample(target, track_id, sample).await,
}
}
pub(crate) async fn add_media_track(
&self,
target: &ActrId,
track_id: &str,
codec: &str,
media_type: &str,
) -> ActorResult<()> {
match self {
Gate::Host(_gate) => Err(ActrError::NotImplemented(
"MediaTrack is only supported for remote actors via WebRTC".to_string(),
)),
Gate::Peer(gate) => {
gate.add_media_track(target, track_id, codec, media_type)
.await
}
}
}
pub(crate) async fn remove_media_track(
&self,
target: &ActrId,
track_id: &str,
) -> ActorResult<()> {
match self {
Gate::Host(_gate) => Err(ActrError::NotImplemented(
"MediaTrack is only supported for remote actors via WebRTC".to_string(),
)),
Gate::Peer(gate) => gate.remove_media_track(target, track_id).await,
}
}
pub(crate) async fn send_data_stream(
&self,
target: &ActrId,
payload_type: actr_protocol::PayloadType,
stream_id: &str,
data: Bytes,
) -> ActorResult<()> {
match self {
Gate::Host(gate) => {
gate.send_data_stream(target, payload_type, stream_id, data)
.await
}
Gate::Peer(gate) => {
gate.send_data_stream(target, payload_type, stream_id, data)
.await
}
}
}
}