xmpp-rs/examples/client.rs

28 lines
966 B
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::sasl::mechanisms::{Scram, Sha1};
2017-02-18 23:01:51 +00:00
use std::env;
fn main() {
let jid: Jid = env::var("JID").unwrap().parse().unwrap();
2017-02-24 16:16:51 +00:00
let mut client = ClientBuilder::new(jid.clone()).connect().unwrap();
2017-02-20 15:28:51 +00:00
client.register_plugin(MessagingPlugin::new());
client.register_plugin(PresencePlugin::new());
2017-02-24 16:16:51 +00:00
let pass = env::var("PASS").unwrap();
2017-02-24 22:42:08 +00:00
let name = jid.node.clone().expect("JID requires a node");
client.connect(&mut Scram::<Sha1>::new(name, pass).unwrap()).unwrap();
2017-02-24 22:53:54 +00:00
client.bind().unwrap();
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);
}
}
2017-02-18 23:01:51 +00:00
}