use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ServerConnectionState {
Handshaking,
WaitingConnect,
Connected,
Publishing,
Playing,
Closing,
Closed,
}
impl ServerConnectionState {
#[must_use]
pub const fn is_active(&self) -> bool {
!matches!(self, Self::Closing | Self::Closed)
}
#[must_use]
pub const fn is_connected(&self) -> bool {
matches!(self, Self::Connected | Self::Publishing | Self::Playing)
}
}
#[derive(Debug, Clone)]
pub struct RtmpServerConfig {
pub bind_address: String,
pub read_timeout: Duration,
pub write_timeout: Duration,
pub chunk_size: u32,
pub window_ack_size: u32,
pub max_connections: usize,
}
impl Default for RtmpServerConfig {
fn default() -> Self {
Self {
bind_address: format!("0.0.0.0:{DEFAULT_SERVER_PORT}"),
read_timeout: DEFAULT_READ_TIMEOUT,
write_timeout: DEFAULT_WRITE_TIMEOUT,
chunk_size: DEFAULT_CHUNK_SIZE,
window_ack_size: 2_500_000,
max_connections: 1000,
}
}
}
#[derive(Debug, Clone)]
pub struct ConnectionInfo {
pub id: u64,
pub address: SocketAddr,
pub app: String,
pub stream_name: String,
pub state: ServerConnectionState,
pub bytes_sent: u64,
pub bytes_received: u64,
pub stream_id: u32,
}
impl ConnectionInfo {
pub(super) fn new(id: u64, address: SocketAddr) -> Self {
Self {
id,
address,
app: String::new(),
stream_name: String::new(),
state: ServerConnectionState::Handshaking,
bytes_sent: 0,
bytes_received: 0,
stream_id: 0,
}
}
}
#[derive(Debug, Clone)]
pub struct OutgoingMessage {
pub message: RtmpMessage,
pub chunk_stream_id: u32,
}