expand client

This commit is contained in:
Adam 2024-04-27 06:00:26 -04:00
parent 998924512c
commit 261941362e

View file

@ -133,7 +133,7 @@ async fn user_connected(ws: WebSocket, users: Users) {
let _ = user_ws_tx
.send(Message::text(format!(
"Server Message: Welcome User {}",
"Server: Welcome User {}",
my_id
)))
.await;
@ -209,27 +209,30 @@ static INDEX_HTML: &str = r#"<!DOCTYPE html>
</head>
<body>
<h1>Cards</h1>
<div id="chat">
<div id="status">
<p><em>Connecting...</em></p>
</div>
Chat:
<form id="muhForm" onsubmit="onSubmit();return false">
<input type="text" id="text" autocomplete="off" />
<textarea id="history" readonly="true" wrap="soft" style="width: 80%; height: 10rem;"></textarea>
<br />
<input type="text" id="text" autocomplete="off" style="width: 80%;" />
<br />
<button type="submit" id="send">Send</button>
</form>
<script type="text/javascript">
const chat = document.getElementById('chat');
const text = document.getElementById('text');
const status = document.getElementById('status');
const history = document.getElementById('history');
history.value = "";
const uri = 'ws://' + location.host + '/chat';
const ws = new WebSocket(uri);
function message(data) {
const line = document.createElement('p');
line.innerText = data;
chat.appendChild(line);
history.value = history.value + data + '\n';
}
ws.onopen = function() {
chat.innerHTML = '<p><em>Connected!</em></p>';
status.innerHTML = '<p><em>Connected!</em></p>';
};
ws.onmessage = function(msg) {
@ -237,7 +240,7 @@ static INDEX_HTML: &str = r#"<!DOCTYPE html>
};
ws.onclose = function() {
chat.getElementsByTagName('em')[0].innerText = 'Disconnected!';
status.getElementsByTagName('em')[0].innerText = 'Disconnected!';
};
function onSubmit() {