wscall_client/
client_types.rs1use std::time::Duration;
2
3use serde_json::Value;
4use thiserror::Error;
5use wscall_protocol::{ErrorPayload, FileAttachment, PacketEnvelope, ProtocolError};
6
7pub(crate) enum ClientOutbound {
8 Packet(PacketEnvelope),
9 Ping(Vec<u8>),
10 Pong(Vec<u8>),
11 Close,
12}
13
14#[derive(Clone, Debug)]
16pub struct ClientConnectionEvent {
17 pub url: String,
19}
20
21#[derive(Clone, Debug)]
23pub struct ClientDisconnectEvent {
24 pub url: String,
26 pub reason: String,
28 pub will_reconnect: bool,
30 pub retry_after: Option<Duration>,
32}
33
34#[derive(Clone)]
36pub struct EventMessage {
37 pub event_id: String,
39 pub name: String,
41 pub data: Value,
43 pub attachments: Vec<FileAttachment>,
45 pub metadata: Value,
47}
48
49#[derive(Debug, Error)]
51pub enum ClientError {
52 #[error("websocket error: {0}")]
53 WebSocket(#[from] tokio_tungstenite::tungstenite::Error),
54 #[error("protocol error: {0}")]
55 Protocol(#[from] ProtocolError),
56 #[error("client disconnected")]
57 Disconnected,
58 #[error("connection closed: {0}")]
59 ConnectionClosed(String),
60 #[error("connection idle timeout")]
61 IdleTimeout,
62 #[error("request timed out")]
63 Timeout,
64 #[error("remote error: {0:?}")]
65 Remote(ErrorPayload),
66}