xmpp-rs/examples/client.rs

31 lines
1.1 KiB
Rust
Raw Normal View History

2017-02-18 23:01:51 +00:00
extern crate xmpp;
use xmpp::jid::Jid;
use xmpp::client::ClientBuilder;
use xmpp::plugins::stanza::StanzaPlugin;
2017-02-20 15:28:51 +00:00
use xmpp::plugins::messaging::{MessagingPlugin, MessageEvent};
use xmpp::plugins::presence::{PresencePlugin, Type};
use xmpp::plugins::ping::{PingPlugin, PingEvent};
2017-05-27 16:01:01 +00:00
use xmpp::event::{Priority, Propagation};
2017-02-18 23:01:51 +00:00
use std::env;
fn main() {
let jid: Jid = env::var("JID").unwrap().parse().unwrap();
let pass = env::var("PASS").unwrap();
let mut client = ClientBuilder::new(jid.clone())
.password(pass)
.connect()
.unwrap();
client.register_plugin(StanzaPlugin::new());
2017-02-20 15:28:51 +00:00
client.register_plugin(MessagingPlugin::new());
client.register_plugin(PresencePlugin::new());
client.register_plugin(PingPlugin::new());
2017-05-27 16:01:01 +00:00
client.register_handler(Priority::Max, |e: &MessageEvent| {
println!("{:?}", e);
Propagation::Continue
});
client.plugin::<PresencePlugin>().set_presence(Type::Available, None, None).unwrap();
client.main().unwrap();
2017-02-18 23:01:51 +00:00
}