use std::time::Duration;
use serde_json::Value;
use thiserror::Error;
use wscall_protocol::{ErrorPayload, FileAttachment, PacketEnvelope, ProtocolError};
pub(crate) enum ClientOutbound {
Packet(PacketEnvelope),
Ping(Vec<u8>),
Pong(Vec<u8>),
Close,
}
#[derive(Clone, Debug)]
pub struct ClientConnectionEvent {
pub url: String,
}
#[derive(Clone, Debug)]
pub struct ClientDisconnectEvent {
pub url: String,
pub reason: String,
pub will_reconnect: bool,
pub retry_after: Option<Duration>,
}
#[derive(Clone)]
pub struct EventMessage {
pub event_id: String,
pub name: String,
pub data: Value,
pub attachments: Vec<FileAttachment>,
pub metadata: Value,
}
#[derive(Debug, Error)]
pub enum ClientError {
#[error("websocket error: {0}")]
WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
#[error("protocol error: {0}")]
Protocol(#[from] ProtocolError),
#[error("client disconnected")]
Disconnected,
#[error("connection closed: {0}")]
ConnectionClosed(String),
#[error("connection idle timeout")]
IdleTimeout,
#[error("request timed out")]
Timeout,
#[error("remote error: {0:?}")]
Remote(ErrorPayload),
}