pub struct Server {Show 13 fields
pub config: ServerConfig,
pub resource_limits: ResourceLimits,
pub max_relay_sends_per_poll: usize,
pub running: bool,
pub server_fd: i32,
pub connections: Vec<Conn>,
pub on_frame_cb: Option<fn(&Frame)>,
pub on_connect_cb: Option<fn()>,
pub on_publish_cb: Option<fn(conn_id: u64, app: &str, stream_name: &str) -> bool>,
pub on_play_cb: Option<fn(conn_id: u64, app: &str, stream_name: &str) -> bool>,
pub on_media_cb: Option<fn(u64, FrameType, Option<&str>) -> bool>,
pub tls_ctx: Option<TlsCtx>,
pub defer_media_relay: bool,
/* private fields */
}Expand description
Server object.
A single Server can bind more than one listener (see Server::listen
and Server::listen_tls) — e.g. plaintext RTMP on one port and RTMPS on
another. All listeners share the same connections, media relay, and
stream cache, so a publisher on one listener is relayed to players on any
other listener exactly as if they shared a port. Running two separate
Server instances instead would silently split the relay: each instance
only relays among its own connections.
Fields§
§config: ServerConfig§resource_limits: ResourceLimits§max_relay_sends_per_poll: usizeMaximum relay send operations allowed in one process_connections pass.
The first eligible frame in a pass is always relayed even when its fan-out exceeds this value, which guarantees forward progress instead of perpetually re-queueing an oversized frame. Later frames are deferred once the accumulated send count would exceed the configured budget.
running: bool§server_fd: i32Identifies one bound listener (whichever was bound first) for
diagnostics/backward compatibility. When more than one listener is
bound, use Server::listener_fds to register every listener with an
external readiness loop. Server::poll itself checks every bound
listener internally.
connections: Vec<Conn>§on_frame_cb: Option<fn(&Frame)>Fired for every audio/video frame on every connection.
on_connect_cb: Option<fn()>Fired when a client completes the AMF connect exchange.
on_publish_cb: Option<fn(conn_id: u64, app: &str, stream_name: &str) -> bool>When set, must return true to allow publish; false rejects the command.
on_play_cb: Option<fn(conn_id: u64, app: &str, stream_name: &str) -> bool>When set, must return true to allow play; false rejects the command.
on_media_cb: Option<fn(u64, FrameType, Option<&str>) -> bool>When set, must return true before publisher media is queued for relay.
tls_ctx: Option<TlsCtx>TLS context built from config at construction time; used by
Server::listen calls. This field stays public for Rust API
compatibility so integrators that used to replace server.tls_ctx
directly can continue to do so before calling listen().
defer_media_relay: boolHold media relay until the integrator enables it per connection.
Implementations§
Source§impl Server
impl Server
Sourcepub fn new(config: ServerConfig) -> Result<Self>
pub fn new(config: ServerConfig) -> Result<Self>
Create a new server.
Sourcepub fn set_conn_id_base(&mut self, base: u64)
pub fn set_conn_id_base(&mut self, base: u64)
Set the starting value used for auto-generated connection IDs.
Only needed when integrating with something outside this crate that
numbers connections independently and must not collide with this
Server’s IDs. Prefer Server::listen_tls over running a second
Server instance for a second listener — one Server with multiple
listeners numbers all of its connections from one counter already, so
this is unnecessary in that case. Call right after Server::new.
Panics if base is zero, cannot leave room for an increment, or if any
connection ID has already been issued.
Sourcepub fn listener_fds(&self) -> Vec<i32>
pub fn listener_fds(&self) -> Vec<i32>
Return the file descriptor for every currently bound listener.
Use this instead of the legacy Server::server_fd field when an
external readiness loop needs to watch a multi-listener Server.
Sourcepub fn listen(&mut self, bind_addr: &str) -> Result<()>
pub fn listen(&mut self, bind_addr: &str) -> Result<()>
Start listening on the given address (“host:port”, default port 1935).
Uses the TLS/plaintext mode selected at construction time via
ServerConfig::tls_enabled. Can be called more than once (e.g. to
also bind an IPv6 address); every bound listener shares this Server’s
connections, media relay, and stream cache. To add a listener with an
independent TLS certificate — e.g. plaintext RTMP plus RTMPS on a
second port — use Server::listen_tls instead.
Sourcepub fn listen_tls(
&mut self,
bind_addr: &str,
cert_file: &str,
key_file: &str,
) -> Result<()>
pub fn listen_tls( &mut self, bind_addr: &str, cert_file: &str, key_file: &str, ) -> Result<()>
Start an additional RTMPS listener with its own certificate/key,
independent of the TLS/plaintext mode passed to Server::new.
Connections accepted here land in the same connections list as every
other listener on this Server, so a publisher here is relayed to
players on any other listener (plaintext or TLS) and vice versa.
Sourcepub fn process_connections(&mut self) -> Result<()>
pub fn process_connections(&mut self) -> Result<()>
Process all active connections: drain readable bytes, drive the protocol state machine, relay frames from publishers to players, flush pending writes, and reap closed peers.