add janus check

This commit is contained in:
petrucci4prez 2017-05-25 02:40:36 -04:00
parent 8e90bd209c
commit 7460b007ce
1 changed files with 15 additions and 8 deletions

View File

@ -1,10 +1,12 @@
import logging import logging
from auxilary import async from subprocess import check_output, CalledProcessError
from flask import Flask, render_template, Response, Blueprint, redirect, url_for from flask import Flask, render_template, Response, Blueprint, redirect, url_for
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from wtforms.fields import StringField, SubmitField from wtforms.fields import StringField, SubmitField
from wtforms.validators import InputRequired from wtforms.validators import InputRequired
from auxilary import async
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
# gag the flask logger unless it has something useful to say # gag the flask logger unless it has something useful to say
@ -18,6 +20,10 @@ class TTSForm(FlaskForm):
# TODO: fix random connection fails (might be an nginx thing) # TODO: fix random connection fails (might be an nginx thing)
@async(daemon=True) @async(daemon=True)
def _runApp(a):
logger.info('Starting web interface')
a.run(debug=False, threaded=True)
def initWebInterface(stateMachine): def initWebInterface(stateMachine):
siteRoot = Blueprint('siteRoot', __name__, static_folder='static', static_url_path='') siteRoot = Blueprint('siteRoot', __name__, static_folder='static', static_url_path='')
@ -28,7 +34,6 @@ def initWebInterface(stateMachine):
if ttsForm.validate_on_submit() and ttsForm.submitTTS.data: if ttsForm.validate_on_submit() and ttsForm.submitTTS.data:
stateMachine.soundLib.speak(ttsForm.tts.data) stateMachine.soundLib.speak(ttsForm.tts.data)
#~ ttsQueue.put_nowait(ttsForm.tts.data)
return redirect(url_for('siteRoot.index')) return redirect(url_for('siteRoot.index'))
return render_template( return render_template(
@ -37,12 +42,14 @@ def initWebInterface(stateMachine):
state=stateMachine.currentState state=stateMachine.currentState
) )
try:
check_output(['pidof', 'janus'])
except CalledProcessError:
logger.critical('Janus not running. Aborting')
raise SystemExit
app = Flask(__name__) app = Flask(__name__)
app.secret_key = '3276d68dac56985bea352325125641ff' app.secret_key = '3276d68dac56985bea352325125641ff'
app.register_blueprint(siteRoot, url_prefix='/pyledriver') app.register_blueprint(siteRoot, url_prefix='/pyledriver')
# TODO: not sure exactly how threaded=True works, intended to enable _runApp(app)
# multiple connections. May want to use something more robust w/ camera
# see here: https://blog.miguelgrinberg.com/post/video-streaming-with-flask
logger.info('Starting web interface')
app.run(debug=False, threaded=True)