Modify the selfhosted webclient. Tried to fix the errors? The server has been modified too to try and compensate for errors.
This commit is contained in:
parent
dab35d9832
commit
44cdbde003
2 changed files with 21 additions and 1 deletions
|
|
@ -131,10 +131,16 @@ def handle_disconnect():
|
||||||
|
|
||||||
@socketio.on('join')
|
@socketio.on('join')
|
||||||
def handle_join(data):
|
def handle_join(data):
|
||||||
|
print(f"Received join event: {data}")
|
||||||
username = data.get('username')
|
username = data.get('username')
|
||||||
chat_room = data.get('chat_room', 'default')
|
chat_room = data.get('chat_room', 'default')
|
||||||
|
|
||||||
|
if not username:
|
||||||
|
emit('error', {'message': 'Username is required'})
|
||||||
|
return
|
||||||
|
|
||||||
join_room(chat_room)
|
join_room(chat_room)
|
||||||
emit('message', {'message': f"{username} has joined the chat room '{chat_room}'."}, room=chat_room)
|
emit('message', {'username': 'Server', 'message': f"{username} has joined the chat room '{chat_room}'."}, room=chat_room)
|
||||||
|
|
||||||
@socketio.on('leave')
|
@socketio.on('leave')
|
||||||
def handle_leave(data):
|
def handle_leave(data):
|
||||||
|
|
@ -145,10 +151,15 @@ def handle_leave(data):
|
||||||
|
|
||||||
@socketio.on('send_message')
|
@socketio.on('send_message')
|
||||||
def handle_send_message(data):
|
def handle_send_message(data):
|
||||||
|
print(f"Received send_message event: {data}")
|
||||||
username = data.get('username')
|
username = data.get('username')
|
||||||
chat_room = data.get('chat_room', 'default')
|
chat_room = data.get('chat_room', 'default')
|
||||||
message = data.get('message')
|
message = data.get('message')
|
||||||
|
|
||||||
|
if not username or not message:
|
||||||
|
emit('error', {'message': 'Username and message are required'})
|
||||||
|
return
|
||||||
|
|
||||||
# Store the message in the chat room's history
|
# Store the message in the chat room's history
|
||||||
if chat_room not in message_history:
|
if chat_room not in message_history:
|
||||||
message_history[chat_room] = []
|
message_history[chat_room] = []
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,8 @@
|
||||||
let username = prompt("Enter your username:");
|
let username = prompt("Enter your username:");
|
||||||
let chatRoom = prompt("Enter chat room (default: 'default')") || 'default';
|
let chatRoom = prompt("Enter chat room (default: 'default')") || 'default';
|
||||||
|
|
||||||
|
// Log the join event data
|
||||||
|
console.log('Joining chat room:', { username: username, chat_room: chatRoom });
|
||||||
// Join the chat room
|
// Join the chat room
|
||||||
socket.emit('join', { username: username, chat_room: chatRoom });
|
socket.emit('join', { username: username, chat_room: chatRoom });
|
||||||
|
|
||||||
|
|
@ -65,10 +67,17 @@
|
||||||
function sendMessage() {
|
function sendMessage() {
|
||||||
const message = messageInput.value;
|
const message = messageInput.value;
|
||||||
if (message.trim() !== '') {
|
if (message.trim() !== '') {
|
||||||
|
// Log the send_message event data
|
||||||
|
console.log('Sending message:', { username: username, chat_room: chatRoom, message: message });
|
||||||
socket.emit('send_message', { username: username, chat_room: chatRoom, message: message });
|
socket.emit('send_message', { username: username, chat_room: chatRoom, message: message });
|
||||||
messageInput.value = ''; // Clear the input field
|
messageInput.value = ''; // Clear the input field
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log the send_message event data
|
||||||
|
console.log('Sending message:', { username: username, chat_room: chatRoom, message: message });
|
||||||
|
// Send a message to the server
|
||||||
|
socket.emit('send_message', { username: username, chat_room: chatRoom, message: message });
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue