Element messages to back to websocket
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use crate::broadcast_messages::BroadcastMessage;
|
||||
use crate::broadcast_messages::{BroadcastMessage, SyncEvent};
|
||||
use crate::constants::{WS_CLIENT_TIMEOUT, WS_HEARTBEAT_INTERVAL};
|
||||
use crate::extractors::client_auth::APIClientAuth;
|
||||
use crate::server::HttpResult;
|
||||
@ -12,6 +12,13 @@ use tokio::sync::broadcast;
|
||||
use tokio::sync::broadcast::Receiver;
|
||||
use tokio::time::interval;
|
||||
|
||||
/// Messages send to the client
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum WsMessage {
|
||||
Sync(SyncEvent),
|
||||
}
|
||||
|
||||
/// Main WS route
|
||||
pub async fn ws(
|
||||
req: HttpRequest,
|
||||
@ -80,6 +87,19 @@ pub async fn ws_handler(
|
||||
break None;
|
||||
}
|
||||
}
|
||||
|
||||
BroadcastMessage::SyncEvent(userid, event) => {
|
||||
if userid != auth.user.user_id {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Send the message to the websocket
|
||||
if let Ok(msg) = serde_json::to_string(&WsMessage::Sync(event)) {
|
||||
if let Err(e) = session.text(msg).await {
|
||||
log::error!("Failed to send SyncEvent: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user