allow user to easily override location with text entry.

This commit is contained in:
jasonwitty 2025-09-09 13:43:45 -07:00
parent 49164da105
commit b91fc7b016
7 changed files with 48 additions and 20 deletions

View File

@ -23,6 +23,16 @@
}
button:hover { background: #0757c7; }
button:disabled { background: #ccc; cursor: not-allowed; }
.server-input {
margin: 10px 0;
padding: 8px;
width: 300px;
border: 1px solid #ddd;
border-radius: 4px;
font-family: monospace;
}
.input-group { margin: 15px 0; }
.input-group label { display: block; margin-bottom: 5px; font-weight: bold; }
#output {
border: 1px solid #ddd;
border-radius: 4px;
@ -43,6 +53,12 @@
<p><strong>Status:</strong> <span id="status">Loading WASM module...</span></p>
</div>
<div class="input-group">
<label for="server-url">Server URL:</label>
<input type="text" id="server-url" class="server-input" value="ws://localhost:3000/ws"
placeholder="ws://localhost:3000/ws">
</div>
<button id="test-btn" disabled>Run WASM Test</button>
<button id="clear-btn">Clear Output</button>
@ -111,9 +127,11 @@
testBtn.onclick = () => {
testBtn.disabled = true;
const serverUrl = document.getElementById('server-url').value.trim();
addLog('=== Starting WASM Test ===', 'info');
addLog(`🌐 Using server: ${serverUrl}`, 'info');
try {
test_socktop_connector();
test_socktop_connector(serverUrl || undefined);
setTimeout(() => {
testBtn.disabled = false;
}, 2000);

View File

@ -16,13 +16,17 @@ macro_rules! console_log {
// This is the main entry point called from JavaScript
#[wasm_bindgen]
pub fn test_socktop_connector() {
pub fn test_socktop_connector(server_url: Option<String>) {
console_error_panic_hook::set_once();
// Use provided URL or default
let url = server_url.unwrap_or_else(|| "ws://localhost:3000/ws".to_string());
console_log!("🦀 Starting WASM connector test...");
console_log!("🌐 Connecting to: {}", url);
// Test 1: Create configuration
let config = ConnectorConfig::new("ws://localhost:3000/ws");
let config = ConnectorConfig::new(&url);
console_log!("✅ Config created: {}", config.url);
// Test 2: Test configuration methods

View File

@ -39,6 +39,20 @@
<p>This test demonstrates that <code>socktop_connector</code> works properly in WebAssembly with real WebSocket connections.</p>
<div style="margin: 20px 0; padding: 15px; background: #f9f9f9; border-radius: 4px;">
<label for="serverUrl" style="display: block; font-weight: bold; margin-bottom: 5px;">
🌐 WebSocket Server URL:
</label>
<input
type="text"
id="serverUrl"
value="ws://localhost:3000/ws"
style="width: 300px; padding: 8px; margin-right: 10px; border: 1px solid #ccc; border-radius: 4px;"
placeholder="ws://your-server:port/ws"
/>
<small style="color: #666;">Edit if your socktop_agent is running on a different host/port</small>
</div>
<div>
<button onclick="runTest()">Run Test</button>
<button onclick="clearLog()">Clear Log</button>
@ -47,22 +61,6 @@
<h2>Test Output:</h2>
<div id="log" class="log">Click "Run Test" to start...\n</div>
<h2>Test Details:</h2>
<ul>
<li>✅ Uses real <code>socktop_connector::SocktopConnector</code> API</li>
<li>✅ Makes actual WebSocket connections to socktop agents</li>
<li>✅ Calls real API methods: <code>get_metrics()</code>, <code>get_disks()</code>, <code>get_processes()</code></li>
<li>✅ No fake data or browser-specific workarounds</li>
<li>✅ Full end-to-end test of socktop_connector in WASM</li>
</ul>
<p><strong>Prerequisites:</strong></p>
<ul>
<li>✅ socktop_agent running on localhost:3000</li>
<li>✅ WebSocket connection allowed (no CORS issues)</li>
<li>✅ WASM module properly compiled and loaded</li>
</ul>
<script type="module">
import init, { test_socktop_connector } from './pkg/socktop_wasm_test.js';
@ -112,14 +110,22 @@
return;
}
// Get the server URL from the input field
const serverUrl = document.getElementById('serverUrl').value.trim();
if (!serverUrl) {
console.log('❌ Server URL cannot be empty');
return;
}
try {
console.log('');
console.log('='.repeat(60));
console.log('🚀 Starting socktop_connector WASM test...');
console.log('🌐 Server URL: ' + serverUrl);
console.log('='.repeat(60));
console.log('');
test_socktop_connector();
test_socktop_connector(serverUrl);
} catch (error) {
console.log('❌ Error running test:', error);
console.log('🔍 Error details:', error.stack);