RtmpHandler

Trait RtmpHandler 

Source
pub trait RtmpHandler:
    Send
    + Sync
    + 'static {
Show 19 methods // Provided methods fn on_connection( &self, _ctx: &SessionContext, ) -> impl Future<Output = bool> + Send { ... } fn on_handshake_complete( &self, _ctx: &SessionContext, ) -> impl Future<Output = ()> + Send { ... } fn on_connect( &self, _ctx: &SessionContext, _params: &ConnectParams, ) -> impl Future<Output = AuthResult> + Send { ... } fn on_fc_publish( &self, _ctx: &SessionContext, _stream_key: &str, ) -> impl Future<Output = AuthResult> + Send { ... } fn on_publish( &self, _ctx: &SessionContext, _params: &PublishParams, ) -> impl Future<Output = AuthResult> + Send { ... } fn on_play( &self, _ctx: &SessionContext, _params: &PlayParams, ) -> impl Future<Output = AuthResult> + Send { ... } fn on_metadata( &self, _ctx: &StreamContext, _metadata: &HashMap<String, AmfValue>, ) -> impl Future<Output = ()> + Send { ... } fn on_media_tag( &self, _ctx: &StreamContext, _tag: &FlvTag, ) -> impl Future<Output = bool> + Send { ... } fn on_video_frame( &self, _ctx: &StreamContext, _frame: &H264Data, _timestamp: u32, ) -> impl Future<Output = ()> + Send { ... } fn on_audio_frame( &self, _ctx: &StreamContext, _frame: &AacData, _timestamp: u32, ) -> impl Future<Output = ()> + Send { ... } fn on_keyframe( &self, _ctx: &StreamContext, _timestamp: u32, ) -> impl Future<Output = ()> + Send { ... } fn on_publish_stop( &self, _ctx: &StreamContext, ) -> impl Future<Output = ()> + Send { ... } fn on_unpublish( &self, _ctx: &StreamContext, ) -> impl Future<Output = ()> + Send { ... } fn on_play_stop( &self, _ctx: &StreamContext, ) -> impl Future<Output = ()> + Send { ... } fn on_pause(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send { ... } fn on_unpause( &self, _ctx: &StreamContext, ) -> impl Future<Output = ()> + Send { ... } fn on_disconnect( &self, _ctx: &SessionContext, ) -> impl Future<Output = ()> + Send { ... } fn media_delivery_mode(&self) -> MediaDeliveryMode { ... } fn on_stats_update( &self, _ctx: &SessionContext, ) -> impl Future<Output = ()> + Send { ... }
}
Expand description

Handler trait for RTMP applications

Implement this trait to customize RTMP server behavior. All methods have default implementations that accept/allow everything.

§Example

use rtmp_rs::{RtmpHandler, AuthResult};
use rtmp_rs::session::SessionContext;
use rtmp_rs::protocol::message::{ConnectParams, PublishParams};

struct MyHandler;

impl RtmpHandler for MyHandler {
    async fn on_connect(&self, ctx: &SessionContext, params: &ConnectParams) -> AuthResult {
        // Validate application name
        if params.app == "live" {
            AuthResult::Accept
        } else {
            AuthResult::Reject("Unknown application".into())
        }
    }

    async fn on_publish(&self, ctx: &SessionContext, params: &PublishParams) -> AuthResult {
        // Validate stream key (e.g., check against database)
        if params.stream_key.starts_with("valid_") {
            AuthResult::Accept
        } else {
            AuthResult::Reject("Invalid stream key".into())
        }
    }
}

Provided Methods§

Source

fn on_connection( &self, _ctx: &SessionContext, ) -> impl Future<Output = bool> + Send

Called when a new TCP connection is established

Return false to immediately close the connection. Use this for IP-based rate limiting or blocklists.

Source

fn on_handshake_complete( &self, _ctx: &SessionContext, ) -> impl Future<Output = ()> + Send

Called after successful handshake, before connect command

Source

fn on_connect( &self, _ctx: &SessionContext, _params: &ConnectParams, ) -> impl Future<Output = AuthResult> + Send

Called on RTMP ‘connect’ command

Validate the application name, auth tokens in tcUrl, etc.

Source

fn on_fc_publish( &self, _ctx: &SessionContext, _stream_key: &str, ) -> impl Future<Output = AuthResult> + Send

Called on FCPublish command (OBS/Twitch compatibility)

This is called before ‘publish’ and can be used for early stream key validation.

Source

fn on_publish( &self, _ctx: &SessionContext, _params: &PublishParams, ) -> impl Future<Output = AuthResult> + Send

Called on ‘publish’ command

Validate the stream key. This is the main authentication point for publishers.

Source

fn on_play( &self, _ctx: &SessionContext, _params: &PlayParams, ) -> impl Future<Output = AuthResult> + Send

Called on ‘play’ command

Validate play access. Return Reject to deny playback.

Source

fn on_metadata( &self, _ctx: &StreamContext, _metadata: &HashMap<String, AmfValue>, ) -> impl Future<Output = ()> + Send

Called when stream metadata is received (@setDataFrame/onMetaData)

Source

fn on_media_tag( &self, _ctx: &StreamContext, _tag: &FlvTag, ) -> impl Future<Output = bool> + Send

Called for each raw FLV tag (when MediaDeliveryMode includes RawFlv)

Return true to continue processing, false to drop the tag.

Source

fn on_video_frame( &self, _ctx: &StreamContext, _frame: &H264Data, _timestamp: u32, ) -> impl Future<Output = ()> + Send

Called for each video frame (when MediaDeliveryMode includes ParsedFrames)

Source

fn on_audio_frame( &self, _ctx: &StreamContext, _frame: &AacData, _timestamp: u32, ) -> impl Future<Output = ()> + Send

Called for each audio frame (when MediaDeliveryMode includes ParsedFrames)

Source

fn on_keyframe( &self, _ctx: &StreamContext, _timestamp: u32, ) -> impl Future<Output = ()> + Send

Called when a keyframe is received

Source

fn on_publish_stop( &self, _ctx: &StreamContext, ) -> impl Future<Output = ()> + Send

👎Deprecated since 0.3.0: Use on_unpublish instead

Called when the publish stream ends

Source

fn on_unpublish(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send

Called when the publish stream ends

Source

fn on_play_stop(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send

Called when the play stream ends

Source

fn on_pause(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send

Called when a subscriber pauses playback

Source

fn on_unpause(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send

Called when a subscriber resumes playback

Source

fn on_disconnect( &self, _ctx: &SessionContext, ) -> impl Future<Output = ()> + Send

Called when the connection closes

Source

fn media_delivery_mode(&self) -> MediaDeliveryMode

Get the media delivery mode for this handler

Source

fn on_stats_update( &self, _ctx: &SessionContext, ) -> impl Future<Output = ()> + Send

Called periodically with stats update

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§