use crate::common::protocol::{
Frame,
MessageCommand,
NotificationCommand,
flare::core::commands::{
message_command::Type as MessageType,
notification_command::Type as NotificationType,
},
};
use crate::common::error::Result;
use async_trait::async_trait;
#[async_trait]
pub trait ServerEventHandler: Send + Sync {
async fn handle_connect(&self, frame: &Frame, connection_id: &str) -> Result<Option<Frame>> {
let _ = (frame, connection_id);
Ok(None)
}
async fn handle_ping(&self, frame: &Frame, connection_id: &str) -> Result<Option<Frame>> {
let _ = (frame, connection_id);
Ok(None)
}
async fn handle_pong(&self, frame: &Frame, connection_id: &str) -> Result<Option<Frame>> {
let _ = (frame, connection_id);
Ok(None)
}
async fn handle_message_command(
&self,
command: &MessageCommand,
connection_id: &str,
) -> Result<Option<Frame>> {
let _ = (command, connection_id);
Ok(None)
}
async fn handle_message_command_by_type(
&self,
command: &MessageCommand,
msg_type: MessageType,
connection_id: &str,
) -> Result<Option<Frame>> {
let _ = msg_type;
self.handle_message_command(command, connection_id).await
}
async fn handle_notification_command(
&self,
command: &NotificationCommand,
connection_id: &str,
) -> Result<Option<Frame>> {
let _ = (command, connection_id);
Ok(None)
}
async fn handle_notification_command_by_type(
&self,
command: &NotificationCommand,
notif_type: NotificationType,
connection_id: &str,
) -> Result<Option<Frame>> {
let _ = notif_type;
self.handle_notification_command(command, connection_id).await
}
async fn on_disconnect(&self, connection_id: &str, reason: Option<&str>) -> Result<()> {
let _ = (connection_id, reason);
Ok(())
}
async fn on_error(&self, connection_id: &str, error: &str) -> Result<()> {
let _ = (connection_id, error);
Ok(())
}
}