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