How do receive stream from flask server (sent via yield) with axios (react frontend)

454 views Asked by At

I'm sending the stream of data from flask server via yield. I'm able to see this stream if I go directly to api url. However I don't know how to receive it on frontend. I would appreciate the help. Here is how my backend looks like:

STREAM

`

def redis_stream():
    global lock
       channel = r.pubsub()
       channel.subscribe('CellGridMapClose')
       for msg in channel.listen():   
          if msg['type'] == 'message': 
                   obj = tm.CellGridMapping()
                   obj.ParseFromString(msg['data'])
                   objects = obj.objects
                   movement = []
                   for vehicle in objects:
                      x, y = vehicle.pos.x, vehicle.pos.y
                      movement.append({'posx': x/50, 'posy': y/40})
                   yield bytes(json.dumps(movement), 'utf-8')

` ROUTE

`

@app.route('/redis-stream')
def redis_data():
   return Response(redis_stream(), mimetype='application/json') 

`

This is how my frontend looks. I've tried many variants. This is the last one, however it's not working

FRONTEND

`

const response = await axios.get("/redis-stream", {responseType: 'arraybuffer'});;
    console.log(response.data);

`

0

There are 0 answers