aboutsummaryrefslogtreecommitdiffstats
path: root/src/client.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2024-12-04 17:38:36 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2024-12-04 17:38:36 +0000
commit21f10a0b43c4ab1429b274b386065c023c661ab0 (patch)
tree9e65aae47363f6ba2f1f8c10cb9ed7c35c82e5b2 /src/client.rs
parent4886396044356d2676a77c3900af796fe7641f42 (diff)
downloadluz-21f10a0b43c4ab1429b274b386065c023c661ab0.tar.gz
luz-21f10a0b43c4ab1429b274b386065c023c661ab0.tar.bz2
luz-21f10a0b43c4ab1429b274b386065c023c661ab0.zip
implement send_stanza
Diffstat (limited to '')
-rw-r--r--src/client.rs44
1 files changed, 12 insertions, 32 deletions
diff --git a/src/client.rs b/src/client.rs
index 5351b34..e94008d 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -44,6 +44,8 @@ impl JabberClient {
pub async fn connect(&mut self) -> Result<()> {
match &self.connection {
ConnectionState::Disconnected => {
+ // TODO: actually set the self.connection as it is connecting, make more asynchronous (mutex while connecting?)
+ // perhaps use take_mut?
self.connection = ConnectionState::Disconnected
.connect(&mut self.jid, self.password.clone(), &mut self.server)
.await?;
@@ -53,6 +55,16 @@ impl JabberClient {
ConnectionState::Connected(_jabber_stream) => Ok(()),
}
}
+
+ pub async fn send_stanza(&mut self, stanza: &Stanza) -> Result<()> {
+ match &mut self.connection {
+ ConnectionState::Disconnected => return Err(Error::Disconnected),
+ ConnectionState::Connecting(_connecting) => return Err(Error::Connecting),
+ ConnectionState::Connected(jabber_stream) => {
+ Ok(jabber_stream.send_stanza(stanza).await?)
+ }
+ }
+ }
}
impl Stream for JabberClient {
@@ -217,38 +229,6 @@ pub enum InsecureConnecting {
Bound(JabberStream<Tls>),
}
-impl Sink<Stanza> for JabberClient {
- type Error = Error;
-
- fn poll_ready(
- self: std::pin::Pin<&mut Self>,
- cx: &mut std::task::Context<'_>,
- ) -> std::task::Poll<std::result::Result<(), Self::Error>> {
- todo!()
- }
-
- fn start_send(
- self: std::pin::Pin<&mut Self>,
- item: Stanza,
- ) -> std::result::Result<(), Self::Error> {
- todo!()
- }
-
- fn poll_flush(
- self: std::pin::Pin<&mut Self>,
- cx: &mut std::task::Context<'_>,
- ) -> std::task::Poll<std::result::Result<(), Self::Error>> {
- todo!()
- }
-
- fn poll_close(
- self: std::pin::Pin<&mut Self>,
- cx: &mut std::task::Context<'_>,
- ) -> std::task::Poll<std::result::Result<(), Self::Error>> {
- todo!()
- }
-}
-
#[cfg(test)]
mod tests {
use std::time::Duration;