mirror of
https://github.com/LukeHagar/crossws.git
synced 2025-12-06 04:19:26 +00:00
29 lines
734 B
HTML
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>
|