-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsgi.py
executable file
·31 lines (24 loc) · 982 Bytes
/
wsgi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from app import ROSVideoStreamFlask
from flask import Flask, Response, render_template, jsonify
app = Flask(__name__)
stream = ROSVideoStreamFlask()
@app.route("/")
def home():
return render_template("index.html", camera_list=stream.get_camera_list())
@app.route("/.json")
def show_camera_urls():
camera_urls = {camera:camera + "-color-image_raw-compressed" for camera in stream.get_camera_list()}
response = jsonify(dict(sorted(camera_urls.items())))
response.headers.add('Access-Control-Allow-Origin', '*')
return response
@app.route("/<topic>")
def show_video(topic):
topic = "/" + topic.replace("-", "/")
response = Response(stream.gen(topic), mimetype="multipart/x-mixed-replace; boundary=frame")
response.headers.add('Access-Control-Allow-Origin', '*')
return response
if __name__ == "__main__":
try:
app.run(host="0.0.0.0", threaded=True, debug=False)
except KeyboardInterrupt:
stream.client.terminate()