2019-03-21 17:41:29 +00:00
|
|
|
// Copyright (c) 2019 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2019-07-25 13:03:22 +00:00
|
|
|
#![deny(bare_trait_objects)]
|
|
|
|
|
2023-08-21 08:57:33 +00:00
|
|
|
pub use tokio_xmpp::parsers;
|
|
|
|
pub use tokio_xmpp::{BareJid, Element, FullJid, Jid};
|
2019-09-29 02:08:56 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2019-03-21 17:41:29 +00:00
|
|
|
|
2023-12-29 23:43:10 +00:00
|
|
|
pub mod agent;
|
2023-12-29 19:58:26 +00:00
|
|
|
pub mod builder;
|
2023-12-31 20:06:15 +00:00
|
|
|
pub mod delay;
|
2023-12-29 21:07:46 +00:00
|
|
|
pub mod disco;
|
2023-12-29 20:56:37 +00:00
|
|
|
pub mod event;
|
2023-12-29 23:13:25 +00:00
|
|
|
pub mod event_loop;
|
2023-12-29 20:41:09 +00:00
|
|
|
pub mod feature;
|
2023-12-29 17:18:38 +00:00
|
|
|
pub mod iq;
|
2023-12-29 17:08:04 +00:00
|
|
|
pub mod message;
|
2023-12-29 23:28:57 +00:00
|
|
|
pub mod muc;
|
2023-12-29 17:08:04 +00:00
|
|
|
pub mod presence;
|
|
|
|
pub mod pubsub;
|
2023-12-29 17:29:22 +00:00
|
|
|
pub mod upload;
|
2019-03-21 17:41:29 +00:00
|
|
|
|
2023-12-29 19:58:26 +00:00
|
|
|
// Module re-exports
|
2023-12-29 23:43:10 +00:00
|
|
|
pub use agent::Agent;
|
2023-12-29 19:58:26 +00:00
|
|
|
pub use builder::{ClientBuilder, ClientType};
|
2023-12-29 20:56:37 +00:00
|
|
|
pub use event::Event;
|
2023-12-29 20:41:09 +00:00
|
|
|
pub use feature::ClientFeature;
|
2019-03-21 17:41:29 +00:00
|
|
|
|
2023-12-29 19:58:26 +00:00
|
|
|
pub type Error = tokio_xmpp::Error;
|
|
|
|
pub type Id = Option<String>;
|
|
|
|
pub type RoomNick = String;
|
2019-03-21 17:41:29 +00:00
|
|
|
|
2019-10-22 21:46:50 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2023-06-01 09:58:04 +00:00
|
|
|
use super::{Agent, BareJid, ClientBuilder, ClientFeature, ClientType, Event};
|
|
|
|
use std::str::FromStr;
|
2020-05-29 22:24:58 +00:00
|
|
|
use tokio_xmpp::AsyncClient as TokioXmppClient;
|
2019-10-22 21:46:50 +00:00
|
|
|
|
2020-03-08 18:57:59 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn test_simple() {
|
2023-06-01 09:58:04 +00:00
|
|
|
let jid = BareJid::from_str("foo@bar").unwrap();
|
|
|
|
|
|
|
|
let client = TokioXmppClient::new(jid.clone(), "meh");
|
2019-10-22 21:46:50 +00:00
|
|
|
|
|
|
|
// Client instance
|
2023-06-01 09:58:04 +00:00
|
|
|
let client_builder = ClientBuilder::new(jid, "meh")
|
2019-10-22 21:46:50 +00:00
|
|
|
.set_client(ClientType::Bot, "xmpp-rs")
|
|
|
|
.set_website("https://gitlab.com/xmpp-rs/xmpp-rs")
|
|
|
|
.set_default_nick("bot")
|
|
|
|
.enable_feature(ClientFeature::ContactList);
|
|
|
|
|
2023-08-17 20:29:04 +00:00
|
|
|
#[cfg(feature = "avatars")]
|
|
|
|
let client_builder = client_builder.enable_feature(ClientFeature::Avatars);
|
|
|
|
|
2023-06-01 09:58:04 +00:00
|
|
|
let mut agent: Agent = client_builder.build_impl(client);
|
2019-10-22 21:46:50 +00:00
|
|
|
|
2020-03-08 18:57:59 +00:00
|
|
|
while let Some(events) = agent.wait_for_events().await {
|
|
|
|
assert!(match events[0] {
|
2023-12-11 12:48:39 +00:00
|
|
|
Event::Disconnected(_) => true,
|
2020-03-08 18:57:59 +00:00
|
|
|
_ => false,
|
|
|
|
});
|
|
|
|
assert_eq!(events.len(), 1);
|
|
|
|
break;
|
|
|
|
}
|
2019-10-22 21:46:50 +00:00
|
|
|
}
|
|
|
|
}
|