2019-03-21 17:41:29 +00:00
|
|
|
// Copyright (c) 2019 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
|
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
2019-07-25 13:03:22 +00:00
|
|
|
#![deny(bare_trait_objects)]
|
2024-08-04 20:35:01 +00:00
|
|
|
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
|
2019-07-25 13:03:22 +00:00
|
|
|
|
2024-07-31 12:28:15 +00:00
|
|
|
pub use tokio_xmpp;
|
2024-07-24 18:52:10 +00:00
|
|
|
pub use tokio_xmpp::jid;
|
|
|
|
pub use tokio_xmpp::minidom;
|
2023-08-21 08:57:33 +00:00
|
|
|
pub use tokio_xmpp::parsers;
|
2019-09-29 02:08:56 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2019-03-21 17:41:29 +00:00
|
|
|
|
2023-12-29 23:43:10 +00:00
|
|
|
pub mod agent;
|
2023-12-29 19:58:26 +00:00
|
|
|
pub mod builder;
|
2023-12-31 20:06:15 +00:00
|
|
|
pub mod delay;
|
2023-12-29 21:07:46 +00:00
|
|
|
pub mod disco;
|
2023-12-29 20:56:37 +00:00
|
|
|
pub mod event;
|
2023-12-29 23:13:25 +00:00
|
|
|
pub mod event_loop;
|
2023-12-29 20:41:09 +00:00
|
|
|
pub mod feature;
|
2023-12-29 17:18:38 +00:00
|
|
|
pub mod iq;
|
2023-12-29 17:08:04 +00:00
|
|
|
pub mod message;
|
2023-12-29 23:28:57 +00:00
|
|
|
pub mod muc;
|
2023-12-29 17:08:04 +00:00
|
|
|
pub mod presence;
|
|
|
|
pub mod pubsub;
|
2023-12-29 17:29:22 +00:00
|
|
|
pub mod upload;
|
2019-03-21 17:41:29 +00:00
|
|
|
|
2023-12-29 19:58:26 +00:00
|
|
|
// Module re-exports
|
2023-12-29 23:43:10 +00:00
|
|
|
pub use agent::Agent;
|
2023-12-29 19:58:26 +00:00
|
|
|
pub use builder::{ClientBuilder, ClientType};
|
2023-12-29 20:56:37 +00:00
|
|
|
pub use event::Event;
|
2023-12-29 20:41:09 +00:00
|
|
|
pub use feature::ClientFeature;
|
2019-03-21 17:41:29 +00:00
|
|
|
|
2023-12-29 19:58:26 +00:00
|
|
|
pub type Error = tokio_xmpp::Error;
|
|
|
|
pub type Id = Option<String>;
|
|
|
|
pub type RoomNick = String;
|
2019-03-21 17:41:29 +00:00
|
|
|
|
2024-01-04 01:01:05 +00:00
|
|
|
#[cfg(all(test, any(feature = "starttls-rust", feature = "starttls-native")))]
|
2019-10-22 21:46:50 +00:00
|
|
|
mod tests {
|
2024-07-24 18:52:10 +00:00
|
|
|
use super::jid::BareJid;
|
|
|
|
use super::{ClientBuilder, ClientFeature, ClientType, Event};
|
2023-06-01 09:58:04 +00:00
|
|
|
use std::str::FromStr;
|
2024-08-06 19:00:11 +00:00
|
|
|
use tokio_xmpp::Client as TokioXmppClient;
|
2019-10-22 21:46:50 +00:00
|
|
|
|
2020-03-08 18:57:59 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn test_simple() {
|
2023-06-01 09:58:04 +00:00
|
|
|
let jid = BareJid::from_str("foo@bar").unwrap();
|
|
|
|
|
|
|
|
let client = TokioXmppClient::new(jid.clone(), "meh");
|
2019-10-22 21:46:50 +00:00
|
|
|
|
|
|
|
// Client instance
|
2023-06-01 09:58:04 +00:00
|
|
|
let client_builder = ClientBuilder::new(jid, "meh")
|
2019-10-22 21:46:50 +00:00
|
|
|
.set_client(ClientType::Bot, "xmpp-rs")
|
|
|
|
.set_website("https://gitlab.com/xmpp-rs/xmpp-rs")
|
|
|
|
.set_default_nick("bot")
|
|
|
|
.enable_feature(ClientFeature::ContactList);
|
|
|
|
|
2023-08-17 20:29:04 +00:00
|
|
|
#[cfg(feature = "avatars")]
|
|
|
|
let client_builder = client_builder.enable_feature(ClientFeature::Avatars);
|
|
|
|
|
2023-12-31 06:17:29 +00:00
|
|
|
let mut agent = client_builder.build_impl(client);
|
2019-10-22 21:46:50 +00:00
|
|
|
|
2024-08-08 13:14:57 +00:00
|
|
|
loop {
|
|
|
|
let events = agent.wait_for_events().await;
|
2020-03-08 18:57:59 +00:00
|
|
|
assert!(match events[0] {
|
2023-12-11 12:48:39 +00:00
|
|
|
Event::Disconnected(_) => true,
|
2020-03-08 18:57:59 +00:00
|
|
|
_ => false,
|
|
|
|
});
|
|
|
|
assert_eq!(events.len(), 1);
|
|
|
|
break;
|
|
|
|
}
|
2019-10-22 21:46:50 +00:00
|
|
|
}
|
|
|
|
}
|