srs_client/callback_api/request.rs
1//! [HTTP Callback API][1] of [SRS] exposed by application.
2//!
3//! [SRS]: https://ossrs.io/
4//! [1]: https://ossrs.io/lts/en-us/docs/v5/doc/http-callback
5
6use std::net::IpAddr;
7
8use super::SrsCallbackEvent;
9use serde::{Deserialize, Serialize};
10
11/// Request performed by [SRS] to [HTTP Callback API][1].
12///
13/// [SRS]: https://ossrs.io/
14/// [1]: https://ossrs.io/lts/en-us/docs/v5/doc/http-callback
15#[derive(Clone, Debug, Deserialize, Serialize)]
16pub struct SrsCallbackReq {
17 /// ID of the [SRS] server
18 ///
19 /// [SRS]: https://ossrs.io/
20 pub server_id: String,
21
22 /// Event that [SRS] reports about.
23 ///
24 /// [SRS]: https://ossrs.io/
25 pub action: SrsCallbackEvent,
26
27 /// ID of [SRS] client that happened event is related to.
28 ///
29 /// [SRS]: https://ossrs.io/
30 pub client_id: String,
31
32 /// IP address of [SRS] client that happened event is related to.
33 ///
34 /// [SRS]: https://ossrs.io/
35 pub ip: IpAddr,
36
37 /// [SRS] `vhost` ([virtual host][1]) of RTMP stream that happened event is
38 /// related to.
39 ///
40 /// [SRS]: https://ossrs.io/
41 /// [1]: https://github.com/ossrs/srs/wiki/migrate_v4_EN_rtmp-url-vhost
42 pub vhost: String,
43
44 /// [SRS] `app` of RTMP stream that happened event is related to.
45 ///
46 /// [SRS]: https://ossrs.io/
47 pub app: String,
48
49 /// [SRS] `stream` of RTMP stream that happened event is related to.
50 ///
51 /// [SRS]: https://ossrs.io/
52 #[serde(default, skip_serializing_if = "Option::is_none")]
53 pub stream: Option<String>,
54}
55
56impl SrsCallbackReq {
57 /// Combine [`SrsCallbackReq::app`] and [`SrsCallbackReq::stream`] fields.
58 /// Uses for tracing
59 #[allow(dead_code)]
60 #[must_use]
61 pub fn app_stream(&self) -> String {
62 if let Some(stream) = &self.stream {
63 format!("{}/{}", self.app, stream)
64 } else {
65 self.app.clone()
66 }
67 }
68}