expand client
This commit is contained in:
parent
998924512c
commit
261941362e
1 changed files with 13 additions and 10 deletions
23
src/main.rs
23
src/main.rs
|
@ -133,7 +133,7 @@ async fn user_connected(ws: WebSocket, users: Users) {
|
||||||
|
|
||||||
let _ = user_ws_tx
|
let _ = user_ws_tx
|
||||||
.send(Message::text(format!(
|
.send(Message::text(format!(
|
||||||
"Server Message: Welcome User {}",
|
"Server: Welcome User {}",
|
||||||
my_id
|
my_id
|
||||||
)))
|
)))
|
||||||
.await;
|
.await;
|
||||||
|
@ -209,27 +209,30 @@ static INDEX_HTML: &str = r#"<!DOCTYPE html>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Cards</h1>
|
<h1>Cards</h1>
|
||||||
<div id="chat">
|
<div id="status">
|
||||||
<p><em>Connecting...</em></p>
|
<p><em>Connecting...</em></p>
|
||||||
</div>
|
</div>
|
||||||
|
Chat:
|
||||||
<form id="muhForm" onsubmit="onSubmit();return false">
|
<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>
|
<button type="submit" id="send">Send</button>
|
||||||
</form>
|
</form>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
const chat = document.getElementById('chat');
|
const status = document.getElementById('status');
|
||||||
const text = document.getElementById('text');
|
const history = document.getElementById('history');
|
||||||
|
history.value = "";
|
||||||
const uri = 'ws://' + location.host + '/chat';
|
const uri = 'ws://' + location.host + '/chat';
|
||||||
const ws = new WebSocket(uri);
|
const ws = new WebSocket(uri);
|
||||||
|
|
||||||
function message(data) {
|
function message(data) {
|
||||||
const line = document.createElement('p');
|
history.value = history.value + data + '\n';
|
||||||
line.innerText = data;
|
|
||||||
chat.appendChild(line);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.onopen = function() {
|
ws.onopen = function() {
|
||||||
chat.innerHTML = '<p><em>Connected!</em></p>';
|
status.innerHTML = '<p><em>Connected!</em></p>';
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onmessage = function(msg) {
|
ws.onmessage = function(msg) {
|
||||||
|
@ -237,7 +240,7 @@ static INDEX_HTML: &str = r#"<!DOCTYPE html>
|
||||||
};
|
};
|
||||||
|
|
||||||
ws.onclose = function() {
|
ws.onclose = function() {
|
||||||
chat.getElementsByTagName('em')[0].innerText = 'Disconnected!';
|
status.getElementsByTagName('em')[0].innerText = 'Disconnected!';
|
||||||
};
|
};
|
||||||
|
|
||||||
function onSubmit() {
|
function onSubmit() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue