flare_im_core/client/
sys_handler.rs

1use crate::client::client::ClientState;
2use flare_core::error::Result;
3use async_trait::async_trait;
4use log::debug;
5use flare_core::flare_net::net::Command;
6
7#[async_trait]
8pub trait ClientSystemHandler: Send + Sync + 'static {
9    /// 退出登录
10    async fn login_out(&self) -> Result<()>;
11
12    /// 设置后台运行
13    async fn set_background(&self) -> Result<()>;
14
15    /// 设置语言
16    async fn set_language(&self) -> Result<()>;
17
18    /// 强制用户下线
19    async fn kick_online(&self) -> Result<()>;
20
21    /// 关闭连接
22    async fn close(&self) -> Result<()>;
23
24    /// 处理连接状态变化
25    async fn on_state_change(&self, state: ClientState);
26    /// 获取支持的命令列表
27    fn supported_commands(&self) -> Vec<Command>{
28        vec![Command::LoginOut , Command::SetBackground ,
29            Command::SetLanguage , Command::KickOnline ,
30            Command::Close]
31    }
32
33    /// 检查是否支持某个命令
34    fn supports_command(&self, command: Command) -> bool {
35        self.supported_commands().contains(&command)
36    }
37}
38
39/// 默认系统处理器
40pub struct DefClientSystemHandler;
41
42impl DefClientSystemHandler {
43    pub fn new() -> Self {
44        Self
45    }
46}
47
48#[async_trait]
49impl ClientSystemHandler for DefClientSystemHandler {
50    async fn login_out(&self) -> Result<()> {
51        debug!("处理退出登录");
52        Ok(())
53    }
54
55    async fn set_background(&self) -> Result<()> {
56        debug!("处理设置后台运行");
57        Ok(())
58    }
59
60    async fn set_language(&self) -> Result<()> {
61        debug!("处理设置语言");
62        Ok(())
63    }
64
65    async fn kick_online(&self) -> Result<()> {
66        debug!("处理强制下线");
67        Ok(())
68    }
69
70    async fn close(&self) -> Result<()> {
71        debug!("处理关闭连接");
72        Ok(())
73    }
74
75    async fn on_state_change(&self, state: ClientState) {
76        debug!("连接状态变化: {:?}", state);
77    }
78}