rtmp_rs/session/
context.rs1use std::net::SocketAddr;
7use std::sync::Arc;
8
9use crate::protocol::message::ConnectParams;
10use crate::protocol::quirks::EncoderType;
11use crate::stats::SessionStats;
12
13#[derive(Debug, Clone)]
18pub struct SessionContext {
19 pub session_id: u64,
21
22 pub peer_addr: SocketAddr,
24
25 pub app: String,
27
28 pub encoder_type: EncoderType,
30
31 pub connect_params: Option<Arc<ConnectParams>>,
33
34 pub stats: SessionStats,
36}
37
38impl SessionContext {
39 pub fn new(session_id: u64, peer_addr: SocketAddr) -> Self {
41 Self {
42 session_id,
43 peer_addr,
44 app: String::new(),
45 encoder_type: EncoderType::Unknown,
46 connect_params: None,
47 stats: SessionStats::default(),
48 }
49 }
50
51 pub fn with_connect(&mut self, params: ConnectParams, encoder_type: EncoderType) {
53 self.app = params.app.clone();
54 self.encoder_type = encoder_type;
55 self.connect_params = Some(Arc::new(params));
56 }
57
58 pub fn tc_url(&self) -> Option<&str> {
60 self.connect_params
61 .as_ref()
62 .and_then(|p| p.tc_url.as_deref())
63 }
64
65 pub fn page_url(&self) -> Option<&str> {
67 self.connect_params
68 .as_ref()
69 .and_then(|p| p.page_url.as_deref())
70 }
71
72 pub fn flash_ver(&self) -> Option<&str> {
74 self.connect_params
75 .as_ref()
76 .and_then(|p| p.flash_ver.as_deref())
77 }
78}
79
80#[derive(Debug, Clone)]
82pub struct StreamContext {
83 pub session: SessionContext,
85
86 pub stream_id: u32,
88
89 pub stream_key: String,
91
92 pub is_publishing: bool,
94}
95
96impl StreamContext {
97 pub fn new(
99 session: SessionContext,
100 stream_id: u32,
101 stream_key: String,
102 is_publishing: bool,
103 ) -> Self {
104 Self {
105 session,
106 stream_id,
107 stream_key,
108 is_publishing,
109 }
110 }
111}