aboutsummaryrefslogtreecommitdiff
path: root/src/subs.rs
blob: df9531d004b4a85c885fd4f6431032b51fa738a3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyleft (ɔ) 2021-2021 The Whirlsplash Collective
// SPDX-License-Identifier: GPL-3.0-only

use crate::{
  api::Api,
  config::Config,
  prompt::Prompt,
  server::{
    distributor::Distributor,
    hub::Hub,
    server::{
      Server,
      ServerType::{AutoServer, RoomServer},
    },
  },
};

pub async fn run() -> ! {
  let _threads = vec![
    tokio::spawn(async move {
      let _ = Distributor::listen(
        &*format!("0.0.0.0:{}", Config::get().unwrap().distributor.port),
        AutoServer,
      )
      .await;
    }),
    tokio::spawn(async move {
      let _ = Hub::listen(
        &*format!("0.0.0.0:{}", Config::get().unwrap().hub.port),
        RoomServer,
      )
      .await;
    }),
    tokio::spawn(async move {
      let _ = Api::listen();
    }),
  ];

  if std::env::var("DISABLE_PROMPT").unwrap_or("false".to_string()) == "true" {
    info!("starting with prompt disabled");
    loop {
      std::thread::sleep(std::time::Duration::default());
    }
  } else {
    std::thread::sleep(std::time::Duration::from_secs(2));
    Prompt::handle();
  }
}