@@ -101,12 +101,20 @@ pub struct Stats {
101101 pub srt : Option < SrtStats > ,
102102}
103103
104+ #[ derive( Serialize , Deserialize , Debug ) ]
105+ pub struct Auth {
106+ username : String ,
107+ password : String ,
108+ }
109+
104110#[ derive( Serialize , Deserialize ) ]
105111#[ serde( rename_all = "camelCase" ) ]
106112pub struct Mediamtx {
107113 /// URL to MediaMTX stats page (ex; http://localhost:9997/v3/paths/get/mystream )
108114 pub stats_url : String ,
109115
116+ pub auth : Option < Auth > ,
117+
110118 /// Client to make HTTP requests with
111119 #[ serde( skip, default = "default_reqwest_client" ) ]
112120 pub client : reqwest:: Client ,
@@ -138,7 +146,13 @@ impl Default for Cache {
138146
139147impl Mediamtx {
140148 pub async fn get_stats ( & self ) -> Option < Stats > {
141- let res = match self . client . get ( & self . stats_url ) . send ( ) . await {
149+ let mut request = self . client . get ( & self . stats_url ) ;
150+
151+ if let Some ( auth) = & self . auth {
152+ request = request. basic_auth ( & auth. username , Some ( & auth. password ) ) ;
153+ }
154+
155+ let res = match request. send ( ) . await {
142156 Ok ( res) => res,
143157 Err ( _) => {
144158 error ! ( "Stats page ({}) is unreachable" , self . stats_url) ;
@@ -197,7 +211,13 @@ impl Mediamtx {
197211 let stats_url: Vec < & str > = self . stats_url . split ( "/v3" ) . collect ( ) ;
198212 let stats_url = format ! ( "{}/v3/srtconns/get/{id}" , stats_url. first( ) ?) ;
199213
200- let res = match self . client . get ( stats_url. clone ( ) ) . send ( ) . await {
214+ let mut request = self . client . get ( stats_url. clone ( ) ) ;
215+
216+ if let Some ( auth) = & self . auth {
217+ request = request. basic_auth ( & auth. username , Some ( & auth. password ) ) ;
218+ }
219+
220+ let res = match request. send ( ) . await {
201221 Ok ( res) => res,
202222 Err ( _) => {
203223 error ! ( "Stats page ({}) is unreachable" , stats_url) ;
0 commit comments