#![deny(missing_docs)]
#![deny(rustdoc::broken_intra_doc_links)]
use caelix_core::{Container, HttpException, Result};
use serde::Serialize;
pub use socketioxide::layer::SocketIoLayer;
pub use socketioxide::{
SocketIo,
extract::{AckSender, Data, SocketRef},
};
#[derive(Clone)]
pub struct SocketIoHandle {
io: SocketIo,
}
impl SocketIoHandle {
pub fn build() -> (SocketIoLayer, Self) {
let (layer, io) = SocketIo::builder().build_layer();
(layer, Self { io })
}
pub fn io(&self) -> &SocketIo {
&self.io
}
}
#[doc(hidden)]
pub trait SocketIoGateway: Send + Sync + 'static {
fn register_socket_io(io: &SocketIo, container: &Container) -> Result<()>;
}
#[derive(Serialize)]
pub struct SocketIoError {
pub error: String,
pub message: String,
}
impl From<HttpException> for SocketIoError {
fn from(exception: HttpException) -> Self {
Self {
error: exception.error.to_owned(),
message: exception.message,
}
}
}