aboutsummaryrefslogtreecommitdiffstats
path: root/lampada/src/connection/read.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-04-13 16:45:53 +0100
committerLibravatar cel 🌸 <cel@bunny.garden>2025-04-13 16:45:53 +0100
commitcf51dcf052af89f8742d887bde2c93d735309bdd (patch)
treefb7d8b7a313511de845db6cfd186f3b87c472154 /lampada/src/connection/read.rs
parent603777c5f4b3f8248378af6fe5af65b54e0f120e (diff)
downloadluz-cf51dcf052af89f8742d887bde2c93d735309bdd.tar.gz
luz-cf51dcf052af89f8742d887bde2c93d735309bdd.tar.bz2
luz-cf51dcf052af89f8742d887bde2c93d735309bdd.zip
feat(lampada): wasm + websockets support
Diffstat (limited to 'lampada/src/connection/read.rs')
-rw-r--r--lampada/src/connection/read.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/lampada/src/connection/read.rs b/lampada/src/connection/read.rs
index 2c7eb58..4451d99 100644
--- a/lampada/src/connection/read.rs
+++ b/lampada/src/connection/read.rs
@@ -8,7 +8,7 @@ use std::{
};
use futures::{future::Fuse, FutureExt};
-use luz::{connection::Tls, jabber_stream::bound_stream::BoundJabberReader};
+use luz::jabber_stream::bound_stream::BoundJabberReader;
use stanza::client::Stanza;
use stanza::stream::Error as StreamErrorStanza;
use stanza::stream_error::Error as StreamError;
@@ -24,7 +24,7 @@ use super::{write::WriteHandle, SupervisorCommand, SupervisorSender};
/// read actor
pub struct Read<Lgc> {
- stream: BoundJabberReader<Tls>,
+ stream: BoundJabberReader,
disconnecting: bool,
disconnect_timedout: Fuse<oneshot::Receiver<()>>,
@@ -51,7 +51,7 @@ pub struct ReadState {
impl<Lgc> Read<Lgc> {
fn new(
- stream: BoundJabberReader<Tls>,
+ stream: BoundJabberReader,
tasks: JoinSet<()>,
connected: Connected,
logic: Lgc,
@@ -129,7 +129,7 @@ impl<Lgc: Clone + Logic + Send + 'static> Read<Lgc> {
let stream_error = match e {
peanuts::Error::ReadError(error) => None,
peanuts::Error::Utf8Error(utf8_error) => Some(StreamError::UnsupportedEncoding),
- peanuts::Error::ParseError(_) => Some(StreamError::BadFormat),
+ peanuts::Error::ParseError(_, _) => Some(StreamError::BadFormat),
peanuts::Error::EntityProcessError(_) => Some(StreamError::RestrictedXml),
peanuts::Error::InvalidCharRef(char_ref_error) => Some(StreamError::UnsupportedEncoding),
peanuts::Error::DuplicateNameSpaceDeclaration(namespace_declaration) => Some(StreamError::NotWellFormed),
@@ -140,6 +140,7 @@ impl<Lgc: Clone + Logic + Send + 'static> Read<Lgc> {
peanuts::Error::UndeclaredNamespace(_) => Some(StreamError::InvalidNamespace),
peanuts::Error::Deserialize(deserialize_error) => Some(StreamError::InvalidXml),
peanuts::Error::RootElementEnded => Some(StreamError::InvalidXml),
+ _ => None,
};
let _ = self.on_crash.send((stream_error, ReadState { supervisor_control: self.supervisor_control, tasks: self.tasks }));
@@ -169,7 +170,8 @@ pub enum ReadControl {
pub struct ReadControlHandle {
sender: mpsc::Sender<ReadControl>,
- pub(crate) handle: JoinHandle<()>,
+ // TODO: same here
+ // pub(crate) handle: JoinHandle<()>,
}
impl Deref for ReadControlHandle {
@@ -188,7 +190,7 @@ impl DerefMut for ReadControlHandle {
impl ReadControlHandle {
pub fn new<Lgc: Clone + Logic + Send + 'static>(
- stream: BoundJabberReader<Tls>,
+ stream: BoundJabberReader,
connected: Connected,
logic: Lgc,
supervisor_control: SupervisorSender,
@@ -205,16 +207,18 @@ impl ReadControlHandle {
control_receiver,
on_crash,
);
- let handle = tokio::spawn(async move { actor.run().await });
+ #[cfg(target_arch = "wasm32")]
+ wasm_bindgen_futures::spawn_local(async move { actor.run().await });
+ #[cfg(not(target_arch = "wasm32"))]
+ tokio::spawn(async move { actor.run().await });
Self {
sender: control_sender,
- handle,
}
}
pub fn reconnect<Lgc: Clone + Logic + Send + 'static>(
- stream: BoundJabberReader<Tls>,
+ stream: BoundJabberReader,
tasks: JoinSet<()>,
connected: Connected,
logic: Lgc,
@@ -232,11 +236,13 @@ impl ReadControlHandle {
control_receiver,
on_crash,
);
- let handle = tokio::spawn(async move { actor.run().await });
+ #[cfg(target_arch = "wasm32")]
+ wasm_bindgen_futures::spawn_local(async move { actor.run().await });
+ #[cfg(not(target_arch = "wasm32"))]
+ tokio::spawn(async move { actor.run().await });
Self {
sender: control_sender,
- handle,
}
}
}