Exemple #1
0
async def message_updates(ws: WebSocket, username: str):
    await ws.accept()
    challenge = pyotp.random_base32()
    await ws.send_json({"type": "CHALLENGE", "payload": challenge})
    # TODO CHECK THIS SHIT
    # resp = await ws.receive_text()
    # print(f"RESP: {resp}")
    async with lock:
        sessions[username] = ws
        print(sessions.keys())
    # valid = verify_signature(username, challenge, resp)
    valid = True
    if not valid:
        ws.send_text("thats not cool bro")
        ws.close()
        return

    while True:
        data = await ws.receive_text()
Exemple #2
0
async def ping_task(
        ws: WebSocket):  # ping task to find crit disconected clients
    while True:
        try:
            await asyncio.wait_for(
                ws.send_text(
                    Answer(None, ACTION_LIST["ping"]).get_ret_object()),
                timeout=5,
            )
            await asyncio.sleep(30)

        except BaseException:
            try:
                await ws.close()
            except BaseException:
                pass
            return