119 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			119 lines
		
	
	
		
			4.0 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<!DOCTYPE html>
 | 
						|
<html>
 | 
						|
<head>
 | 
						|
    <meta charset="UTF-8" />
 | 
						|
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
 | 
						|
    <title>Circles WebSocket Client</title>
 | 
						|
    <link data-trunk rel="rust" href="../Cargo.toml" data-wasm-opt="z" />
 | 
						|
    <style>
 | 
						|
        body {
 | 
						|
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
 | 
						|
            margin: 20px;
 | 
						|
            max-width: 800px;
 | 
						|
            margin: 0 auto;
 | 
						|
            padding: 20px;
 | 
						|
        }
 | 
						|
        .container {
 | 
						|
            background: white;
 | 
						|
            padding: 20px;
 | 
						|
            border-radius: 8px;
 | 
						|
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
 | 
						|
        }
 | 
						|
        .input-group {
 | 
						|
            margin-bottom: 20px;
 | 
						|
        }
 | 
						|
        input[type="text"] {
 | 
						|
            padding: 8px;
 | 
						|
            border: 1px solid #ddd;
 | 
						|
            border-radius: 4px;
 | 
						|
            width: 100%;
 | 
						|
            margin-top: 8px;
 | 
						|
        }
 | 
						|
        button {
 | 
						|
            background: #007bff;
 | 
						|
            color: white;
 | 
						|
            padding: 8px 16px;
 | 
						|
            border: none;
 | 
						|
            border-radius: 4px;
 | 
						|
            cursor: pointer;
 | 
						|
        }
 | 
						|
        button:hover {
 | 
						|
            background: #0056b3;
 | 
						|
        }
 | 
						|
        pre {
 | 
						|
            background: #f5f5f5;
 | 
						|
            padding: 15px;
 | 
						|
            border-radius: 4px;
 | 
						|
            overflow-x: auto;
 | 
						|
        }
 | 
						|
    </style>
 | 
						|
</head>
 | 
						|
<body>
 | 
						|
    <div class="container">
 | 
						|
        <h1>Circles WebSocket Client</h1>
 | 
						|
        
 | 
						|
        <div class="input-group">
 | 
						|
            <label for="ws-url">WebSocket URL:</label>
 | 
						|
            <input type="text" id="ws-url" placeholder="ws://localhost:8080">
 | 
						|
        </div>
 | 
						|
 | 
						|
        <div class="input-group">
 | 
						|
            <label for="script">Rhai Script:</label>
 | 
						|
            <input type="text" id="script" placeholder="Enter Rhai script here">
 | 
						|
        </div>
 | 
						|
 | 
						|
        <button id="run-script">Run Script</button>
 | 
						|
        <button id="run-interactive">Interactive Mode</button>
 | 
						|
 | 
						|
        <div id="output" style="margin-top: 20px;">
 | 
						|
            <h2>Output:</h2>
 | 
						|
            <pre id="output-content"></pre>
 | 
						|
        </div>
 | 
						|
    </div>
 | 
						|
 | 
						|
    <script type="module">
 | 
						|
        // Trunk will inject the necessary JS to load the WASM module.
 | 
						|
        // The wasm_bindgen functions will be available on the `window` object.
 | 
						|
        async function main() {
 | 
						|
            // The `wasm_bindgen` object is exposed globally by the Trunk-injected script.
 | 
						|
            const { start_client } = wasm_bindgen;
 | 
						|
 | 
						|
            document.getElementById('run-script').addEventListener('click', async () => {
 | 
						|
                const url = document.getElementById('ws-url').value;
 | 
						|
                const script = document.getElementById('script').value;
 | 
						|
                if (!url) {
 | 
						|
                    alert('Please enter a WebSocket URL');
 | 
						|
                    return;
 | 
						|
                }
 | 
						|
                try {
 | 
						|
                    // The init function is called automatically by Trunk's setup.
 | 
						|
                    const result = await start_client(url, script);
 | 
						|
                    document.getElementById('output-content').textContent = result;
 | 
						|
                } catch (error) {
 | 
						|
                    console.error('Error:', error);
 | 
						|
                    document.getElementById('output-content').textContent = `Error: ${error}`;
 | 
						|
                }
 | 
						|
            });
 | 
						|
 | 
						|
            document.getElementById('run-interactive').addEventListener('click', async () => {
 | 
						|
                const url = document.getElementById('ws-url').value;
 | 
						|
                if (!url) {
 | 
						|
                    alert('Please enter a WebSocket URL');
 | 
						|
                    return;
 | 
						|
                }
 | 
						|
                try {
 | 
						|
                    // The init function is called automatically by Trunk's setup.
 | 
						|
                    await start_client(url, null);
 | 
						|
                } catch (error) {
 | 
						|
                    console.error('Error:', error);
 | 
						|
                    alert(`Error: ${error}`);
 | 
						|
                }
 | 
						|
            });
 | 
						|
        }
 | 
						|
 | 
						|
        // The `wasm_bindgen` function is a promise that resolves when the WASM is loaded.
 | 
						|
        wasm_bindgen('./pkg/circle_client_ws_bg.wasm').then(main).catch(console.error);
 | 
						|
    </script>
 | 
						|
</body>
 | 
						|
</html>
 |