diff --git a/README.md b/README.md index 99f3e6b..37c8386 100644 --- a/README.md +++ b/README.md @@ -402,11 +402,16 @@ You should be able to find the details in your [BELABOX cloud](https://cloud.bel ```JSON "streamServer": { "type": "Mediamtx", - "statsUrl": "http://localhost:9997/v3/paths/get/{name}" + "statsUrl": "http://localhost:9997/v3/paths/get/{name}", + "auth": { + "username": "user", + "password": "pass" + } }, ``` - `statsUrl`: The API stats page. Replace `{name}` with the name of your stream. +- `auth`: Optional field For more details, refer to the [MediaMTX documentation](https://github.com/bluenviron/mediamtx#table-of-contents). diff --git a/src/stream_servers/mediamtx.rs b/src/stream_servers/mediamtx.rs index cf52a32..d5703fd 100644 --- a/src/stream_servers/mediamtx.rs +++ b/src/stream_servers/mediamtx.rs @@ -101,12 +101,20 @@ pub struct Stats { pub srt: Option, } +#[derive(Serialize, Deserialize, Debug)] +pub struct Auth { + username: String, + password: String, +} + #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Mediamtx { /// URL to MediaMTX stats page (ex; http://localhost:9997/v3/paths/get/mystream ) pub stats_url: String, + pub auth: Option, + /// Client to make HTTP requests with #[serde(skip, default = "default_reqwest_client")] pub client: reqwest::Client, @@ -138,7 +146,13 @@ impl Default for Cache { impl Mediamtx { pub async fn get_stats(&self) -> Option { - let res = match self.client.get(&self.stats_url).send().await { + let mut request = self.client.get(&self.stats_url); + + if let Some(auth) = &self.auth { + request = request.basic_auth(&auth.username, Some(&auth.password)); + } + + let res = match request.send().await { Ok(res) => res, Err(_) => { error!("Stats page ({}) is unreachable", self.stats_url); @@ -197,7 +211,13 @@ impl Mediamtx { let stats_url: Vec<&str> = self.stats_url.split("/v3").collect(); let stats_url = format!("{}/v3/srtconns/get/{id}", stats_url.first()?); - let res = match self.client.get(stats_url.clone()).send().await { + let mut request = self.client.get(stats_url.clone()); + + if let Some(auth) = &self.auth { + request = request.basic_auth(&auth.username, Some(&auth.password)); + } + + let res = match request.send().await { Ok(res) => res, Err(_) => { error!("Stats page ({}) is unreachable", stats_url);