#![allow(unused)]
use actix_ws::{Closed, Session};
use arifa::prelude::*;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use thiserror::Error;
use uuid::Uuid;
#[derive(Debug, Error)]
pub enum WsSendError {
#[error("serialization error: {0}")]
Serde(#[from] serde_json::Error),
#[error("websocket session closed")]
Closed(#[from] Closed),
}
pub struct ActixWsSession {
pub ws: Session,
}
impl ActixWsSession {
pub fn new(ws: Session) -> Self {
Self { ws }
}
}
#[async_trait]
impl WsSession for ActixWsSession {
type Error = WsSendError;
async fn send(&self, event: WsMessage) -> Result<(), Self::Error> {
let text = serde_json::to_string(&event)?;
let mut session = self.ws.clone();
session.text(text).await?;
Ok(())
}
}
#[derive(Debug, Deserialize)]
pub struct ConnectRequestQuery {
pub user_id: Uuid,
}