Merge branch 'feature/extract-socktop-connector' of https://github.com/jasonwitty/socktop into feature/extract-socktop-connector

This commit is contained in:
jasonwitty 2025-09-09 13:43:48 -07:00
commit 8286d21a2a

View File

@ -25,6 +25,8 @@ This directory contains a complete WebAssembly (WASM) compatibility test and imp
## Quick Test
```bash
# Please note that the test assumes you have and agent runnign on your local host at port 3000. If you would like to use an alternate configuration please update lib.rs prior to build.
# Build the WASM package
wasm-pack build --target web --out-dir pkg
@ -143,71 +145,3 @@ async function run() {
run();
```
## Benefits of This Approach
1. **Type Safety**: All socktop types work identically in WASM
2. **Validation**: Configuration validation happens in Rust
3. **Maintainability**: Share types between native and WASM code
4. **Performance**: Rust types compile to efficient WASM
5. **Future Proof**: Updates to socktop types automatically work in WASM
## Real-World Usage
For production WASM applications:
1. Use this pattern to create a WASM module that exports configuration and serialization functions
2. Handle WebSocket connections in JavaScript using browser APIs
3. Use the exported functions for type-safe message creation and parsing
4. Leverage socktop's structured error handling for robust applications
- **No TLS dependencies**: Completely avoids rustls/TLS
- **No tokio/mio**: Uses only WASM-compatible dependencies
### ❌ WASM Limitations
- **No native networking**: `tokio-tungstenite` doesn't work in WASM
- **No TLS support**: rustls is not WASM-compatible
- **No file system**: Certificate loading not available
## Architecture for WASM Users
```
WASM Application
├── Use socktop_connector types (✅ this test proves it works)
├── Use browser WebSocket API for networking
└── Handle serialization with socktop message format
```
## Quick Start
1. **Build the WASM package**:
```bash
cd socktop_wasm_test
wasm-pack build --target web --out-dir pkg
```
2. **Start local server**:
```bash
basic-http-server .
```
3. **Open browser** to `http://localhost:8000` and click "Run WASM Test"
## Success Criteria
- ✅ WASM builds without any networking dependencies
- ✅ Core types compile and serialize properly
- ✅ Configuration API works for WebSocket setup
- ✅ No rustls/TLS/tokio/mio dependencies
## Real-World WASM Usage
WASM users should:
1. **Use these types** for message structure compatibility
2. **Use browser WebSocket** for actual connections:
```javascript
const ws = new WebSocket('ws://localhost:3000/ws');
ws.send(JSON.stringify({ request: 'Metrics' }));
```
3. **Handle responses** using the same serialization format
This test proves `socktop_connector`'s **types and patterns** work in WASM, even though the networking must be handled differently.