Commit 8ced7b9f authored by Torsten Grote's avatar Torsten Grote

Switch to new websocket authentication method

parent 045ee489
......@@ -28,24 +28,27 @@ def main():
threading.Thread(target=get_message_stdin, args=[auth_token]).start()
loop = asyncio.get_event_loop()
loop.create_task(get_message_websocket(auth_token))
loop.create_task(connect_websocket(auth_token))
loop.run_forever()
loop.close()
async def get_message_websocket(token):
url = URL_WS.replace('ws://', 'ws://%s@' % token)
async with websockets.connect(url) as ws:
while not ws.closed and not asyncio.get_event_loop().is_closed():
message = await ws.recv()
m = json.loads(message)
if m['name'] == 'org.briarproject.briar.api.messaging' + \
'.event.PrivateMessageReceivedEvent':
print() # line-break
print_message(m['data'])
print(PROMPT, end='', flush=True)
if not asyncio.get_event_loop().is_closed():
asyncio.get_event_loop().create_task(get_message_websocket(token))
async def connect_websocket(token):
async with websockets.connect(URL_WS) as ws:
await ws.send(token)
await get_message_websocket(ws)
async def get_message_websocket(ws):
while not ws.closed and not asyncio.get_event_loop().is_closed():
message = await ws.recv()
m = json.loads(message)
if m['name'] == 'ConversationMessageReceivedEvent':
print() # line-break
print_message(m['data'])
print(PROMPT, end='', flush=True)
if not asyncio.get_event_loop().is_closed():
asyncio.get_event_loop().create_task(get_message_websocket(ws))
def get_message_stdin(token):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment