fix stanza events
This commit is contained in:
parent
aece3798c1
commit
0a34c6c71f
2 changed files with 11 additions and 6 deletions
|
@ -105,6 +105,7 @@ impl Future for TcpClient {
|
||||||
mod tests {
|
mod tests {
|
||||||
use tokio_core::reactor::Core;
|
use tokio_core::reactor::Core;
|
||||||
use futures::{Future, Stream};
|
use futures::{Future, Stream};
|
||||||
|
use xmpp_codec::Packet;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn it_works() {
|
fn it_works() {
|
||||||
|
@ -118,8 +119,12 @@ mod tests {
|
||||||
&addr,
|
&addr,
|
||||||
&core.handle()
|
&core.handle()
|
||||||
).and_then(|stream| {
|
).and_then(|stream| {
|
||||||
stream.for_each(|item| {
|
stream.for_each(|event| {
|
||||||
Ok(println!("stream item: {:?}", item))
|
match event {
|
||||||
|
Packet::Stanza(el) => println!("<< {}", el),
|
||||||
|
_ => println!("!! {:?}", event),
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
core.run(client).unwrap();
|
core.run(client).unwrap();
|
||||||
|
|
|
@ -85,12 +85,12 @@ impl Codec for XMPPCodec {
|
||||||
let mut new_root = None;
|
let mut new_root = None;
|
||||||
let mut result = None;
|
let mut result = None;
|
||||||
for event in &mut self.parser {
|
for event in &mut self.parser {
|
||||||
match &mut self.root {
|
match self.root {
|
||||||
&mut None => {
|
None => {
|
||||||
// Expecting <stream:stream>
|
// Expecting <stream:stream>
|
||||||
match event {
|
match event {
|
||||||
Ok(xml::Event::ElementStart(start_tag)) => {
|
Ok(xml::Event::ElementStart(start_tag)) => {
|
||||||
new_root = Some(XMPPRoot::new(start_tag));
|
self.root = Some(XMPPRoot::new(start_tag));
|
||||||
result = Some(Packet::StreamStart);
|
result = Some(Packet::StreamStart);
|
||||||
break
|
break
|
||||||
},
|
},
|
||||||
|
@ -103,7 +103,7 @@ impl Codec for XMPPCodec {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&mut Some(ref mut root) => {
|
Some(ref mut root) => {
|
||||||
match root.handle_event(event) {
|
match root.handle_event(event) {
|
||||||
None => (),
|
None => (),
|
||||||
Some(Ok(stanza)) => {
|
Some(Ok(stanza)) => {
|
||||||
|
|
Loading…
Reference in a new issue