I have this code tne I'm trying to use in a Bevy app that compiles to wasm:
fn actually_connect(
mut ev_connect: EventWriter<WebSocketConnectionEvents>,
mut commands: Commands
) {
let options = ewebsock::Options::default();
let (mut sender, receiver) = ewebsock::connect("ws://0.0.0.0:8000/ws", options).unwrap();
println!("Conected!");
sender.send(ewebsock::WsMessage::Text("Hello!".into()));
while let Some(event) = receiver.try_recv() {
println!("Received message {:?}", event);
}
}
In the logs of the server I can see that it immediately connects and then disconnects which is not what I want- I want it to stay connected. I also want to get a handle on the "sender" and "receiver" ideally in a bevy resource or something like that so that I can use them later in other system functions. When I try to just set them as struct params marked as Component though it gives me this error for receiver:
std::sync::mpsc::Receiver<WsEvent> cannot be shared between threads safely
within WebSocketClient, the trait Sync is not implemented for std::sync::mpsc::Receiver<WsEvent>, which is required by WebSocketClient: bevy::prelude::Bundle
the following other types implement trait bevy::prelude::Bundle:
Is what I'm trying to do even right?
What would be the proper syntax that works with Rust and Bevy to do this?
Thanks!