turn_server/
lib.rs

1pub mod api;
2pub mod config;
3pub mod observer;
4pub mod router;
5pub mod server;
6pub mod statistics;
7pub mod stun;
8pub mod turn;
9
10use std::sync::Arc;
11
12use self::{config::Config, observer::Observer, statistics::Statistics, turn::Service};
13
14#[rustfmt::skip]
15static SOFTWARE: &str = concat!(
16    "turn-rs.",
17    env!("CARGO_PKG_VERSION")
18);
19
20/// In order to let the integration test directly use the turn-server crate and
21/// start the server, a function is opened to replace the main function to
22/// directly start the server.
23pub async fn startup(config: Arc<Config>) -> anyhow::Result<()> {
24    let statistics = Statistics::default();
25    let service = Service::new(
26        SOFTWARE.to_string(),
27        config.turn.realm.clone(),
28        config.turn.get_externals(),
29        Observer::new(config.clone(), statistics.clone()).await?,
30    );
31
32    server::start(&config, &statistics, &service).await?;
33
34    #[cfg(feature = "api")]
35    {
36        api::start_server(config, service, statistics).await?;
37    }
38
39    // The turn server is non-blocking after it runs and needs to be kept from
40    // exiting immediately if the api server is not enabled.
41    #[cfg(not(feature = "api"))]
42    {
43        std::future::pending::<()>().await;
44    }
45
46    Ok(())
47}