@@ -101,12 +101,20 @@ pub struct Stats {
101
101
pub srt : Option < SrtStats > ,
102
102
}
103
103
104
+ #[ derive( Serialize , Deserialize , Debug ) ]
105
+ pub struct Auth {
106
+ username : String ,
107
+ password : String ,
108
+ }
109
+
104
110
#[ derive( Serialize , Deserialize ) ]
105
111
#[ serde( rename_all = "camelCase" ) ]
106
112
pub struct Mediamtx {
107
113
/// URL to MediaMTX stats page (ex; http://localhost:9997/v3/paths/get/mystream )
108
114
pub stats_url : String ,
109
115
116
+ pub auth : Option < Auth > ,
117
+
110
118
/// Client to make HTTP requests with
111
119
#[ serde( skip, default = "default_reqwest_client" ) ]
112
120
pub client : reqwest:: Client ,
@@ -138,7 +146,13 @@ impl Default for Cache {
138
146
139
147
impl Mediamtx {
140
148
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 {
142
156
Ok ( res) => res,
143
157
Err ( _) => {
144
158
error ! ( "Stats page ({}) is unreachable" , self . stats_url) ;
@@ -197,7 +211,13 @@ impl Mediamtx {
197
211
let stats_url: Vec < & str > = self . stats_url . split ( "/v3" ) . collect ( ) ;
198
212
let stats_url = format ! ( "{}/v3/srtconns/get/{id}" , stats_url. first( ) ?) ;
199
213
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 {
201
221
Ok ( res) => res,
202
222
Err ( _) => {
203
223
error ! ( "Stats page ({}) is unreachable" , stats_url) ;
0 commit comments