MCPcopy Create free account
hub / github.com/SiddhantSilwal/RaspberryPi-GPIO-Web-Controller / event_stream

Function event_stream

AppData/app.py:503–525  ·  view source on GitHub ↗

Server-Sent Events endpoint for real-time updates

()

Source from the content-addressed store, hash-verified

501
502@app.route('/api/events')
503def event_stream():
504 """Server-Sent Events endpoint for real-time updates"""
505 def generate():
506 try:
507 while True:
508 try:
509 # Wait for events with timeout
510 event = event_queue.get(timeout=30)
511 yield f"data: {json.dumps(event)}\n\n"
512 except queue.Empty:
513 # Send heartbeat to keep connection alive
514 yield f"data: {json.dumps({'type': 'heartbeat'})}\n\n"
515 except Exception as e:
516 yield f"data: {json.dumps({'type': 'error', 'message': str(e)})}\n\n"
517 break
518 except GeneratorExit:
519 pass
520
521 return Response(generate(), mimetype='text/plain', headers={
522 'Cache-Control': 'no-cache',
523 'Connection': 'keep-alive',
524 'Access-Control-Allow-Origin': '*'
525 })
526
527@app.route('/api/graph/stream', methods=['POST'])
528def graph_stream():

Callers

nothing calls this directly

Calls 1

generateFunction · 0.85

Tested by

no test coverage detected