Files
crossws/playground/public/index.html
2024-01-29 02:11:00 +01:00

29 lines
734 B
HTML

<!doctype html>
<head>
<title>CrossWS Test Page</title>
</head>
<body>
<div id="logs"></div>
<script type="module">
const url = `ws://${location.host}/_ws`;
const logsEl = document.querySelector("#logs");
const log = (...args) => {
console.log("[ws]", ...args);
logsEl.innerHTML += `<p>[${new Date().toJSON()}] ${args.join(" ")}</p>`;
};
log(`Connecting to "${url}""...`);
const ws = new WebSocket(url);
ws.addEventListener("message", (event) => {
log("Message from server:", event.data);
});
log("Waiting for connection...");
await new Promise((resolve) => ws.addEventListener("open", resolve));
log("Sending ping...");
ws.send("ping");
</script>
</body>