refactoring and cleanup

This commit is contained in:
2023-05-19 08:07:36 +02:00
parent 24f2758f16
commit 9c96a4e12a
33 changed files with 50 additions and 42 deletions

View File

@ -0,0 +1,69 @@
<html>
<body>
<input type="text" size="20" id="websocket" placeholde="websocket url" value="wss://cloudvars.br0tkasten.de">
<input type="text" size="20" id="projectID" placeholder="project_id" value="p4-@cloud.sb3">
<button id="read" name="read">read</button>
<ul id="data"></ul>
<script src="https://code.jquery.com/jquery-3.6.3.min.js"></script>
<script>
let socket;
let projectID;
$("#read").click(function() {
$("#data").empty();
projectID = $("#projectID").val();
socket = new WebSocket($("#websocket").val());
socket.onopen = function(e) {
console.log("connection established");
socket.send(JSON.stringify({
method: "handshake",
project_id: projectID,
user: "testClient"+Math.random()
}));
};
function setVariable(name, value) {
console.log(`Setting variable: ${name} = ${value}`);
socket.send(JSON.stringify({
method: "set",
// project_id: projectID,
name,
value
}));
};
socket.onmessage = function(event) {
console.log(event.data);
for (const message of event.data.split("\n")) {
console.log(`${message}`);
const obj = JSON.parse(message);
if (obj.method === "set") {
obj_id = obj.name.replace(/[^0-9A-Za-z]/g,'_');
console.log(obj_id + ":" + $(`#${obj_id}`).length)
if($(`#${obj_id}`).length > 0) {
$(`#${obj_id}`).html(`<b>${obj.name}:</b> ${obj.value}`);
} else {
$('#data').append(`<li id="${obj_id}"><b/>${obj.name}:</b>${obj.value}</li>`);
}
}
}
};
socket.onclose = function(event) {
if (event.wasClean) {
console.log(`connection closed cleanly, code=${event.code} reason=${event.reason}`);
} else {
console.log('connection died');
}
};
socket.onerror = function(error) {
console.log(`[error] ${error.data}`);
};
});
</script>
</body>
</html>

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 KiB

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 496 KiB