rustpbx/proxy/
mediaproxy.rs1use super::{server::SipServerRef, ProxyAction, ProxyModule};
2use crate::config::ProxyConfig;
3use anyhow::Result;
4use async_trait::async_trait;
5use rsipstack::transaction::transaction::Transaction;
6use std::{
7 collections::HashMap,
8 path::PathBuf,
9 sync::{Arc, Mutex},
10 time::SystemTime,
11};
12use tokio_util::sync::CancellationToken;
13use tracing::info;
14
15pub struct MediaSession {
16 pub call_id: String,
17 pub from_tag: String,
18 pub to_tag: Option<String>,
19 pub start_time: SystemTime,
20 pub sdp_offer: Option<String>,
21 pub sdp_answer: Option<String>,
22 pub recording_enabled: bool,
23 pub recording_path: Option<PathBuf>,
24}
25
26impl MediaSession {
27 pub fn new(call_id: &str, from_tag: &str) -> Self {
28 Self {
29 call_id: call_id.to_string(),
30 from_tag: from_tag.to_string(),
31 to_tag: None,
32 start_time: SystemTime::now(),
33 sdp_offer: None,
34 sdp_answer: None,
35 recording_enabled: false,
36 recording_path: None,
37 }
38 }
39}
40
41#[derive(Clone)]
42pub struct MediaProxyModule {
43 config: Arc<ProxyConfig>,
44 sessions: Arc<Mutex<HashMap<String, MediaSession>>>,
45}
46
47impl MediaProxyModule {
48 pub fn new(config: Arc<ProxyConfig>) -> Self {
49 Self {
50 config,
51 sessions: Arc::new(Mutex::new(HashMap::new())),
52 }
53 }
54}
55
56#[async_trait]
57impl ProxyModule for MediaProxyModule {
58 fn name(&self) -> &str {
59 "mediaproxy"
60 }
61
62 async fn on_start(&mut self, _inner: SipServerRef) -> Result<()> {
63 info!("MediaProxyModule started");
64 Ok(())
65 }
66
67 async fn on_stop(&self) -> Result<()> {
68 info!("MediaProxyModule stopped");
69 Ok(())
70 }
71 async fn on_transaction_begin(
72 &self,
73 _token: CancellationToken,
74 _tx: &mut Transaction,
75 ) -> Result<ProxyAction> {
76 Ok(ProxyAction::Continue)
77 }
78 async fn on_transaction_end(&self, _tx: &mut Transaction) -> Result<()> {
79 Ok(())
80 }
81}