diff options
Diffstat (limited to '')
-rw-r--r-- | lampada/Cargo.toml | 31 | ||||
-rw-r--r-- | lampada/src/error.rs | 6 | ||||
-rw-r--r-- | lampada/src/lib.rs | 14 |
3 files changed, 33 insertions, 18 deletions
diff --git a/lampada/Cargo.toml b/lampada/Cargo.toml index 090aa9f..1937162 100644 --- a/lampada/Cargo.toml +++ b/lampada/Cargo.toml @@ -3,19 +3,26 @@ name = "lampada" version = "0.1.0" edition = "2021" +[features] +serde = ["dep:serde"] + [dependencies] -futures = "0.3.31" -luz = { version = "0.1.0", path = "../luz" } -peanuts = { version = "0.1.0", git = "https://bunny.garden/peanuts" } -jid = { version = "0.1.0", path = "../jid" } -stanza = { version = "0.1.0", path = "../stanza", features = ["xep_0203"] } +futures = { workspace = true } +luz = { workspace = true } +peanuts = { workspace = true } +jid = { workspace = true } +stanza = { workspace = true, features = ["xep_0203"] } +tracing = { workspace = true } +thiserror = { workspace = true } +serde = { workspace = true, features = ["derive"], optional = true } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { workspace = true, features = ["macros", "sync"] } -tracing = "0.1.41" -thiserror = "2.0.11" [target.'cfg(target_arch = "wasm32")'.dependencies] -tokio = { workspace = true, features = ["macros", "rt", "time", "sync"] } -tokio_with_wasm = { version = "0.8.2", features = ["macros", "rt", "time", "sync"] } - -# [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -# tokio = { version = "1.42.0", features = ["rt-multi-thread"] } +tokio_with_wasm = { workspace = true, features = [ + "macros", + "rt", + "time", + "sync", +] } diff --git a/lampada/src/error.rs b/lampada/src/error.rs index 40be012..f29d0cc 100644 --- a/lampada/src/error.rs +++ b/lampada/src/error.rs @@ -1,10 +1,10 @@ use std::sync::Arc; -#[cfg(not(target_arch = "wasm32"))] -use ::tokio::time::error::Elapsed; use stanza::client::Stanza; use thiserror::Error; use tokio::sync::{mpsc::error::SendError, oneshot::error::RecvError}; +#[cfg(not(target_arch = "wasm32"))] +use tokio::time::error::Elapsed; #[cfg(target_arch = "wasm32")] use tokio::time::Elapsed; #[cfg(target_arch = "wasm32")] @@ -28,6 +28,7 @@ pub enum ConnectionError { } #[derive(Debug, Error, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub enum CommandError<T> { #[error("actor: {0}")] Actor(ActorError), @@ -61,6 +62,7 @@ pub enum ReadError { } #[derive(Debug, Error, Clone)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub enum ActorError { #[error("receive timed out")] Timeout, diff --git a/lampada/src/lib.rs b/lampada/src/lib.rs index dacc56d..6b6cbe8 100644 --- a/lampada/src/lib.rs +++ b/lampada/src/lib.rs @@ -217,9 +217,10 @@ where else => break, }; match msg { - CoreClientCommand::Connect => { + CoreClientCommand::Connect(sender) => { match self.connected { Some(_) => { + sender.send(Err(ConnectionError::AlreadyConnected)); self.logic .clone() .handle_connection_error(ConnectionError::AlreadyConnected) @@ -238,9 +239,10 @@ where self.logic .clone() .handle_connection_error(ConnectionError::InvalidServerJID( - e, + e.clone(), )) .await; + sender.send(Err(ConnectionError::InvalidServerJID(e))); continue; } }; @@ -260,6 +262,7 @@ where let shutdown_recv = shutdown_recv.fuse(); self.connection_supervisor_shutdown = shutdown_recv; + let resource = jid.resourcepart.clone().expect("client somehow connected without binding"); let connected = Connected { jid, write_handle: writer, @@ -269,15 +272,18 @@ where self.logic.clone().handle_connect(connected.clone()).await; self.connected = Some((connected, supervisor)); + // REMEMBER TO NOTIFY IT@S GOOD + sender.send(Ok(resource)); } Err(e) => { tracing::error!("error: {}", e); self.logic .clone() .handle_connection_error(ConnectionError::ConnectionFailed( - e.into(), + e.clone().into(), )) .await; + sender.send(Err(ConnectionError::ConnectionFailed(e))); } } } @@ -315,7 +321,7 @@ where pub enum CoreClientCommand<C> { // TODO: login invisible xep-0186 /// connect to XMPP chat server. gets roster and publishes initial presence. - Connect, + Connect(oneshot::Sender<Result<String, ConnectionError>>), /// disconnect from XMPP chat server, sending unavailable presence then closing stream. Disconnect, /// TODO: generics |