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-26 10:48:09 +08:00
|
|
|
pub use lib_ws::{WSConnectState, WSMessageReceiver, WebScoketRawMessage};
|
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>;
|
2021-12-16 22:24:05 +08:00
|
|
|
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 22:24:05 +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 {
|
2021-12-26 10:48:09 +08:00
|
|
|
fn send(&self, msg: WebScoketRawMessage) -> Result<(), FlowyError>;
|
2021-12-14 15:31:44 +08:00
|
|
|
}
|