Skip to content

Commit

Permalink
fix(websocket): config (#541)
Browse files Browse the repository at this point in the history
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
Dreaming-Codes and lucasfernog authored Aug 8, 2023
1 parent dacde16 commit ac495b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 13 additions & 2 deletions plugins/websocket/guest-js/index.ts
Original file line number Diff line number Diff line change
@@ -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<T, D> {
type: T;
data: D;
Expand All @@ -26,7 +34,10 @@ export default class WebSocket {
this.listeners = listeners;
}

static async connect(url: string, options?: unknown): Promise<WebSocket> {
static async connect(
url: string,
config?: ConnectionConfig,
): Promise<WebSocket> {
const listeners: Array<(arg: Message) => void> = [];
const handler = (message: Message): void => {
listeners.forEach((l) => l(message));
Expand All @@ -35,7 +46,7 @@ export default class WebSocket {
return await invoke<number>("plugin:websocket|connect", {
url,
callbackFunction: transformCallback(handler),
options,
config,
}).then((id) => new WebSocket(id, listeners));
}

Expand Down
3 changes: 2 additions & 1 deletion plugins/websocket/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ impl Serialize for Error {
#[derive(Default)]
struct ConnectionManager(Mutex<HashMap<Id, WebSocketWriter>>);

#[derive(Default, Deserialize)]
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ConnectionConfig {
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>,
#[serde(default)]
pub accept_unmasked_frames: bool,
}

Expand Down

0 comments on commit ac495b9

Please sign in to comment.