From 22c1f80e70c52dd47b192161f35984df18dd7036 Mon Sep 17 00:00:00 2001 From: jasonwitty Date: Tue, 9 Sep 2025 02:38:35 -0700 Subject: [PATCH] docs(connector): update README to reflect full WASM support --- socktop_connector/README.md | 38 +++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/socktop_connector/README.md b/socktop_connector/README.md index ce706bf..6839aef 100644 --- a/socktop_connector/README.md +++ b/socktop_connector/README.md @@ -32,7 +32,7 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -socktop_connector = "0.1.3" +socktop_connector = "0.1.5" tokio = { version = "1", features = ["rt", "rt-multi-thread", "net", "time", "macros"] } ``` @@ -342,27 +342,57 @@ The library provides flexible configuration through the `ConnectorConfig` builde ## WASM Compatibility -`socktop_connector` provides **types-only support** for WebAssembly (WASM) environments. The core types and configuration work perfectly in WASM, but networking must be handled through browser WebSocket APIs. +`socktop_connector` provides **full WebSocket support** for WebAssembly (WASM) environments, including complete networking functionality with automatic compression and protobuf decoding. ### Quick Setup ```toml [dependencies] -socktop_connector = { version = "0.1.3", default-features = false } +socktop_connector = { version = "0.1.5", default-features = false, features = ["wasm"] } wasm-bindgen = "0.2" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" ``` ### What Works +- ✅ Full WebSocket connectivity (`ws://` connections) +- ✅ All request types (`Metrics`, `Disks`, `Processes`) +- ✅ Automatic gzip decompression for metrics and disks +- ✅ Automatic protobuf decoding for process data - ✅ All types (`ConnectorConfig`, `AgentRequest`, `AgentResponse`) - ✅ JSON serialization/deserialization - ✅ Protocol and version configuration ### What Doesn't Work -- ❌ Direct WebSocket connections (use browser APIs instead) +- ❌ TLS connections (`wss://`) - use `ws://` only - ❌ TLS certificate handling +### Basic WASM Usage + +```rust +use wasm_bindgen::prelude::*; +use socktop_connector::{ConnectorConfig, SocktopConnector, AgentRequest}; + +#[wasm_bindgen] +pub async fn test_connection() { + let config = ConnectorConfig::new("ws://localhost:3000/ws"); + let mut connector = SocktopConnector::new(config); + + match connector.connect().await { + Ok(()) => { + // Request metrics with automatic gzip decompression + let response = connector.request(AgentRequest::Metrics).await.unwrap(); + console_log!("Got metrics: {:?}", response); + + // Request processes with automatic protobuf decoding + let response = connector.request(AgentRequest::Processes).await.unwrap(); + console_log!("Got processes: {:?}", response); + } + Err(e) => console_log!("Connection failed: {}", e), + } +} +``` + ### Complete WASM Guide For detailed implementation examples, complete code samples, and a working test environment, see the **[WASM Compatibility Guide](../socktop_wasm_test/README.md)** in the `socktop_wasm_test/` directory.