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;
10use tokio_xmpp::{AsyncClient, AsyncServerConfig};
11pub use tokio_xmpp::{BareJid, Element, FullJid, Jid};
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
35type TokioXmppClient = AsyncClient<AsyncServerConfig>;
36
37pub type Error = tokio_xmpp::Error;
38pub type Id = Option<String>;
39pub type RoomNick = String;
40
41#[cfg(test)]
42mod tests {
43 use super::{Agent, BareJid, 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: 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}