add a ping plugin
This is a demo of the simplest iq-based protocol. When an iq is received containing a payload qualified by this namespace, an empty result iq is sent.
This commit is contained in:
parent
9d57e1a63b
commit
40d01a729f
4 changed files with 73 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ use xmpp::jid::Jid;
|
|||
use xmpp::client::ClientBuilder;
|
||||
use xmpp::plugins::messaging::{MessagingPlugin, MessageEvent};
|
||||
use xmpp::plugins::presence::{PresencePlugin, Show};
|
||||
use xmpp::plugins::ping::{PingPlugin, PingEvent};
|
||||
|
||||
use std::env;
|
||||
|
||||
|
|
@ -16,11 +17,16 @@ fn main() {
|
|||
.unwrap();
|
||||
client.register_plugin(MessagingPlugin::new());
|
||||
client.register_plugin(PresencePlugin::new());
|
||||
client.register_plugin(PingPlugin::new());
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue