echo_bot: send presence

This commit is contained in:
Astro 2017-06-19 02:35:21 +02:00
parent 000f848dd0
commit 547902fe8f

View file

@ -2,13 +2,14 @@ extern crate futures;
extern crate tokio_core; extern crate tokio_core;
extern crate tokio_xmpp; extern crate tokio_xmpp;
extern crate jid; extern crate jid;
extern crate xml;
use std::str::FromStr; use std::str::FromStr;
use tokio_core::reactor::Core; use tokio_core::reactor::Core;
use futures::{Future, Stream}; use futures::{Future, Stream, Sink};
use jid::Jid;
use tokio_xmpp::TcpClient; use tokio_xmpp::TcpClient;
use tokio_xmpp::xmpp_codec::Packet; use tokio_xmpp::xmpp_codec::Packet;
use jid::Jid;
fn main() { fn main() {
let jid = Jid::from_str("astrobot@example.net").expect("JID"); let jid = Jid::from_str("astrobot@example.net").expect("JID");
@ -38,6 +39,11 @@ fn main() {
stream.bind() stream.bind()
}).and_then(|stream| { }).and_then(|stream| {
println!("Bound to {}", stream.jid); println!("Bound to {}", stream.jid);
let presence = xml::Element::new("presence".to_owned(), None, vec![]);
stream.send(Packet::Stanza(presence))
.map_err(|e| format!("{}", e))
}).and_then(|stream| {
stream.for_each(|event| { stream.for_each(|event| {
match event { match event {
Packet::Stanza(el) => println!("<< {}", el), Packet::Stanza(el) => println!("<< {}", el),