xmpp-rs/examples/client.rs

33 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;
2017-02-20 15:28:51 +00:00
use xmpp::plugins::messaging::{MessagingPlugin, MessageEvent};
use xmpp::plugins::presence::{PresencePlugin, Show};
use xmpp::plugins::ping::{PingPlugin, PingEvent};
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();
2017-02-20 15:28:51 +00:00
client.register_plugin(MessagingPlugin::new());
client.register_plugin(PresencePlugin::new());
client.register_plugin(PingPlugin::new());
2017-02-20 15:28:51 +00:00
client.plugin::<PresencePlugin>().set_presence(Show::Available, None).unwrap();
loop {
let event = client.next_event().unwrap();
if let Some(evt) = event.downcast::<MessageEvent>() {
println!("{:?}", evt);
}
else if let Some(evt) = event.downcast::<PingEvent>() {
println!("{:?}", evt);
client.plugin::<PingPlugin>().reply_ping(evt);
}
2017-02-20 15:28:51 +00:00
}
2017-02-18 23:01:51 +00:00
}