2021-12-14 15:31:44 +08:00
|
|
|
use lib_infra::future::FutureResult;
|
|
|
|
use std::sync::Arc;
|
|
|
|
use tokio::sync::broadcast;
|
|
|
|
|
|
|
|
pub use flowy_error::FlowyError;
|
2021-12-16 21:31:36 +08:00
|
|
|
pub use lib_ws::{WsConnectState, WsMessage, WsMessageReceiver};
|
2021-12-14 15:31:44 +08:00
|
|
|
|
|
|
|
pub trait FlowyWebSocket: Send + Sync {
|
|
|
|
fn start_connect(&self, addr: String) -> FutureResult<(), FlowyError>;
|
2021-12-14 20:50:07 +08:00
|
|
|
fn stop_connect(&self) -> FutureResult<(), FlowyError>;
|
|
|
|
fn subscribe_connect_state(&self) -> broadcast::Receiver<WsConnectState>;
|
2021-12-14 15:31:44 +08:00
|
|
|
fn reconnect(&self, count: usize) -> FutureResult<(), FlowyError>;
|
2021-12-16 21:31:36 +08:00
|
|
|
fn add_message_receiver(&self, handler: Arc<dyn WsMessageReceiver>) -> Result<(), FlowyError>;
|
2021-12-14 15:31:44 +08:00
|
|
|
fn ws_sender(&self) -> Result<Arc<dyn FlowyWsSender>, FlowyError>;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait FlowyWsSender: Send + Sync {
|
|
|
|
fn send(&self, msg: WsMessage) -> Result<(), FlowyError>;
|
|
|
|
}
|