63 lines
1.9 KiB
HTML
63 lines
1.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="fr">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Client WebSocket - Pull à la demande</title>
|
|
<style>
|
|
body { font-family: monospace; background: #1e1e1e; color: #f0f0f0; padding: 1rem; }
|
|
button { padding: 0.5rem 1rem; margin: 0.5rem; cursor: pointer; }
|
|
pre { background: #252526; padding: 1rem; border-radius: 6px; white-space: pre-wrap; word-break: break-word; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h2>Client WebSocket - Pull à la demande</h2>
|
|
<button onclick="sendTeamList()">Requête : team-list</button>
|
|
<button onclick="sendRaceDatas()">Requête : race-datas</button>
|
|
<button onclick="sendReset()">Reset chronos</button>
|
|
<button onclick="clearLog()">🧹 Clear screen</button>
|
|
<pre id="log"></pre>
|
|
|
|
<script>
|
|
const ws = new WebSocket("ws://yotta.tds-France.com:80");
|
|
|
|
ws.onopen = () => log("[INFO] Connexion ouverte");
|
|
ws.onclose = () => log("[INFO] Connexion fermée");
|
|
ws.onerror = (e) => log("[ERREUR] " + e.message);
|
|
|
|
ws.onmessage = (event) => {
|
|
try {
|
|
const json = JSON.parse(event.data);
|
|
const pretty = JSON.stringify(json, null, 2);
|
|
log("[MESSAGE] Reçu :\n" + pretty);
|
|
} catch (e) {
|
|
log("[MESSAGE] Non JSON :\n" + event.data);
|
|
}
|
|
};
|
|
|
|
function sendTeamList() {
|
|
ws.send(JSON.stringify({ path: "team-list" }));
|
|
log("[SEND] { path: 'team-list' }");
|
|
}
|
|
|
|
function sendRaceDatas() {
|
|
ws.send(JSON.stringify({ path: "race-datas" }));
|
|
log("[SEND] { path: 'race-datas' }");
|
|
}
|
|
|
|
function sendReset() {
|
|
ws.send(JSON.stringify({ path: "reset-sensors" }));
|
|
log("[SEND] { path: 'reset-sensors' }");
|
|
}
|
|
|
|
function clearLog() {
|
|
document.getElementById("log").textContent = "";
|
|
}
|
|
|
|
function log(msg) {
|
|
const el = document.getElementById("log");
|
|
el.textContent += msg + "\n\n";
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|