diff --git a/Cargo.lock b/Cargo.lock index dc25bb8..4120452 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2506,11 +2506,12 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.7" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebbbdb961df0ad3f2652da8f3fdc4b36122f568f968f45ad3316f26c025c677b" +checksum = "bf4ef73721ac7bcd79b2b315da7779d8fc09718c6b3d2d1b2d94850eb8c18432" dependencies = [ - "once_cell", + "log", + "ring", "rustls-pki-types", "rustls-webpki", "subtle", @@ -2880,9 +2881,9 @@ dependencies = [ [[package]] name = "tokio-tungstenite" -version = "0.23.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "becd34a233e7e31a3dbf7c7241b38320f57393dcae8e7324b0167d21b8e320b0" +checksum = "c83b561d025642014097b66e6c1bb422783339e0909e4429cde4749d1990bc38" dependencies = [ "futures-util", "log", @@ -2957,9 +2958,9 @@ checksum = "17f77d76d837a7830fe1d4f12b7b4ba4192c1888001c7164257e4bc6d21d96b4" [[package]] name = "tungstenite" -version = "0.23.0" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e2e2ce1e47ed2994fd43b04c8f618008d4cabdd5ee34027cf14f9d918edd9c8" +checksum = "9ef1a641ea34f399a848dea702823bbecfb4c486f911735368f1f137cb8257e1" dependencies = [ "byteorder", "bytes", @@ -2972,6 +2973,7 @@ dependencies = [ "rustls-pki-types", "sha1", "thiserror", + "url", "utf-8", "webpki-roots", ] diff --git a/Cargo.toml b/Cargo.toml index f7cc876..3bff19c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,8 +20,8 @@ futures-util = { version = "0.3", default-features = false } js-sys = "0.3" log = "0.4" tokio = "1.16" -tokio-tungstenite = "0.23" -tungstenite = "0.23" +tokio-tungstenite = ">=0.17, <=0.21" +tungstenite = { version = ">=0.17, <=0.21" } wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" web-sys = "0.3" diff --git a/echo_server/src/main.rs b/echo_server/src/main.rs index 88a0861..37e70ed 100644 --- a/echo_server/src/main.rs +++ b/echo_server/src/main.rs @@ -1,3 +1,4 @@ +#![allow(deprecated)] // TODO(emilk): Remove when we update tungstenite #![allow(clippy::unwrap_used, clippy::disallowed_methods)] // We are just testing here. use std::{net::TcpListener, thread::spawn}; @@ -10,10 +11,10 @@ fn main() { spawn(move || { let mut websocket = tungstenite::accept(stream.unwrap()).unwrap(); eprintln!("New client connected"); - while let Ok(msg) = websocket.read() { + while let Ok(msg) = websocket.read_message() { // We do not want to send back ping/pong messages. if msg.is_binary() || msg.is_text() { - if let Err(err) = websocket.send(msg) { + if let Err(err) = websocket.write_message(msg) { eprintln!("Error sending message: {err}"); break; } else { diff --git a/ewebsock/src/lib.rs b/ewebsock/src/lib.rs index 67eea3b..b0ce916 100644 --- a/ewebsock/src/lib.rs +++ b/ewebsock/src/lib.rs @@ -133,16 +133,12 @@ pub struct Options { /// /// Ignored on Web. pub max_incoming_frame_size: usize, - - /// Delay blocking in ms - default 10ms - pub delay_blocking: std::time::Duration, } impl Default for Options { fn default() -> Self { Self { max_incoming_frame_size: 64 * 1024 * 1024, - delay_blocking: std::time::Duration::from_millis(10), } } } diff --git a/ewebsock/src/native_tungstenite.rs b/ewebsock/src/native_tungstenite.rs index 1af2ae7..c5d1e84 100644 --- a/ewebsock/src/native_tungstenite.rs +++ b/ewebsock/src/native_tungstenite.rs @@ -1,4 +1,4 @@ -//! Native implementation of the WebSocket client using the `tungstenite` crate. +#![allow(deprecated)] // TODO(emilk): Remove when we update tungstenite use std::{ ops::ControlFlow, @@ -95,7 +95,7 @@ pub fn ws_receiver_blocking(url: &str, options: Options, on_event: &EventHandler } loop { - let control = match socket.read() { + let control = match socket.read_message() { Ok(incoming_msg) => match incoming_msg { tungstenite::protocol::Message::Text(text) => { on_event(WsEvent::Message(WsMessage::Text(text))) @@ -155,7 +155,7 @@ pub(crate) fn ws_connect_impl( /// Connect and call the given event handler on each received event. /// -/// This is a blocking variant of [`crate::ws_connect`], only available on native. +/// This is a blocking variant of [`ws_connect`], only available on native. /// /// # Errors /// All errors are returned to the caller, and NOT reported via `on_event`. @@ -165,7 +165,6 @@ pub fn ws_connect_blocking( on_event: &EventHandler, rx: &Receiver, ) -> Result<()> { - let delay = options.delay_blocking; let config = tungstenite::protocol::WebSocketConfig::from(options); let max_redirects = 3; // tungstenite default let (mut socket, response) = @@ -217,22 +216,22 @@ pub fn ws_connect_blocking( WsMessage::Pong(data) => tungstenite::protocol::Message::Pong(data), WsMessage::Unknown(_) => panic!("You cannot send WsMessage::Unknown"), }; - if let Err(err) = socket.write(outgoing_message) { + if let Err(err) = socket.write_message(outgoing_message) { socket.close(None).ok(); - socket.flush().ok(); + socket.write_pending().ok(); return Err(format!("send: {err}")); } } Err(TryRecvError::Disconnected) => { log::debug!("WsSender dropped - closing connection."); socket.close(None).ok(); - socket.flush().ok(); + socket.write_pending().ok(); return Ok(()); } Err(TryRecvError::Empty) => {} }; - let control = match socket.read() { + let control = match socket.read_message() { Ok(incoming_msg) => { did_work = true; match incoming_msg { @@ -274,7 +273,7 @@ pub fn ws_connect_blocking( } if !did_work { - std::thread::sleep(delay); + std::thread::sleep(std::time::Duration::from_millis(10)); // TODO(emilk): make configurable } } } diff --git a/ewebsock/src/tungstenite_common.rs b/ewebsock/src/tungstenite_common.rs index 4b8cfdc..cc579bd 100644 --- a/ewebsock/src/tungstenite_common.rs +++ b/ewebsock/src/tungstenite_common.rs @@ -2,7 +2,6 @@ impl From for tungstenite::protocol::WebSocketConfig { fn from(options: crate::Options) -> Self { let crate::Options { max_incoming_frame_size, - .. } = options; Self {