-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-whiteboard.html
More file actions
70 lines (61 loc) · 1.87 KB
/
test-whiteboard.html
File metadata and controls
70 lines (61 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html>
<head>
<title>Whiteboard WebSocket Test</title>
</head>
<body>
<h1>Whiteboard WebSocket Test</h1>
<div id="status">Connecting...</div>
<button onclick="sendTestDraw()">Send Test Draw</button>
<div id="messages"></div>
<script>
const ws = new WebSocket(
"ws://localhost:5000/ws?roomId=test&username=testuser"
);
const statusDiv = document.getElementById("status");
const messagesDiv = document.getElementById("messages");
ws.onopen = function () {
statusDiv.textContent = "Connected!";
statusDiv.style.color = "green";
};
ws.onerror = function (error) {
statusDiv.textContent = "Connection Error: " + JSON.stringify(error);
statusDiv.style.color = "red";
};
ws.onclose = function () {
statusDiv.textContent = "Connection Closed";
statusDiv.style.color = "orange";
};
ws.onmessage = function (event) {
const message = JSON.parse(event.data);
const messageDiv = document.createElement("div");
messageDiv.textContent = `Received: ${
message.action
} - ${JSON.stringify(message.payload)}`;
messagesDiv.appendChild(messageDiv);
if (message.action === "WELCOME") {
console.log("Welcome state:", message.payload.state);
}
};
function sendTestDraw() {
const testElements = [
{
id: "test-1",
type: "path",
path: "M10,10 L50,50",
stroke: "#ffffff",
strokeWidth: 2,
fill: "none",
},
];
ws.send(
JSON.stringify({
action: "WHITEBOARD_DRAW",
payload: { elements: testElements },
})
);
console.log("Sent test whiteboard draw:", testElements);
}
</script>
</body>
</html>