Skip to content

Commit

Permalink
feat(artusx-websocket): update client ui
Browse files Browse the repository at this point in the history
  • Loading branch information
thonatos committed Jun 21, 2024
1 parent ab90825 commit 86af21b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/apps/artusx-websocket/src/view/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,25 @@
const input = document.getElementById('input');
const messages = document.getElementById('messages');

const appendMsg = (msg, from = 'default') => {
const item = document.createElement('li');
item.textContent = `${from}: ${msg}`;
messages.appendChild(item);
window.scrollTo(0, document.body.scrollHeight);
};

form.addEventListener('submit', (e) => {
e.preventDefault();
if (input.value) {
socket.emit('chat_message', input.value);
appendMsg(input.value, 'client');
input.value = '';
}
});

socket.on('chat_message', (msg) => {
console.log('chat_message', msg);
const item = document.createElement('li');
item.textContent = msg;
messages.appendChild(item);
window.scrollTo(0, document.body.scrollHeight);
appendMsg(msg, 'server');
});
</script>
</body>
Expand Down

0 comments on commit 86af21b

Please sign in to comment.