1// Copyright (c) 2019 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#![deny(bare_trait_objects)]
8
9pub use tokio_xmpp::parsers;
10pub use tokio_xmpp::{BareJid, Element, FullJid, Jid};
11#[macro_use]
12extern crate log;
13
14pub mod agent;
15pub mod builder;
16pub mod delay;
17pub mod disco;
18pub mod event;
19pub mod event_loop;
20pub mod feature;
21pub mod iq;
22pub mod message;
23pub mod muc;
24pub mod presence;
25pub mod pubsub;
26pub mod upload;
27
28// Module re-exports
29pub use agent::Agent;
30pub use builder::{ClientBuilder, ClientType};
31pub use event::Event;
32pub use feature::ClientFeature;
33
34pub type Error = tokio_xmpp::Error;
35pub type Id = Option<String>;
36pub type RoomNick = String;
37
38#[cfg(all(test, any(feature = "starttls-rust", feature = "starttls-native")))]
39mod tests {
40 use super::{BareJid, ClientBuilder, ClientFeature, ClientType, Event};
41 use std::str::FromStr;
42 use tokio_xmpp::AsyncClient as TokioXmppClient;
43
44 #[tokio::test]
45 async fn test_simple() {
46 let jid = BareJid::from_str("foo@bar").unwrap();
47
48 let client = TokioXmppClient::new(jid.clone(), "meh");
49
50 // Client instance
51 let client_builder = ClientBuilder::new(jid, "meh")
52 .set_client(ClientType::Bot, "xmpp-rs")
53 .set_website("https://gitlab.com/xmpp-rs/xmpp-rs")
54 .set_default_nick("bot")
55 .enable_feature(ClientFeature::ContactList);
56
57 #[cfg(feature = "avatars")]
58 let client_builder = client_builder.enable_feature(ClientFeature::Avatars);
59
60 let mut agent = client_builder.build_impl(client);
61
62 while let Some(events) = agent.wait_for_events().await {
63 assert!(match events[0] {
64 Event::Disconnected(_) => true,
65 _ => false,
66 });
67 assert_eq!(events.len(), 1);
68 break;
69 }
70 }
71}