use crate::data_structures::AppData;
use crate::producer::{Producer, ProducerId};
use crate::uuid_based_wrapper_type;
use crate::worker::RequestError;
use async_trait::async_trait;
use event_listener_primitives::HandlerId;
uuid_based_wrapper_type!(
RtpObserverId
);
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct RtpObserverAddProducerOptions {
pub producer_id: ProducerId,
}
impl RtpObserverAddProducerOptions {
pub fn new(producer_id: ProducerId) -> Self {
Self { producer_id }
}
}
#[async_trait(?Send)]
pub trait RtpObserver {
fn id(&self) -> RtpObserverId;
fn paused(&self) -> bool;
fn app_data(&self) -> &AppData;
fn closed(&self) -> bool;
async fn pause(&self) -> Result<(), RequestError>;
async fn resume(&self) -> Result<(), RequestError>;
async fn add_producer(
&self,
rtp_observer_add_producer_options: RtpObserverAddProducerOptions,
) -> Result<(), RequestError>;
async fn remove_producer(&self, producer_id: ProducerId) -> Result<(), RequestError>;
fn on_pause(&self, callback: Box<dyn Fn() + Send + Sync + 'static>) -> HandlerId;
fn on_resume(&self, callback: Box<dyn Fn() + Send + Sync + 'static>) -> HandlerId;
fn on_add_producer(
&self,
callback: Box<dyn Fn(&Producer) + Send + Sync + 'static>,
) -> HandlerId;
fn on_remove_producer(
&self,
callback: Box<dyn Fn(&Producer) + Send + Sync + 'static>,
) -> HandlerId;
fn on_router_close(&self, callback: Box<dyn FnOnce() + Send + 'static>) -> HandlerId;
fn on_close(&self, callback: Box<dyn FnOnce() + Send + 'static>) -> HandlerId;
}