use bytes::Bytes;
use super::error::ServerSessionError;
use crate::command_messages::UnknownCommand;
use crate::messages::UnknownMessage;
#[derive(Debug, Clone)]
pub enum SessionData {
Video {
timestamp: u32,
data: Bytes,
},
Audio {
timestamp: u32,
data: Bytes,
},
Amf0 {
timestamp: u32,
data: Bytes,
},
}
pub trait SessionHandler {
fn on_publish(
&mut self,
stream_id: u32,
app_name: &str,
stream_name: &str,
) -> impl std::future::Future<Output = Result<(), ServerSessionError>> + Send;
fn on_unpublish(&mut self, stream_id: u32) -> impl std::future::Future<Output = Result<(), ServerSessionError>> + Send;
fn on_unknown_message(
&mut self,
stream_id: u32,
message: UnknownMessage,
) -> impl std::future::Future<Output = Result<(), ServerSessionError>> + Send {
async move {
tracing::warn!(stream_id = %stream_id, message = ?message, "unknown message");
Ok(())
}
}
fn on_unknown_command(
&mut self,
stream_id: u32,
command: UnknownCommand,
) -> impl std::future::Future<Output = Result<(), ServerSessionError>> + Send {
async move {
tracing::debug!(stream_id = %stream_id, command = ?command, "unknown command");
Ok(())
}
}
fn on_data(
&mut self,
stream_id: u32,
data: SessionData,
) -> impl std::future::Future<Output = Result<(), ServerSessionError>> + Send;
}