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