Compare commits

...

2 commits

Author SHA1 Message Date
Adam
b82a0f32c7 expand client 2024-04-29 02:18:20 -04:00
Adam
7341a8802f fix tracing 2024-04-29 02:18:07 -04:00
2 changed files with 35 additions and 34 deletions

View file

@ -76,7 +76,7 @@ async fn main() {
tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| "example_chat=trace".into()),
.unwrap_or_else(|_| "cards=trace".into()),
)
.with(tracing_subscriber::fmt::layer())
.init();

View file

@ -12,45 +12,46 @@
</head>
<body>
<h1>Cards For Humanity Test Client</h1>
<div id="status">
<p><em>Disconnected...</em></p>
</div>
<form id="login" onsubmit="loginSubmit();return false">
<input id="username" style="display:block; width:100px; box-sizing: border-box" type="text" placeholder="username">
<button id="join-chat" type="button">Join Chat</button>
<textarea id="chat" style="display:block; width:600px; height:400px; box-sizing: border-box" cols="30" rows="10"></textarea>
<input id="input" style="display:block; width:600px; box-sizing: border-box" type="text" placeholder="chat">
<button id="join-chat" type="submit">Join Chat</button>
</form>
<form id="chat" onsubmit="chatSubmit();return false">
<textarea id="chat-history" style="display:block; width:600px; height:400px; box-sizing: border-box" cols="30" rows="10"></textarea>
<input id="chat-input" style="display:block; width:600px; box-sizing: border-box" type="text" placeholder="chat">
</form>
<script type="text/javascript">
const username = document.querySelector("#username");
const join_btn = document.querySelector("#join-chat");
const textarea = document.querySelector("#chat");
const input = document.querySelector("#input");
websocket = new WebSocket("ws://localhost:3030/websocket");
join_btn.addEventListener("click", function(e) {
this.disabled = true;
const websocket = new WebSocket("ws://localhost:3000/websocket");
function loginSubmit() {
document.getElementById("join-chat").disabled = true;
websocket.send(username.value);
};
websocket.onopen = function() {
console.log("connection opened");
websocket.send(username.value);
document.getElementById("status").innerHTML = '<p><em>Connected!</em></p>';
}
const btn = this;
websocket.onclose = function() {
console.log("connection closed");
btn.disabled = false;
// document.getElementById("join-chat").disabled = false;
document.getElementById("status").innerHTML = '<p><em>Disconnected...</em></p>';
}
websocket.onmessage = function(e) {
console.log("received message: "+e.data);
textarea.value += e.data+"\r\n";
document.getElementById("chat-history").value += e.data+"\r\n";
}
input.onkeydown = function(e) {
if (e.key == "Enter") {
function chatSubmit() {
let input = document.getElementById("chat-input");
websocket.send(input.value);
input.value = "";
}
}
});
};
</script>
</body>
</html>