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')
|
||||
def handle_join(data):
|
||||
print(f"Received join event: {data}")
|
||||
username = data.get('username')
|
||||
chat_room = data.get('chat_room', 'default')
|
||||
|
||||
if not username:
|
||||
emit('error', {'message': 'Username is required'})
|
||||
return
|
||||
|
||||
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')
|
||||
def handle_leave(data):
|
||||
|
|
@ -145,10 +151,15 @@ def handle_leave(data):
|
|||
|
||||
@socketio.on('send_message')
|
||||
def handle_send_message(data):
|
||||
print(f"Received send_message event: {data}")
|
||||
username = data.get('username')
|
||||
chat_room = data.get('chat_room', 'default')
|
||||
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
|
||||
if chat_room not in message_history:
|
||||
message_history[chat_room] = []
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue