mirror of
https://github.com/blakeblackshear/frigate.git
synced 2024-11-21 19:07:46 +01:00
simple echo websocket working
This commit is contained in:
parent
69cab1e6bb
commit
22461d1728
@ -34,7 +34,10 @@ RUN apt-get -qq update \
|
||||
RUN pip3 install \
|
||||
peewee_migrate \
|
||||
zeroconf \
|
||||
voluptuous
|
||||
voluptuous\
|
||||
Flask-Sockets \
|
||||
gevent \
|
||||
gevent-websocket
|
||||
|
||||
COPY nginx/nginx.conf /etc/nginx/nginx.conf
|
||||
|
||||
|
@ -8,6 +8,8 @@ import sys
|
||||
import signal
|
||||
|
||||
import yaml
|
||||
from gevent import pywsgi
|
||||
from geventwebsocket.handler import WebSocketHandler
|
||||
from peewee_migrate import Router
|
||||
from playhouse.sqlite_ext import SqliteExtDatabase
|
||||
from playhouse.sqliteq import SqliteQueueDatabase
|
||||
@ -106,8 +108,8 @@ class FrigateApp():
|
||||
for log, level in self.config.logger.logs.items():
|
||||
logging.getLogger(log).setLevel(level)
|
||||
|
||||
if not 'werkzeug' in self.config.logger.logs:
|
||||
logging.getLogger('werkzeug').setLevel('ERROR')
|
||||
if not 'geventwebsocket.handler' in self.config.logger.logs:
|
||||
logging.getLogger('geventwebsocket.handler').setLevel('ERROR')
|
||||
|
||||
def init_queues(self):
|
||||
# Queues for clip processing
|
||||
@ -239,7 +241,9 @@ class FrigateApp():
|
||||
|
||||
signal.signal(signal.SIGTERM, receiveSignal)
|
||||
|
||||
self.flask_app.run(host='127.0.0.1', port=5001, debug=False)
|
||||
server = pywsgi.WSGIServer(('127.0.0.1', 5001), self.flask_app, handler_class=WebSocketHandler)
|
||||
server.serve_forever()
|
||||
|
||||
self.stop()
|
||||
|
||||
def stop(self):
|
||||
|
@ -9,6 +9,7 @@ import cv2
|
||||
import numpy as np
|
||||
from flask import (Blueprint, Flask, Response, current_app, jsonify,
|
||||
make_response, request)
|
||||
from flask_sockets import Sockets
|
||||
from peewee import SqliteDatabase, operator, fn, DoesNotExist
|
||||
from playhouse.shortcuts import model_to_dict
|
||||
|
||||
@ -21,9 +22,11 @@ from frigate.version import VERSION
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
bp = Blueprint('frigate', __name__)
|
||||
ws = Blueprint('ws', __name__)
|
||||
|
||||
def create_app(frigate_config, database: SqliteDatabase, stats_tracking, detected_frames_processor):
|
||||
app = Flask(__name__)
|
||||
sockets = Sockets(app)
|
||||
|
||||
@app.before_request
|
||||
def _db_connect():
|
||||
@ -39,6 +42,7 @@ def create_app(frigate_config, database: SqliteDatabase, stats_tracking, detecte
|
||||
app.detected_frames_processor = detected_frames_processor
|
||||
|
||||
app.register_blueprint(bp)
|
||||
sockets.register_blueprint(ws)
|
||||
|
||||
return app
|
||||
|
||||
@ -304,3 +308,9 @@ def imagestream(detected_frames_processor, camera_name, fps, height, draw_option
|
||||
ret, jpg = cv2.imencode('.jpg', frame, [int(cv2.IMWRITE_JPEG_QUALITY), 70])
|
||||
yield (b'--frame\r\n'
|
||||
b'Content-Type: image/jpeg\r\n\r\n' + jpg.tobytes() + b'\r\n\r\n')
|
||||
|
||||
@ws.route('/ws')
|
||||
def echo_socket(socket):
|
||||
while not socket.closed:
|
||||
message = socket.receive()
|
||||
socket.send(message)
|
||||
|
@ -102,6 +102,14 @@ http {
|
||||
root /media/frigate;
|
||||
}
|
||||
|
||||
location /ws {
|
||||
proxy_pass http://frigate_api/ws;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "Upgrade";
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
location /api/ {
|
||||
add_header 'Access-Control-Allow-Origin' '*';
|
||||
add_header Cache-Control "no-store";
|
||||
|
Loading…
Reference in New Issue
Block a user