This commit is contained in:
Zhanghu
2026-01-13 13:50:27 +08:00
commit a9efcd55a7
72 changed files with 8430 additions and 0 deletions

67
test_websocket.html Normal file
View File

@@ -0,0 +1,67 @@
<!DOCTYPE html>
<html>
<head>
<title>WebSocket Test</title>
<meta charset="utf-8">
</head>
<body>
<h1>DRS9 Dashboard WebSocket Test</h1>
<div>
<input type="text" id="deviceId" placeholder="Device ID (optional)" value="1">
<button onclick="connect()">Connect</button>
<button onclick="disconnect()">Disconnect</button>
</div>
<div>
<input type="text" id="message" placeholder="Message (e.g., {\"type\":\"ping\"})" value='{"type":"ping"}'>
<button onclick="send()">Send</button>
</div>
<pre id="log"></pre>
<script>
let ws = null;
function log(msg) {
const el = document.getElementById('log');
el.textContent += new Date().toLocaleTimeString() + ': ' + msg + '\n';
}
function connect() {
const deviceId = document.getElementById('deviceId').value;
const url = 'ws://localhost:5264/ws' + (deviceId ? '?deviceId=' + deviceId : '');
log('Connecting to ' + url);
ws = new WebSocket(url);
ws.onopen = () => {
log('Connected!');
};
ws.onmessage = (e) => {
log('Received: ' + e.data);
};
ws.onerror = (e) => {
log('Error: ' + e);
};
ws.onclose = () => {
log('Disconnected');
};
}
function disconnect() {
if (ws) ws.close();
}
function send() {
if (!ws || ws.readyState !== WebSocket.OPEN) {
log('Not connected');
return;
}
const msg = document.getElementById('message').value;
log('Sending: ' + msg);
ws.send(msg);
}
</script>
</body>
</html>