chore(deps): update rust crate tokio-tungstenite to 0.26 (v1) (#2211)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: FabianLars <fabianlars@fabianlars.de>

Committed via a GitHub action: https://github.com/tauri-apps/plugins-workspace/actions/runs/12632737471

Co-authored-by: FabianLars <FabianLars@users.noreply.github.com>
This commit is contained in:
renovate[bot]
2025-01-06 13:05:50 +00:00
committed by tauri-bot
parent 8265bec139
commit 4e578854c1
7 changed files with 112 additions and 32 deletions

View File

@@ -19,4 +19,4 @@ http = "1"
rand = "0.8"
futures-util = "0.3"
tokio = { version = "1", features = ["net", "sync"] }
tokio-tungstenite = { version = "0.24", features = ["native-tls"] }
tokio-tungstenite = { version = "0.26", features = ["native-tls"] }

30
dist-js/index.d.ts vendored
View File

@@ -1,9 +1,35 @@
export interface ConnectionConfig {
/**
* Read buffer capacity. The default value is 128 KiB.
*/
readBufferSize?: number;
/** The target minimum size of the write buffer to reach before writing the data to the underlying stream. The default value is 128 KiB.
*
* If set to 0 each message will be eagerly written to the underlying stream. It is often more optimal to allow them to buffer a little, hence the default value.
*/
writeBufferSize?: number;
/** The max size of the write buffer in bytes. Setting this can provide backpressure in the case the write buffer is filling up due to write errors. The default value is unlimited.
*
* Note: The write buffer only builds up past write_buffer_size when writes to the underlying stream are failing. So the write buffer can not fill up if you are not observing write errors.
*
* Note: Should always be at least write_buffer_size + 1 message and probably a little more depending on error handling strategy.
*/
maxWriteBufferSize?: number;
maxMessageSize?: number;
maxFrameSize?: number;
/**
* The maximum size of an incoming message. The string "none" means no size limit. The default value is 64 MiB which should be reasonably big for all normal use-cases but small enough to prevent memory eating by a malicious user.
*/
maxMessageSize?: number | "none";
/**
* The maximum size of a single incoming message frame. The string "none" means no size limit. The limit is for frame payload NOT including the frame header. The default value is 16 MiB which should be reasonably big for all normal use-cases but small enough to prevent memory eating by a malicious user.
*/
maxFrameSize?: number | "none";
/**
* When set to true, the server will accept and handle unmasked frames from the client. According to the RFC 6455, the server must close the connection to the client in such cases, however it seems like there are some popular libraries that are sending unmasked frames, ignoring the RFC. By default this option is set to false, i.e. according to RFC 6455.
*/
acceptUnmaskedFrames?: boolean;
/**
* Additional connect request headers.
*/
headers?: HeadersInit;
}
export interface MessageKind<T, D> {

File diff suppressed because one or more lines are too long

View File

@@ -1 +1 @@
{"version":3,"file":"index.mjs","sources":["../guest-js/index.ts"],"sourcesContent":[null],"names":[],"mappings":";;AA4Bc,MAAO,SAAS,CAAA;IAI5B,WAAY,CAAA,EAAU,EAAE,SAAwC,EAAA;AAC9D,QAAA,IAAI,CAAC,EAAE,GAAG,EAAE;AACZ,QAAA,IAAI,CAAC,SAAS,GAAG,SAAS;;AAG5B,IAAA,aAAa,OAAO,CAClB,GAAW,EACX,MAAyB,EAAA;QAEzB,MAAM,SAAS,GAAkC,EAAE;AACnD,QAAA,MAAM,OAAO,GAAG,CAAC,OAAgB,KAAU;AACzC,YAAA,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC;AACtC,SAAC;QAED,IAAI,MAAM,aAAN,MAAM,KAAA,SAAA,GAAA,SAAA,GAAN,MAAM,CAAE,OAAO,EAAE;AACnB,YAAA,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC;;AAGpE,QAAA,OAAO,MAAM,MAAM,CAAS,0BAA0B,EAAE;YACtD,GAAG;AACH,YAAA,gBAAgB,EAAE,iBAAiB,CAAC,OAAO,CAAC;YAC5C,MAAM;AACP,SAAA,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,IAAI,SAAS,CAAC,EAAE,EAAE,SAAS,CAAC,CAAC;;AAG/C,IAAA,WAAW,CAAC,EAA0B,EAAA;AACpC,QAAA,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC;;IAGzB,MAAM,IAAI,CAAC,OAAo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MAAM,IAAI,CAAC,IAAI,CAAC;AACrB,YAAA,IAAI,EAAE,OAAO;AACb,YAAA,IAAI,EAAE;AACJ,gBAAA,IAAI,EAAE,IAAI;AACV,gBAAA,MAAM,EAAE,wBAAwB;AACjC,aAAA;AACF,SAAA,CAAC;;AAEL;;;;"}

View File

@@ -11,7 +11,7 @@ tauri = { workspace = true }
tokio = { version = "1", features = ["net"] }
futures-util = "0.3"
tauri-plugin-websocket = { path = "../../../" }
tokio-tungstenite = "0.24"
tokio-tungstenite = "0.26"
[build-dependencies]
tauri-build = { workspace = true }

View File

@@ -1,11 +1,37 @@
import { invoke, transformCallback } from "@tauri-apps/api/tauri";
export interface ConnectionConfig {
/**
* Read buffer capacity. The default value is 128 KiB.
*/
readBufferSize?: number;
/** The target minimum size of the write buffer to reach before writing the data to the underlying stream. The default value is 128 KiB.
*
* If set to 0 each message will be eagerly written to the underlying stream. It is often more optimal to allow them to buffer a little, hence the default value.
*/
writeBufferSize?: number;
/** The max size of the write buffer in bytes. Setting this can provide backpressure in the case the write buffer is filling up due to write errors. The default value is unlimited.
*
* Note: The write buffer only builds up past write_buffer_size when writes to the underlying stream are failing. So the write buffer can not fill up if you are not observing write errors.
*
* Note: Should always be at least write_buffer_size + 1 message and probably a little more depending on error handling strategy.
*/
maxWriteBufferSize?: number;
maxMessageSize?: number;
maxFrameSize?: number;
/**
* The maximum size of an incoming message. The string "none" means no size limit. The default value is 64 MiB which should be reasonably big for all normal use-cases but small enough to prevent memory eating by a malicious user.
*/
maxMessageSize?: number | "none";
/**
* The maximum size of a single incoming message frame. The string "none" means no size limit. The limit is for frame payload NOT including the frame header. The default value is 16 MiB which should be reasonably big for all normal use-cases but small enough to prevent memory eating by a malicious user.
*/
maxFrameSize?: number | "none";
/**
* When set to true, the server will accept and handle unmasked frames from the client. According to the RFC 6455, the server must close the connection to the client in such cases, however it seems like there are some popular libraries that are sending unmasked frames, ignoring the RFC. By default this option is set to false, i.e. according to RFC 6455.
*/
acceptUnmaskedFrames?: boolean;
/**
* Additional connect request headers.
*/
headers?: HeadersInit;
}

View File

@@ -51,13 +51,21 @@ struct ConnectionManager(Mutex<HashMap<Id, WebSocketWriter>>);
struct TlsConnector(Mutex<Option<Connector>>);
#[derive(Deserialize)]
#[serde(untagged, rename_all = "camelCase")]
enum Max {
None,
Number(usize),
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConnectionConfig {
pub(crate) struct ConnectionConfig {
pub read_buffer_size: Option<usize>,
pub write_buffer_size: Option<usize>,
pub max_write_buffer_size: Option<usize>,
pub max_message_size: Option<usize>,
pub max_frame_size: Option<usize>,
pub max_message_size: Option<Max>,
pub max_frame_size: Option<Max>,
#[serde(default)]
pub accept_unmasked_frames: bool,
pub headers: Option<Vec<(String, String)>>,
@@ -65,18 +73,38 @@ pub struct ConnectionConfig {
impl From<ConnectionConfig> for WebSocketConfig {
fn from(config: ConnectionConfig) -> Self {
// Disabling the warning on max_send_queue which we don't use anymore since it was deprecated.
#[allow(deprecated)]
Self {
max_send_queue: None,
write_buffer_size: config.write_buffer_size.unwrap_or(128 * 1024),
max_write_buffer_size: config.max_write_buffer_size.unwrap_or(usize::MAX),
// This may be harmful since if it's not provided from js we're overwriting the default value with None, meaning no size limit.
max_message_size: config.max_message_size,
// This may be harmful since if it's not provided from js we're overwriting the default value with None, meaning no size limit.
max_frame_size: config.max_frame_size,
accept_unmasked_frames: config.accept_unmasked_frames,
let mut builder =
WebSocketConfig::default().accept_unmasked_frames(config.accept_unmasked_frames);
if let Some(read_buffer_size) = config.read_buffer_size {
builder = builder.read_buffer_size(read_buffer_size)
}
if let Some(write_buffer_size) = config.write_buffer_size {
builder = builder.write_buffer_size(write_buffer_size)
}
if let Some(max_write_buffer_size) = config.max_write_buffer_size {
builder = builder.max_write_buffer_size(max_write_buffer_size)
}
if let Some(max_message_size) = config.max_message_size {
let max_size = match max_message_size {
Max::None => Option::None,
Max::Number(n) => Some(n),
};
builder = builder.max_message_size(max_size);
}
if let Some(max_frame_size) = config.max_frame_size {
let max_size = match max_frame_size {
Max::None => Option::None,
Max::Number(n) => Some(n),
};
builder = builder.max_frame_size(max_size);
}
builder
}
}
@@ -136,21 +164,21 @@ async fn connect<R: Runtime>(
let response = match message {
Ok(Message::Text(t)) => {
serde_json::to_value(WebSocketMessage::Text(t)).unwrap()
serde_json::to_value(WebSocketMessage::Text(t.to_string())).unwrap()
}
Ok(Message::Binary(t)) => {
serde_json::to_value(WebSocketMessage::Binary(t)).unwrap()
serde_json::to_value(WebSocketMessage::Binary(t.to_vec())).unwrap()
}
Ok(Message::Ping(t)) => {
serde_json::to_value(WebSocketMessage::Ping(t)).unwrap()
serde_json::to_value(WebSocketMessage::Ping(t.to_vec())).unwrap()
}
Ok(Message::Pong(t)) => {
serde_json::to_value(WebSocketMessage::Pong(t)).unwrap()
serde_json::to_value(WebSocketMessage::Pong(t.to_vec())).unwrap()
}
Ok(Message::Close(t)) => {
serde_json::to_value(WebSocketMessage::Close(t.map(|v| CloseFrame {
code: v.code.into(),
reason: v.reason.into_owned(),
reason: v.reason.to_string(),
})))
.unwrap()
}
@@ -177,13 +205,13 @@ async fn send(
if let Some(write) = manager.0.lock().await.get_mut(&id) {
write
.send(match message {
WebSocketMessage::Text(t) => Message::Text(t),
WebSocketMessage::Binary(t) => Message::Binary(t),
WebSocketMessage::Ping(t) => Message::Ping(t),
WebSocketMessage::Pong(t) => Message::Pong(t),
WebSocketMessage::Text(t) => Message::Text(t.into()),
WebSocketMessage::Binary(t) => Message::Binary(t.into()),
WebSocketMessage::Ping(t) => Message::Ping(t.into()),
WebSocketMessage::Pong(t) => Message::Pong(t.into()),
WebSocketMessage::Close(t) => Message::Close(t.map(|v| ProtocolCloseFrame {
code: v.code.into(),
reason: std::borrow::Cow::Owned(v.reason),
reason: v.reason.into(),
})),
})
.await?;