aboutsummaryrefslogtreecommitdiffstats
path: root/filamento/src/lib.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-04-17 11:03:51 +0100
committerLibravatar cel 🌸 <cel@bunny.garden>2025-04-17 11:03:51 +0100
commitb9d75f38743113c054be3d97af36bdd2a7dd0d69 (patch)
tree537623664010d26d5f2574e2d51d03f8c25e08ac /filamento/src/lib.rs
parentcf51dcf052af89f8742d887bde2c93d735309bdd (diff)
downloadluz-b9d75f38743113c054be3d97af36bdd2a7dd0d69.tar.gz
luz-b9d75f38743113c054be3d97af36bdd2a7dd0d69.tar.bz2
luz-b9d75f38743113c054be3d97af36bdd2a7dd0d69.zip
feat(filamento): compiles on wasm
Diffstat (limited to '')
-rw-r--r--filamento/src/lib.rs93
1 files changed, 93 insertions, 0 deletions
diff --git a/filamento/src/lib.rs b/filamento/src/lib.rs
index 14b0cae..e06f7c6 100644
--- a/filamento/src/lib.rs
+++ b/filamento/src/lib.rs
@@ -32,6 +32,8 @@ use tokio::{
sync::{Mutex, mpsc, oneshot},
time::timeout,
};
+#[cfg(target_arch = "wasm32")]
+use tokio_with_wasm::alias as tokio;
use tracing::{debug, info};
use user::User;
use uuid::Uuid;
@@ -258,6 +260,7 @@ impl<Fs: FileStore + Clone + Send + Sync + 'static> Client<Fs> {
let actor: CoreClient<ClientLogic<Fs>> =
CoreClient::new(jid, password, command_receiver, None, sup_recv, logic);
+
tokio::spawn(async move { actor.run().await });
(client, update_recv)
@@ -728,3 +731,93 @@ impl<Fs: FileStore> From<Command<Fs>> for CoreClientCommand<Command<Fs>> {
CoreClientCommand::Command(value)
}
}
+
+#[cfg(test)]
+mod tests {
+ use wasm_bindgen_test::*;
+
+ use super::*;
+
+ wasm_bindgen_test_configure!(run_in_browser);
+
+ use crate::chat;
+ use crate::files::FilesMem;
+ use std::path::Path;
+ use tokio_with_wasm::alias as tokio;
+
+ #[wasm_bindgen_test]
+ async fn login() -> () {
+ tracing_wasm::set_as_global_default();
+ let db = Db::create_connect_and_migrate(Path::new("./filamento.db"))
+ .await
+ .unwrap();
+ let (client, mut recv) = Client::new(
+ "test@blos.sm/testing2".try_into().unwrap(),
+ "slayed".to_string(),
+ db,
+ FilesMem::new(),
+ );
+
+ tokio::spawn(async move {
+ while let Some(msg) = recv.recv().await {
+ info!("{:#?}", msg)
+ }
+ });
+
+ client.connect().await.unwrap();
+ // tokio::time::sleep(Duration::from_secs(5)).await;
+ info!("changing nick");
+ client
+ .change_nick(Some("britney".to_string()))
+ .await
+ .unwrap();
+ let mut data = include_bytes!("../files/britney_starbies.jpg");
+ client.change_avatar(Some(data.to_vec())).await.unwrap();
+ info!("sending message");
+ client
+ .send_message(
+ JID::from_str("cel@blos.sm").unwrap(),
+ chat::Body {
+ body: "hallo!!!".to_string(),
+ },
+ )
+ .await
+ .unwrap();
+ info!("sent message");
+ client
+ .send_message(
+ JID::from_str("cel@blos.sm").unwrap(),
+ chat::Body {
+ body: "hallo 2".to_string(),
+ },
+ )
+ .await
+ .unwrap();
+ // tokio::time::sleep(Duration::from_secs(15)).await;
+ // info!("sending disco query");
+ // let info = client.disco_info(None, None).await.unwrap();
+ // info!("got disco result: {:#?}", info);
+ // let items = client.disco_items(None, None).await.unwrap();
+ // info!("got disco result: {:#?}", items);
+ // let info = client
+ // .disco_info(Some("blos.sm".parse().unwrap()), None)
+ // .await
+ // .unwrap();
+ // info!("got disco result: {:#?}", info);
+ // let items = client
+ // .disco_items(Some("blos.sm".parse().unwrap()), None)
+ // .await
+ // .unwrap();
+ // info!("got disco result: {:#?}", items);
+ // let info = client
+ // .disco_info(Some("pubsub.blos.sm".parse().unwrap()), None)
+ // .await
+ // .unwrap();
+ // info!("got disco result: {:#?}", info);
+ // let items = client
+ // .disco_items(Some("pubsub.blos.sm".parse().unwrap()), None)
+ // .await
+ // .unwrap();
+ // info!("got disco result: {:#?}", items); let mut jid: JID = "test@blos.sm".try_into().unwrap();
+ }
+}