Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(websocket): config #541

Merged
merged 6 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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