lib.rs

 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::jid;
10pub use tokio_xmpp::minidom;
11pub use tokio_xmpp::parsers;
12#[macro_use]
13extern crate log;
14
15pub mod agent;
16pub mod builder;
17pub mod delay;
18pub mod disco;
19pub mod event;
20pub mod event_loop;
21pub mod feature;
22pub mod iq;
23pub mod message;
24pub mod muc;
25pub mod presence;
26pub mod pubsub;
27pub mod upload;
28
29// Module re-exports
30pub use agent::Agent;
31pub use builder::{ClientBuilder, ClientType};
32pub use event::Event;
33pub use feature::ClientFeature;
34
35pub type Error = tokio_xmpp::Error;
36pub type Id = Option<String>;
37pub type RoomNick = String;
38
39#[cfg(all(test, any(feature = "starttls-rust", feature = "starttls-native")))]
40mod tests {
41    use super::jid::BareJid;
42    use super::{ClientBuilder, ClientFeature, ClientType, Event};
43    use std::str::FromStr;
44    use tokio_xmpp::AsyncClient as TokioXmppClient;
45
46    #[tokio::test]
47    async fn test_simple() {
48        let jid = BareJid::from_str("foo@bar").unwrap();
49
50        let client = TokioXmppClient::new(jid.clone(), "meh");
51
52        // Client instance
53        let client_builder = ClientBuilder::new(jid, "meh")
54            .set_client(ClientType::Bot, "xmpp-rs")
55            .set_website("https://gitlab.com/xmpp-rs/xmpp-rs")
56            .set_default_nick("bot")
57            .enable_feature(ClientFeature::ContactList);
58
59        #[cfg(feature = "avatars")]
60        let client_builder = client_builder.enable_feature(ClientFeature::Avatars);
61
62        let mut agent = client_builder.build_impl(client);
63
64        while let Some(events) = agent.wait_for_events().await {
65            assert!(match events[0] {
66                Event::Disconnected(_) => true,
67                _ => false,
68            });
69            assert_eq!(events.len(), 1);
70            break;
71        }
72    }
73}