unify Client::Event and Component::Event into Event
This commit is contained in:
parent
c0f3fc4afb
commit
993fdcab8f
5 changed files with 14 additions and 52 deletions
|
@ -15,13 +15,12 @@ use super::xmpp_codec::Packet;
|
|||
use super::xmpp_stream;
|
||||
use super::starttls::{NS_XMPP_TLS, StartTlsClient};
|
||||
use super::happy_eyeballs::Connecter;
|
||||
use super::event::Event;
|
||||
|
||||
mod auth;
|
||||
use self::auth::ClientAuth;
|
||||
mod bind;
|
||||
use self::bind::ClientBind;
|
||||
mod event;
|
||||
pub use self::event::Event as ClientEvent;
|
||||
|
||||
pub struct Client {
|
||||
pub jid: Jid,
|
||||
|
@ -112,7 +111,7 @@ impl Client {
|
|||
}
|
||||
|
||||
impl Stream for Client {
|
||||
type Item = ClientEvent;
|
||||
type Item = Event;
|
||||
type Error = String;
|
||||
|
||||
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
||||
|
@ -127,7 +126,7 @@ impl Stream for Client {
|
|||
match connect.poll() {
|
||||
Ok(Async::Ready(stream)) => {
|
||||
self.state = ClientState::Connected(stream);
|
||||
Ok(Async::Ready(Some(ClientEvent::Online)))
|
||||
Ok(Async::Ready(Some(Event::Online)))
|
||||
},
|
||||
Ok(Async::NotReady) => {
|
||||
self.state = ClientState::Connecting(connect);
|
||||
|
@ -142,11 +141,11 @@ impl Stream for Client {
|
|||
Ok(Async::Ready(None)) => {
|
||||
// EOF
|
||||
self.state = ClientState::Disconnected;
|
||||
Ok(Async::Ready(Some(ClientEvent::Disconnected)))
|
||||
Ok(Async::Ready(Some(Event::Disconnected)))
|
||||
},
|
||||
Ok(Async::Ready(Some(Packet::Stanza(stanza)))) => {
|
||||
self.state = ClientState::Connected(stream);
|
||||
Ok(Async::Ready(Some(ClientEvent::Stanza(stanza))))
|
||||
Ok(Async::Ready(Some(Event::Stanza(stanza))))
|
||||
},
|
||||
Ok(Async::NotReady) |
|
||||
Ok(Async::Ready(_)) => {
|
||||
|
|
|
@ -1,38 +0,0 @@
|
|||
use minidom::Element;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Event {
|
||||
Online,
|
||||
Disconnected,
|
||||
Stanza(Element),
|
||||
}
|
||||
|
||||
impl Event {
|
||||
pub fn is_online(&self) -> bool {
|
||||
match *self {
|
||||
Event::Online => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_stanza(&self, name: &str) -> bool {
|
||||
match *self {
|
||||
Event::Stanza(ref stanza) => stanza.name() == name,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn as_stanza(&self) -> Option<&Element> {
|
||||
match *self {
|
||||
Event::Stanza(ref stanza) => Some(stanza),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_stanza(self) -> Option<Element> {
|
||||
match self {
|
||||
Event::Stanza(stanza) => Some(stanza),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,11 +11,10 @@ use jid::{Jid, JidParseError};
|
|||
use super::xmpp_codec::Packet;
|
||||
use super::xmpp_stream;
|
||||
use super::happy_eyeballs::Connecter;
|
||||
use super::event::Event;
|
||||
|
||||
mod auth;
|
||||
use self::auth::ComponentAuth;
|
||||
mod event;
|
||||
pub use self::event::Event as ComponentEvent;
|
||||
|
||||
pub struct Component {
|
||||
pub jid: Jid,
|
||||
|
@ -67,7 +66,7 @@ impl Component {
|
|||
}
|
||||
|
||||
impl Stream for Component {
|
||||
type Item = ComponentEvent;
|
||||
type Item = Event;
|
||||
type Error = String;
|
||||
|
||||
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
|
||||
|
@ -82,7 +81,7 @@ impl Stream for Component {
|
|||
match connect.poll() {
|
||||
Ok(Async::Ready(stream)) => {
|
||||
self.state = ComponentState::Connected(stream);
|
||||
Ok(Async::Ready(Some(ComponentEvent::Online)))
|
||||
Ok(Async::Ready(Some(Event::Online)))
|
||||
},
|
||||
Ok(Async::NotReady) => {
|
||||
self.state = ComponentState::Connecting(connect);
|
||||
|
@ -101,11 +100,11 @@ impl Stream for Component {
|
|||
Ok(Async::Ready(None)) => {
|
||||
// EOF
|
||||
self.state = ComponentState::Disconnected;
|
||||
Ok(Async::Ready(Some(ComponentEvent::Disconnected)))
|
||||
Ok(Async::Ready(Some(Event::Disconnected)))
|
||||
},
|
||||
Ok(Async::Ready(Some(Packet::Stanza(stanza)))) => {
|
||||
self.state = ComponentState::Connected(stream);
|
||||
Ok(Async::Ready(Some(ComponentEvent::Stanza(stanza))))
|
||||
Ok(Async::Ready(Some(Event::Stanza(stanza))))
|
||||
},
|
||||
Ok(Async::Ready(_)) => {
|
||||
self.state = ComponentState::Connected(stream);
|
||||
|
|
|
@ -20,7 +20,9 @@ mod stream_start;
|
|||
mod starttls;
|
||||
pub use starttls::StartTlsClient;
|
||||
mod happy_eyeballs;
|
||||
mod event;
|
||||
pub use event::Event;
|
||||
mod client;
|
||||
pub use client::{Client, ClientEvent};
|
||||
pub use client::Client;
|
||||
mod component;
|
||||
pub use component::{Component, ComponentEvent};
|
||||
pub use component::Component;
|
||||
|
|
Loading…
Reference in a new issue