parent
38b3239d91
commit
5e0705149f
@ -1,36 +0,0 @@ |
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<title>WebSocket Test</title> |
||||
</head> |
||||
<body> |
||||
<h1>WebSocket Test</h1> |
||||
<input id="messageInput" type="text"> |
||||
<button onclick="sendMessage()">Send</button> |
||||
<div id="messages"></div> |
||||
|
||||
<script> |
||||
const chatSocket = new WebSocket( |
||||
'ws://' + window.location.host + '/ws/sync/' |
||||
); |
||||
|
||||
chatSocket.onmessage = function(e) { |
||||
const data = JSON.parse(e.data); |
||||
document.querySelector('#messages').innerHTML += '<p>' + data.message + '</p>'; |
||||
}; |
||||
|
||||
chatSocket.onclose = function(e) { |
||||
console.error('Chat socket closed unexpectedly'); |
||||
}; |
||||
|
||||
function sendMessage() { |
||||
const messageInputDom = document.querySelector('#messageInput'); |
||||
const message = messageInputDom.value; |
||||
chatSocket.send(JSON.stringify({ |
||||
'message': message |
||||
})); |
||||
messageInputDom.value = ''; |
||||
} |
||||
</script> |
||||
</body> |
||||
</html> |
||||
Loading…
Reference in new issue