Exemplo n.º 1
0
    async def get(self):
        ws = WebSocketResponse()
        await ws.prepare(self.request)
        session = await get_session(self.request)
        user = await self.request.app.db['users'].find_one({'_id': ObjectId(session['user_id'])})
        ws.username = user['username']
        ws.lot_id = session['lot_id']
        self.request.app.wslist.append(ws)

        async for bet in ws:
            data = json.loads(bet.data)
            for websocket_connection in self.request.app.wslist:
                if websocket_connection.lot_id == data['lot_id']:
                    await websocket_connection.send_str(f"{user['username']}: {data['my_bet_text']}")

        self.request.app.wslist.remove(ws)

        return ws