diff --git a/src/client/auth.rs b/src/client/auth.rs index ef828b37..36f66059 100644 --- a/src/client/auth.rs +++ b/src/client/auth.rs @@ -76,7 +76,7 @@ impl ClientAuth { .append(content.to_base64(base64::STANDARD)) .build(); - let send = stream.send(Packet::Stanza(nonza)); + let send = stream.send_stanza(nonza); self.state = ClientAuthState::WaitSend(send); } diff --git a/src/client/bind.rs b/src/client/bind.rs index d258f7b7..348fc307 100644 --- a/src/client/bind.rs +++ b/src/client/bind.rs @@ -32,10 +32,8 @@ impl ClientBind { ClientBind::Unsupported(stream), Some(_) => { let resource = stream.jid.resource.clone(); - let iq = Element::from( - Bind::new(resource) - ); - let send = stream.send(Packet::Stanza(iq)); + let iq = Bind::new(resource); + let send = stream.send_stanza(iq); ClientBind::WaitSend(send) }, } diff --git a/src/component/auth.rs b/src/component/auth.rs index 2149da8f..d53cc67b 100644 --- a/src/component/auth.rs +++ b/src/component/auth.rs @@ -34,8 +34,8 @@ impl ComponentAuth { } fn send(&mut self, stream: XMPPStream, handshake: Handshake) { - let nonza = Element::from(handshake); - let send = stream.send(Packet::Stanza(nonza)); + let nonza = handshake; + let send = stream.send_stanza(nonza); self.state = ComponentAuthState::WaitSend(send); } diff --git a/src/xmpp_stream.rs b/src/xmpp_stream.rs index 29f7d2e7..e5ba9fcb 100644 --- a/src/xmpp_stream.rs +++ b/src/xmpp_stream.rs @@ -1,10 +1,11 @@ use futures::{Poll, Stream, Sink, StartSend}; +use futures::sink::Send; use tokio_io::{AsyncRead, AsyncWrite}; use tokio_codec::Framed; use minidom::Element; use jid::Jid; -use xmpp_codec::XMPPCodec; +use xmpp_codec::{XMPPCodec, Packet}; use stream_start::StreamStart; pub const NS_XMPP_STREAM: &str = "http://etherx.jabber.org/streams"; @@ -38,6 +39,13 @@ impl XMPPStream { } } +impl XMPPStream { + /// Convenience method + pub fn send_stanza>(self, e: E) -> Send { + self.send(Packet::Stanza(e.into())) + } +} + /// Proxy to self.stream impl Sink for XMPPStream { type SinkItem = as Sink>::SinkItem;