mirror of
https://gitlab.com/xmpp-rs/xmpp-rs.git
synced 2024-07-12 22:21:53 +00:00
add XMPPStream.send_stanza() convenience method
This commit is contained in:
parent
06b97ea228
commit
71e2b1c84f
4 changed files with 14 additions and 8 deletions
|
@ -76,7 +76,7 @@ impl<S: AsyncWrite> ClientAuth<S> {
|
|||
.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);
|
||||
}
|
||||
|
|
|
@ -32,10 +32,8 @@ impl<S: AsyncWrite> ClientBind<S> {
|
|||
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)
|
||||
},
|
||||
}
|
||||
|
|
|
@ -34,8 +34,8 @@ impl<S: AsyncWrite> ComponentAuth<S> {
|
|||
}
|
||||
|
||||
fn send(&mut self, stream: XMPPStream<S>, 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);
|
||||
}
|
||||
|
|
|
@ -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<S: AsyncRead + AsyncWrite> XMPPStream<S> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S: AsyncWrite> XMPPStream<S> {
|
||||
/// Convenience method
|
||||
pub fn send_stanza<E: Into<Element>>(self, e: E) -> Send<Self> {
|
||||
self.send(Packet::Stanza(e.into()))
|
||||
}
|
||||
}
|
||||
|
||||
/// Proxy to self.stream
|
||||
impl<S: AsyncWrite> Sink for XMPPStream<S> {
|
||||
type SinkItem = <Framed<S, XMPPCodec> as Sink>::SinkItem;
|
||||
|
|
Loading…
Reference in a new issue