diff options
Diffstat (limited to 'lampada/src/connection/write.rs')
-rw-r--r-- | lampada/src/connection/write.rs | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/lampada/src/connection/write.rs b/lampada/src/connection/write.rs index 1070cdf..4c6ed24 100644 --- a/lampada/src/connection/write.rs +++ b/lampada/src/connection/write.rs @@ -1,6 +1,6 @@ use std::ops::{Deref, DerefMut}; -use luz::{connection::Tls, jabber_stream::bound_stream::BoundJabberWriter}; +use luz::jabber_stream::bound_stream::BoundJabberWriter; use stanza::{ client::Stanza, stream::Error as StreamErrorStanza, stream_error::Error as StreamError, }; @@ -13,7 +13,7 @@ use crate::error::WriteError; /// actor that receives jabber stanzas to write, and if there is an error, sends a message back to the supervisor then aborts, so the supervisor can spawn a new stream. pub struct Write { - stream: BoundJabberWriter<Tls>, + stream: BoundJabberWriter, /// connection session write queue stanza_receiver: mpsc::Receiver<WriteMessage>, @@ -41,7 +41,7 @@ pub enum WriteControl { impl Write { fn new( - stream: BoundJabberWriter<Tls>, + stream: BoundJabberWriter, stanza_receiver: mpsc::Receiver<WriteMessage>, control_receiver: mpsc::Receiver<WriteControl>, on_crash: oneshot::Sender<(WriteMessage, WriteState)>, @@ -192,7 +192,7 @@ impl DerefMut for WriteHandle { pub struct WriteControlHandle { sender: mpsc::Sender<WriteControl>, - pub(crate) handle: JoinHandle<()>, + // pub(crate) handle: JoinHandle<()>, } impl Deref for WriteControlHandle { @@ -211,14 +211,17 @@ impl DerefMut for WriteControlHandle { impl WriteControlHandle { pub fn new( - stream: BoundJabberWriter<Tls>, + stream: BoundJabberWriter, on_crash: oneshot::Sender<(WriteMessage, WriteState)>, ) -> (WriteHandle, Self) { let (control_sender, control_receiver) = mpsc::channel(20); let (stanza_sender, stanza_receiver) = mpsc::channel(20); let actor = Write::new(stream, stanza_receiver, 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 }); ( WriteHandle { @@ -226,13 +229,12 @@ impl WriteControlHandle { }, Self { sender: control_sender, - handle, }, ) } pub fn reconnect_retry( - stream: BoundJabberWriter<Tls>, + stream: BoundJabberWriter, on_crash: oneshot::Sender<(WriteMessage, WriteState)>, stanza_receiver: mpsc::Receiver<WriteMessage>, retry_msg: WriteMessage, @@ -240,27 +242,32 @@ impl WriteControlHandle { let (control_sender, control_receiver) = mpsc::channel(20); let actor = Write::new(stream, stanza_receiver, control_receiver, on_crash); - let handle = tokio::spawn(async move { actor.run_reconnected(retry_msg).await }); + #[cfg(target_arch = "wasm32")] + wasm_bindgen_futures::spawn_local(async move { actor.run_reconnected(retry_msg).await }); + #[cfg(not(target_arch = "wasm32"))] + tokio::spawn(async move { actor.run_reconnected(retry_msg).await }); Self { sender: control_sender, - handle, } } pub fn reconnect( - stream: BoundJabberWriter<Tls>, + stream: BoundJabberWriter, on_crash: oneshot::Sender<(WriteMessage, WriteState)>, stanza_receiver: mpsc::Receiver<WriteMessage>, ) -> Self { let (control_sender, control_receiver) = mpsc::channel(20); let actor = Write::new(stream, stanza_receiver, 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, } } } |