Server: send test messages after init

This commit is contained in:
Lexi / Zoe 2018-11-24 02:10:33 +01:00
parent 635b44fff3
commit 733a537f58
1 changed files with 20 additions and 1 deletions

View File

@ -32,8 +32,13 @@ async def handle_client_init(websocket, message):
"""Handle client 'init' message."""
print(f"< init: chat_id='{message['chat_id']}', nickname='{message['nickname']}'")
await send_client_init_response(websocket)
await send_client_previous_messages(websocket)
async def send_client_init_response(websocket):
"""Send an init response message to a newly connected client."""
# Send response to client
response = json.dumps({
'type': 'init'
})
@ -41,6 +46,20 @@ async def handle_client_init(websocket, message):
await websocket.send(response)
async def send_client_previous_messages(websocket):
"""Sends previously written chat messages to a newly connected client."""
# For now: send test messages
for i in range(1, 4):
testmsg = json.dumps({
'type': 'message',
'from': 'Alice',
'text': f"Message number {i}, hello!"
})
print(f"> {testmsg}")
await websocket.send(testmsg)
async def client_handler(websocket, path):
"""Handle client connection."""