From 86b5f72d2f2ac38a21deb194bdd2f6fe017e4603 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 1 Apr 2017 17:15:56 +0100 Subject: [PATCH] add a component example --- examples/component.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 examples/component.rs diff --git a/examples/component.rs b/examples/component.rs new file mode 100644 index 0000000..3e04af9 --- /dev/null +++ b/examples/component.rs @@ -0,0 +1,27 @@ +extern crate xmpp; + +use xmpp::jid::Jid; +use xmpp::component::ComponentBuilder; +use xmpp::plugins::messaging::{MessagingPlugin, MessageEvent}; + +use std::env; + +fn main() { + let jid: Jid = env::var("JID").unwrap().parse().unwrap(); + let pass = env::var("PASS").unwrap(); + let host = env::var("HOST").unwrap(); + let port: u16 = env::var("PORT").unwrap().parse().unwrap(); + let mut component = ComponentBuilder::new(jid.clone()) + .password(pass) + .host(host) + .port(port) + .connect() + .unwrap(); + component.register_plugin(MessagingPlugin::new()); + loop { + let event = component.next_event().unwrap(); + if let Some(evt) = event.downcast::() { + println!("{:?}", evt); + } + } +}