-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-ws.html
More file actions
64 lines (55 loc) · 2.01 KB
/
debug-ws.html
File metadata and controls
64 lines (55 loc) · 2.01 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
<!DOCTYPE html>
<html>
<head>
<title>WebSocket Debug Test</title>
</head>
<body>
<h1>WebSocket Debug Test</h1>
<div id="status">Testing...</div>
<div id="messages"></div>
<script>
const statusDiv = document.getElementById("status");
const messagesDiv = document.getElementById("messages");
function addMessage(msg) {
const div = document.createElement("div");
div.textContent = new Date().toLocaleTimeString() + ": " + msg;
messagesDiv.appendChild(div);
}
// Test WebSocket connection like the frontend does
const protocol = window.location.protocol === "https:" ? "wss" : "ws";
const isDevelopment =
window.location.hostname === "localhost" &&
window.location.port === "3000";
const wsHost = isDevelopment ? "localhost:5000" : window.location.host;
const wsUrl = `${protocol}://${wsHost}/ws?roomId=debug&username=debuguser`;
addMessage(`Connecting to: ${wsUrl}`);
addMessage(`Development mode: ${isDevelopment}`);
addMessage(
`Host: ${window.location.hostname}, Port: ${window.location.port}`
);
const ws = new WebSocket(wsUrl);
ws.onopen = function () {
statusDiv.textContent = "Connected!";
statusDiv.style.color = "green";
addMessage("WebSocket connection opened successfully");
};
ws.onerror = function (error) {
statusDiv.textContent = "Error!";
statusDiv.style.color = "red";
addMessage(`WebSocket error: ${JSON.stringify(error)}`);
addMessage(`Error type: ${error.type}`);
addMessage(`Error target: ${error.target.readyState}`);
};
ws.onclose = function (event) {
statusDiv.textContent = "Closed";
statusDiv.style.color = "orange";
addMessage(
`WebSocket closed: code=${event.code}, reason=${event.reason}`
);
};
ws.onmessage = function (event) {
addMessage(`Received: ${event.data}`);
};
</script>
</body>
</html>