tokio_xmpp/client/
receiver.rs1use crate::Client;
8use crate::Event;
9use core::{pin::Pin, task::Context};
10use futures::StreamExt;
11use futures::{task::Poll, Stream};
12use std::sync::Arc;
13use tokio::sync::Mutex;
14use xmpp_parsers::{jid::Jid, stream_features::StreamFeatures};
15
16#[derive(Debug)]
18pub struct ClientReceiver(pub(super) Arc<Mutex<Client>>);
19
20impl ClientReceiver {
21 pub async fn bound_jid(&self) -> Option<Jid> {
26 self.0.lock().await.bound_jid.clone()
27 }
28
29 pub async fn get_stream_features(&self) -> Option<StreamFeatures> {
34 self.0.lock().await.features.clone()
35 }
36}
37
38impl Stream for ClientReceiver {
39 type Item = Event;
40
41 fn poll_next(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
42 let Ok(mut client) = self.0.try_lock() else {
43 return Poll::Pending;
44 };
45
46 client.poll_next_unpin(cx)
47 }
48}