From ac495b9fb4644aa5b77ab90bdab5e2524a96cf9b Mon Sep 17 00:00:00 2001 From: Lorenzo Rizzotti Date: Tue, 8 Aug 2023 15:32:34 +0200 Subject: [PATCH] fix(websocket): config (#541) Co-authored-by: Lucas Nogueira --- plugins/websocket/guest-js/index.ts | 15 +++++++++++++-- plugins/websocket/src/lib.rs | 3 ++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/plugins/websocket/guest-js/index.ts b/plugins/websocket/guest-js/index.ts index 27beee5fb..0f748092d 100644 --- a/plugins/websocket/guest-js/index.ts +++ b/plugins/websocket/guest-js/index.ts @@ -1,5 +1,13 @@ import { invoke, transformCallback } from "@tauri-apps/api/tauri"; +export interface ConnectionConfig { + writeBufferSize?: number; + maxWriteBufferSize?: number; + maxMessageSize?: number; + maxFrameSize?: number; + acceptUnmaskedFrames?: boolean; +} + export interface MessageKind { type: T; data: D; @@ -26,7 +34,10 @@ export default class WebSocket { this.listeners = listeners; } - static async connect(url: string, options?: unknown): Promise { + static async connect( + url: string, + config?: ConnectionConfig, + ): Promise { const listeners: Array<(arg: Message) => void> = []; const handler = (message: Message): void => { listeners.forEach((l) => l(message)); @@ -35,7 +46,7 @@ export default class WebSocket { return await invoke("plugin:websocket|connect", { url, callbackFunction: transformCallback(handler), - options, + config, }).then((id) => new WebSocket(id, listeners)); } diff --git a/plugins/websocket/src/lib.rs b/plugins/websocket/src/lib.rs index a26f6ae24..3d3878b5d 100644 --- a/plugins/websocket/src/lib.rs +++ b/plugins/websocket/src/lib.rs @@ -42,13 +42,14 @@ impl Serialize for Error { #[derive(Default)] struct ConnectionManager(Mutex>); -#[derive(Default, Deserialize)] +#[derive(Deserialize)] #[serde(rename_all = "camelCase")] pub struct ConnectionConfig { pub write_buffer_size: Option, pub max_write_buffer_size: Option, pub max_message_size: Option, pub max_frame_size: Option, + #[serde(default)] pub accept_unmasked_frames: bool, }