diff --git a/examples/client.rs b/examples/client.rs index cf6692d6..16fe4db8 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -27,6 +27,7 @@ fn main() { client.register_plugin(DiscoPlugin::new("client", "bot", "en", "xmpp-rs")); client.register_plugin(IbbPlugin::new()); client.register_plugin(PingPlugin::new()); + client.plugin::().init(); client.register_handler(Priority::Max, |e: &MessageEvent| { println!("{:?}", e); Propagation::Continue diff --git a/src/plugins/ping.rs b/src/plugins/ping.rs index 7c3fe777..dbf21fda 100644 --- a/src/plugins/ping.rs +++ b/src/plugins/ping.rs @@ -6,8 +6,10 @@ use error::Error; use jid::Jid; use plugins::stanza::Iq; +use plugins::disco::DiscoPlugin; use xmpp_parsers::iq::{IqType, IqPayload}; use xmpp_parsers::ping::Ping; +use xmpp_parsers::ns; #[derive(Debug)] pub struct PingEvent { @@ -28,6 +30,24 @@ impl PingPlugin { } } + // TODO: make that called automatically after plugins are created. + pub fn init(&self) { + if let Some(disco) = self.proxy.plugin::() { + disco.add_feature(ns::PING); + } else { + panic!("Please handle dependencies in the correct order."); + } + } + + // TODO: make that called automatically before removal. + pub fn deinit(&self) { + if let Some(disco) = self.proxy.plugin::() { + disco.remove_feature(ns::PING); + } else { + panic!("Please handle dependencies in the correct order."); + } + } + pub fn send_ping(&self, to: &Jid) -> Result<(), Error> { let to = to.clone(); self.proxy.send(Iq {