pub struct Client { /* private fields */ }Expand description
SMS Client.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(config: ClientConfig) -> ClientResult<Self>
pub fn new(config: ClientConfig) -> ClientResult<Self>
Create an SMS client with a connection config.
Sourcepub fn http(&self) -> ClientResult<&HttpClient>
pub fn http(&self) -> ClientResult<&HttpClient>
Borrow the optional inner HTTP client.
Sourcepub fn http_arc(&self) -> ClientResult<Arc<HttpClient>>
pub fn http_arc(&self) -> ClientResult<Arc<HttpClient>>
Get a cloned Arc to the optional HTTP client for use in async contexts.
Sourcepub async fn on_message<F>(&self, callback: F) -> ClientResult<()>
pub async fn on_message<F>(&self, callback: F) -> ClientResult<()>
Set the callback for incoming WebSocket messages. The callback will include the WebSocket message and an Arc to the current Client allowing for easy use within the callback! This must be called before starting the WebSocket connection.
§Example
use sms_client::http::types::HttpOutgoingSmsMessage;
use sms_client::ws::types::WebsocketMessage;
use sms_client::Client;
use log::info;
#[tokio::main]
async fn main() {
let client: Client = unimplemented!("See other examples");
client.on_message(move |message, client| {
match message {
WebsocketMessage::IncomingMessage(sms) => {
// Can access client.http() here!
},
_ => { }
}
}).await?
}Sourcepub async fn on_message_simple<F>(&self, callback: F) -> ClientResult<()>
pub async fn on_message_simple<F>(&self, callback: F) -> ClientResult<()>
Set the callback for incoming WebSocket messages (simple version without client copy). This must be called before starting the WebSocket connection.
§Example
use sms_client::Client;
use sms_client::ws::types::WebsocketMessage;
use log::info;
#[tokio::main]
async fn main() {
let client: Client = unimplemented!("See other examples");
client.on_message_simple(move |message| {
match message {
WebsocketMessage::OutgoingMessage(sms) => info!("Outgoing message: {:?}", sms),
_ => { }
}
}).await?
}Sourcepub async fn start_background_websocket(&self) -> ClientResult<()>
pub async fn start_background_websocket(&self) -> ClientResult<()>
Start the WebSocket connection.
Sourcepub async fn start_blocking_websocket(&self) -> ClientResult<()>
pub async fn start_blocking_websocket(&self) -> ClientResult<()>
Start the WebSocket connection and block until closed.
Sourcepub async fn stop_background_websocket(&self) -> ClientResult<()>
pub async fn stop_background_websocket(&self) -> ClientResult<()>
Stop the WebSocket connection.
Sourcepub async fn is_websocket_connected(&self) -> bool
pub async fn is_websocket_connected(&self) -> bool
Check if the WebSocket is currently connected.
Sourcepub async fn reconnect_websocket(&self) -> ClientResult<()>
pub async fn reconnect_websocket(&self) -> ClientResult<()>
Force a WebSocket reconnection.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more