25 lines
501 B
JavaScript
25 lines
501 B
JavaScript
|
function log(text) {
|
|||
|
document.getElementById("log").innerText += text + "\n";
|
|||
|
}
|
|||
|
|
|||
|
log("Connecting");
|
|||
|
const ws = new WebSocket(`wss://${location.host}/`, "test");
|
|||
|
function send(text) {
|
|||
|
log(">> " + text);
|
|||
|
ws.send(text);
|
|||
|
}
|
|||
|
ws.onerror = (e) => {
|
|||
|
log("Error");
|
|||
|
throw e;
|
|||
|
};
|
|||
|
ws.onopen = (event) => {
|
|||
|
log("Connected");
|
|||
|
send("Hello world");
|
|||
|
};
|
|||
|
ws.onclose = (event) => {
|
|||
|
log("Closed");
|
|||
|
};
|
|||
|
ws.onmessage = (event) => {
|
|||
|
log("<< " + event.data);
|
|||
|
console.log(event.data);
|
|||
|
};
|