Files
huly-platform/foundations/hulypulse/scripts/TEST_lleo.html
T
Denis Bykhov 43fb903924 Add 'foundations/hulypulse/' from commit '27e5a23ee935ac15cdfdf032cd649644390572a5'
git-subtree-dir: foundations/hulypulse
git-subtree-mainline: 64e456e0ec
git-subtree-split: 27e5a23ee9
2025-11-26 22:57:14 +05:00

130 lines
3.5 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>WebSocket JSON Tester</title>
<style>
body {
font-family: sans-serif;
background: #f5f5f5;
margin: 2em;
}
h1 {
margin-bottom: 0.5em;
}
textarea {
width: 100%;
height: 200px;
font-family: monospace;
font-size: 14px;
padding: 1em;
border: 1px solid #ccc;
border-radius: 6px;
background: #fff;
resize: vertical;
}
button {
margin-top: 1em;
padding: 0.5em 1.5em;
font-size: 16px;
border: none;
border-radius: 4px;
background: #007bff;
color: white;
cursor: pointer;
}
button:hover {
background: #0056b3;
}
#output {
margin-top: 1.5em;
padding: 1em;
background: #222;
color: #0f0;
font-family: monospace;
font-size: 14px;
border-radius: 6px;
min-height: 100px;
white-space: pre-wrap;
overflow-wrap: anywhere;
}
</style>
</head>
<body>
<h1>WebSocket JSON Tester</h1>
<textarea id="jsonInput" placeholder='{
"type": "put",
"key": "foo/bar",
"data": "hello from UI",
"correlation": "abc123"
}'></textarea>
<br />
<button onclick="sendMessage()">Send JSON</button>
<button onclick="pr('clear')">❌clear</button>
<p>
<button onclick="place()" data='{"type":"put", "key":"dnevnik/online/1", "data": "Хули", "TTL":5}'>PUT</button>
<button onclick="place()" data='{"type":"delete", "key":"dnevnik/online/1"}'>DEL 1</button>
<button onclick="place()" data='{"type":"get", "key":"dnevnik/online/"}'>LIST</button>
<button onclick="place()" data='{"type":"sub", "key":"dnevnik/online/"}'>SUB</button>
<button onclick="place()" data='{"type":"unsub", "key":"dnevnik/online/"}'>UNSUB</button>
<button onclick="place()" data='{"type":"unsub", "key":"*"}'>UNSUB *</button>
<button onclick="place()" data='{"type": "sublist" }'>SUBLIST</button>
<div id="output">Waiting for server response...</div>
<script>
const output = document.getElementById("output");
const textarea = document.getElementById("jsonInput");
function pr(s) {
if(s=="clear") return output.textContent = "";
output.textContent = s+"\n\n"+output.textContent;
}
// const workspace="00000000-0000-0000-0000-000000000001";
// let token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhY2NvdW50IjoiYWFhYWFhYWEtYmJiYi1jY2NjLWRkZGQtZWVlZWVlZWVlZWVlIiwiZXh0cmEiOnsic2VydmljZSI6ImFjY291bnQifSwid29ya3NwYWNlIjoiMDAwMDAwMDAtMDAwMC0wMDAwLTAwMDAtMDAwMDAwMDAwMDAxIn0.ZrwMvv_0CjuKeF2CkmHyMK2vHd9Ro4M3kHZcZBrBxZQ";
// let ws = new WebSocket(`ws://localhost:8095/ws?token=${token}`);
// let ws = new WebSocket(`ws://localhost:8095/ws`);
let ws = new WebSocket(`wss://hulypulse_mem.lleo.me/ws`);
ws.onopen = () => {
pr("clear");
pr("✅ WebSocket connected.");
};
ws.onmessage = (e) => {
pr(e.data);
};
ws.onerror = (e) => {
pr("❌ WebSocket error!");
console.error(e);
};
function sendMessage() {
const json = ( textarea.value || textarea.getAttribute('placeholder') ).trim();
try {
const parsed = JSON.parse(json); // validate JSON
ws.send(JSON.stringify(parsed));
pr("📤 Sent:\n" + JSON.stringify(parsed, null, 2));
} catch (e) {
pr("\n\n⚠️ Invalid JSON:\n" + e.message);
}
}
function place(event) { textarea.value = (event || window.event).target.getAttribute("data"); sendMessage(); }
</script>
</body>
</html>