tokio_xmpp/client/sender.rs
1// Copyright (c) 2025 xmpp-rs contributors.
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7use crate::stanzastream::StanzaToken;
8use crate::IqRequest;
9use crate::IqResponseToken;
10use crate::Stanza;
11use std::io;
12use std::sync::Arc;
13use tokio::sync::Mutex;
14use xmpp_parsers::jid::Jid;
15
16/// Write half of a [`Client`](crate::Client).
17#[derive(Debug)]
18pub struct ClientSender(pub(super) Arc<Mutex<super::Client>>);
19
20impl ClientSender {
21 /// Send a stanza.
22 ///
23 /// See the documentation of [`Client::send_stanza`](crate::Client::send_stanza) for more
24 /// information.
25 pub async fn send_stanza(&self, stanza: Stanza) -> Result<StanzaToken, io::Error> {
26 self.0.lock().await.send_stanza(stanza).await
27 }
28
29 /// Send in iq.
30 ///
31 /// See the documentation of [`Client::send_iq`](crate::Client::send_iq) for more information.
32 pub async fn send_iq(&self, to: Option<Jid>, req: IqRequest) -> IqResponseToken {
33 self.0.lock().await.send_iq(to, req).await
34 }
35}