xmpp-rs/xmpp/src/lib.rs

71 lines
1.9 KiB
Rust
Raw Normal View History

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/.
#![deny(bare_trait_objects)]
pub use tokio_xmpp::parsers;
pub use tokio_xmpp::{BareJid, Element, FullJid, Jid};
#[macro_use]
extern crate log;
2019-03-21 17:41:29 +00:00
2023-12-29 23:43:10 +00:00
pub mod agent;
pub mod builder;
pub mod disco;
2023-12-29 20:56:37 +00:00
pub mod event;
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;
pub mod muc;
2023-12-29 17:08:04 +00:00
pub mod presence;
pub mod pubsub;
pub mod upload;
2019-03-21 17:41:29 +00:00
// Module re-exports
2023-12-29 23:43:10 +00:00
pub use agent::Agent;
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
pub type Error = tokio_xmpp::Error;
pub type Id = Option<String>;
pub type RoomNick = String;
2019-03-21 17:41:29 +00:00
#[cfg(test)]
mod tests {
use super::{Agent, BareJid, ClientBuilder, ClientFeature, ClientType, Event};
use std::str::FromStr;
2020-05-29 22:24:58 +00:00
use tokio_xmpp::AsyncClient as TokioXmppClient;
#[tokio::test]
async fn test_simple() {
let jid = BareJid::from_str("foo@bar").unwrap();
let client = TokioXmppClient::new(jid.clone(), "meh");
// Client instance
let client_builder = ClientBuilder::new(jid, "meh")
.set_client(ClientType::Bot, "xmpp-rs")
.set_website("https://gitlab.com/xmpp-rs/xmpp-rs")
.set_default_nick("bot")
.enable_feature(ClientFeature::ContactList);
#[cfg(feature = "avatars")]
let client_builder = client_builder.enable_feature(ClientFeature::Avatars);
let mut agent: Agent = client_builder.build_impl(client);
while let Some(events) = agent.wait_for_events().await {
assert!(match events[0] {
Event::Disconnected(_) => true,
_ => false,
});
assert_eq!(events.len(), 1);
break;
}
}
}