sms_client/ws/
types.rs

1//! Websocket interface related message types.
2
3use serde::{Deserialize, Serialize};
4
5/// WebSocket message types that can be received from the server.
6#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
7#[serde(tag = "type", content = "data")]
8pub enum WebsocketMessage {
9    /// New SMS message received.
10    #[serde(rename = "incoming")]
11    IncomingMessage(crate::types::SmsStoredMessage),
12
13    /// SMS message being sent from API or other connected client.
14    #[serde(rename = "outgoing")]
15    OutgoingMessage(crate::types::SmsStoredMessage),
16
17    /// Delivery report update.
18    #[serde(rename = "delivery")]
19    DeliveryReport {
20        /// The target message_id this delivery report applies to.
21        /// This is determined from the message_reference and sender.
22        message_id: i64,
23
24        /// The received delivery report.
25        report: crate::types::SmsPartialDeliveryReport,
26    },
27
28    /// Modem hat connection status update.
29    /// This can be either: Startup, Online, ShuttingDown, Offline
30    #[serde(rename = "modem_status_update")]
31    ModemStatusUpdate {
32        /// Previous state from last update.
33        previous: crate::types::ModemStatusUpdateState,
34
35        /// Current state after update.
36        current: crate::types::ModemStatusUpdateState,
37    },
38
39    /// An unsolicited position report from GNSS.
40    #[serde(rename = "gnss_position_report")]
41    GnssPositionReport(crate::types::GnssPositionReport),
42
43    /// WebSocket connection status update (client-side only).
44    /// This message is generated locally when there is a connection or disconnection.
45    WebsocketConnectionUpdate {
46        /// Connection status: true = connected, false = disconnected
47        connected: bool,
48
49        /// If connection is false, will the client attempt to automatically reconnect?
50        reconnect: bool,
51    },
52}
53
54/// A callback to be run when the websocket receives a message.
55pub type MessageCallback = std::sync::Arc<dyn Fn(WebsocketMessage) + Send + Sync>;