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