add a component example
This commit is contained in:
parent
caa83ce789
commit
86b5f72d2f
1 changed files with 27 additions and 0 deletions
27
examples/component.rs
Normal file
27
examples/component.rs
Normal file
|
|
@ -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::<MessageEvent>() {
|
||||||
|
println!("{:?}", evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue