Crate scuffle_rtmp

Source
Expand description

A crate for handling RTMP server connections.

See the changelog for a full release history.

§Specifications

NameVersionLinkComments
Adobe’s Real Time Messaging Protocol1.0https://github.com/veovera/enhanced-rtmp/blob/main/docs/legacy/rtmp-v1-0-spec.pdfRefered to as ‘Legacy RTMP spec’ in this documentation
Enhancing RTMP, FLVv1-2024-02-29-r1https://github.com/veovera/enhanced-rtmp/blob/main/docs/enhanced/enhanced-rtmp-v1.pdf
Enhanced RTMPv2-2024-10-22-b1https://github.com/veovera/enhanced-rtmp/blob/main/docs/enhanced/enhanced-rtmp-v2.pdfRefered to as ‘Enhanced RTMP spec’ in this documentation

§Feature flags

  • docs — Enables changelog and documentation of feature flags

§Example

struct Handler;

impl SessionHandler for Handler {
    async fn on_data(&mut self, stream_id: u32, data: SessionData) -> Result<(), ServerSessionError> {
        // Handle incoming video/audio/meta data
        Ok(())
    }

    async fn on_publish(&mut self, stream_id: u32, app_name: &str, stream_name: &str) -> Result<(), ServerSessionError> {
        // Handle the publish event
        Ok(())
    }

    async fn on_unpublish(&mut self, stream_id: u32) -> Result<(), ServerSessionError> {
        // Handle the unpublish event
        Ok(())
    }
}

#[tokio::main]
async fn main() {
    let listener = TcpListener::bind("[::]:1935").await.unwrap();
    // listening on [::]:1935

    while let Ok((stream, addr)) = listener.accept().await {
        let session = ServerSession::new(stream, Handler);

        tokio::spawn(async move {
            if let Err(err) = session.run().await {
                // Handle the session error
            }
        });
    }
}

§License

This project is licensed under the MIT or Apache-2.0 license. You can choose between one of them if you use this work.

SPDX-License-Identifier: MIT OR Apache-2.0

Modules§

chunk
RTMP chunk protocol.
command_messages
Command messages.
error
General RTMP error type.
handshake
RTMP handshake logic.
messages
Message types and definitions.
protocol_control_messages
Protocol control messages as defined in 5.4.
session
High-level API to drive RTMP sessions.
user_control_messages
User control messages.
changelog
Changelogs generated by scuffle_changelog

Re-exports§

pub use session::server::ServerSession;