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§
Sourcefn on_connection(
&self,
_ctx: &SessionContext,
) -> impl Future<Output = bool> + Send
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.
Sourcefn on_handshake_complete(
&self,
_ctx: &SessionContext,
) -> impl Future<Output = ()> + Send
fn on_handshake_complete( &self, _ctx: &SessionContext, ) -> impl Future<Output = ()> + Send
Called after successful handshake, before connect command
Sourcefn on_connect(
&self,
_ctx: &SessionContext,
_params: &ConnectParams,
) -> impl Future<Output = AuthResult> + Send
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.
Sourcefn on_fc_publish(
&self,
_ctx: &SessionContext,
_stream_key: &str,
) -> impl Future<Output = AuthResult> + Send
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.
Sourcefn on_publish(
&self,
_ctx: &SessionContext,
_params: &PublishParams,
) -> impl Future<Output = AuthResult> + Send
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.
Sourcefn on_play(
&self,
_ctx: &SessionContext,
_params: &PlayParams,
) -> impl Future<Output = AuthResult> + Send
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.
Sourcefn on_metadata(
&self,
_ctx: &StreamContext,
_metadata: &HashMap<String, AmfValue>,
) -> impl Future<Output = ()> + Send
fn on_metadata( &self, _ctx: &StreamContext, _metadata: &HashMap<String, AmfValue>, ) -> impl Future<Output = ()> + Send
Called when stream metadata is received (@setDataFrame/onMetaData)
Sourcefn on_media_tag(
&self,
_ctx: &StreamContext,
_tag: &FlvTag,
) -> impl Future<Output = bool> + Send
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.
Sourcefn on_video_frame(
&self,
_ctx: &StreamContext,
_frame: &H264Data,
_timestamp: u32,
) -> impl Future<Output = ()> + Send
fn on_video_frame( &self, _ctx: &StreamContext, _frame: &H264Data, _timestamp: u32, ) -> impl Future<Output = ()> + Send
Called for each video frame (when MediaDeliveryMode includes ParsedFrames)
Sourcefn on_audio_frame(
&self,
_ctx: &StreamContext,
_frame: &AacData,
_timestamp: u32,
) -> impl Future<Output = ()> + Send
fn on_audio_frame( &self, _ctx: &StreamContext, _frame: &AacData, _timestamp: u32, ) -> impl Future<Output = ()> + Send
Called for each audio frame (when MediaDeliveryMode includes ParsedFrames)
Sourcefn on_keyframe(
&self,
_ctx: &StreamContext,
_timestamp: u32,
) -> impl Future<Output = ()> + Send
fn on_keyframe( &self, _ctx: &StreamContext, _timestamp: u32, ) -> impl Future<Output = ()> + Send
Called when a keyframe is received
Sourcefn on_publish_stop(
&self,
_ctx: &StreamContext,
) -> impl Future<Output = ()> + Send
👎Deprecated since 0.3.0: Use on_unpublish instead
fn on_publish_stop( &self, _ctx: &StreamContext, ) -> impl Future<Output = ()> + Send
Called when the publish stream ends
Sourcefn on_unpublish(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send
fn on_unpublish(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send
Called when the publish stream ends
Sourcefn on_play_stop(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send
fn on_play_stop(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send
Called when the play stream ends
Sourcefn on_pause(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send
fn on_pause(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send
Called when a subscriber pauses playback
Sourcefn on_unpause(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send
fn on_unpause(&self, _ctx: &StreamContext) -> impl Future<Output = ()> + Send
Called when a subscriber resumes playback
Sourcefn on_disconnect(
&self,
_ctx: &SessionContext,
) -> impl Future<Output = ()> + Send
fn on_disconnect( &self, _ctx: &SessionContext, ) -> impl Future<Output = ()> + Send
Called when the connection closes
Sourcefn media_delivery_mode(&self) -> MediaDeliveryMode
fn media_delivery_mode(&self) -> MediaDeliveryMode
Get the media delivery mode for this handler
Sourcefn on_stats_update(
&self,
_ctx: &SessionContext,
) -> impl Future<Output = ()> + Send
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.