Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
UkoeHB committed Oct 13, 2023
1 parent 4c2028c commit 15d1cf7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
6 changes: 3 additions & 3 deletions examples/chat-client-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ console_error_panic_hook = "0.1"
ezsockets = { path = "../../", default-features = false, features = ["wasm_client"] }
tracing = "0.1.32"
tracing-subscriber = "0.3.9"
tracing-wasm = { version = "0.2" }
tracing-wasm = "0.2"
url = "2.2.2"
wasm-bindgen = { version = "0.2" }
wasm-bindgen-futures = { version = "0.4" }
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
wasmtimer = "0.2.0"
5 changes: 3 additions & 2 deletions examples/chat-client-wasm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ async fn main() -> Result<(), wasm_bindgen::JsValue> {
tracing_wasm::set_as_global_default();

// make client
// - note: we use a hacky custom Ping/Pong protocol to keep the client alive (see the 'chat-server' example
// for the Ping side via SessionExt::on_binary())
let config = ClientConfig::new("ws://localhost:8080/websocket").socket_config(SocketConfig {
heartbeat: Duration::from_secs(5),
timeout: Duration::from_secs(10),
heartbeat_ping_msg_fn: Arc::new(|_t: Duration| RawMessage::Binary("ping".into())),
..Default::default()
});
let (client, mut handle) = ezsockets::connect_with(
|_client| Client {},
Expand Down
2 changes: 1 addition & 1 deletion examples/chat-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl ezsockets::SessionExt for SessionActor {
}

async fn on_binary(&mut self, bytes: Vec<u8>) -> Result<(), Error> {
// echo bytes back (we use this for a hacky ping/pong protocol for the client demo)
// echo bytes back (we use this for a hacky ping/pong protocol for the wasm client demo)
tracing::info!("echoing bytes: {bytes:?}");
self.session.binary("pong".as_bytes())?;
Ok(())
Expand Down
2 changes: 0 additions & 2 deletions src/client_connectors/client_connector_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ impl futures_util::Sink<tokio_tungstenite_wasm::Message> for WebSocketStreamProx
async fn wasm_client_connect(
request_url: String,
) -> Result<WebSocketStreamProxy, tokio_tungstenite_wasm::Error> {
// connect the websocket
let (result_sender, result_receiver) = async_channel::bounded(1usize);

wasm_bindgen_futures::spawn_local(async move {
Expand All @@ -174,6 +173,5 @@ async fn wasm_client_connect(
.await
.unwrap_or(Err(tokio_tungstenite_wasm::Error::ConnectionClosed))?;

// build proxy
Ok(WebSocketStreamProxy { inner: websocket })
}
7 changes: 3 additions & 4 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ where
loop {
futures::select! {
res = self.receiver.recv().fuse() => {
let Ok(mut inmessage) = res else { break; };
let Ok(mut inmessage) = res else {
break;
};
let Some(message) = inmessage.take_message() else {
continue;
};
Expand All @@ -351,9 +353,6 @@ where
_ = &mut self.abort_receiver.recv().fuse() => {
break;
},
complete => {
break;
}
}
}
Ok(())
Expand Down

0 comments on commit 15d1cf7

Please sign in to comment.