turn_server/
lib.rs

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