aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYingtong Li <runassudo@yingtongli.me>2017-03-28 19:24:00 +1100
committerYingtong Li <runassudo@yingtongli.me>2017-03-28 19:24:33 +1100
commit16f5bb5834460a9cff32591e1e904a933e195d19 (patch)
treeda9279dfe0558386b0f93003c5001bed24cf1cbe
parentd50c7b9d32f1c16a752bca4eed8341570df9168a (diff)
Switch to eventlet
-rw-r--r--pblive/__init__.py11
-rw-r--r--pblive/templates/admin_session.html2
-rw-r--r--pblive/templates/session.html2
-rw-r--r--requirements.txt17
4 files changed, 28 insertions, 4 deletions
diff --git a/pblive/__init__.py b/pblive/__init__.py
index 63b9d8f..cc5770a 100644
--- a/pblive/__init__.py
+++ b/pblive/__init__.py
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import eventlet
import flask
import flask_socketio
@@ -25,6 +26,8 @@ import socket
import sys
import yaml
+eventlet.monkey_patch()
+
app = flask.Flask('pblive')
app.jinja_env.globals['data'] = pblive.data
@@ -41,7 +44,7 @@ for f in os.listdir('data'):
if f.endswith('.yaml') and not f.startswith('.'):
session_name = f[:-5]
with open(os.path.join('data', f)) as fh:
- pblive.data.sessions[session_name] = data.Session.from_dict(yaml.load(fh), session_name)
+ pblive.data.sessions[session_name] = pblive.data.Session.from_dict(yaml.load(fh), session_name)
@app.route('/')
def index():
@@ -73,7 +76,7 @@ def socket_join(session_name):
app.logger.debug('New client {} connected'.format(flask.request.sid))
session = pblive.data.sessions[session_name]
- user = data.User(sid=flask.request.sid, session=session)
+ user = pblive.data.User(sid=flask.request.sid, session=session)
pblive.data.users[flask.request.sid] = user
# Send initial colour picker
@@ -224,3 +227,7 @@ def socket_pass_question():
if admin.session == user.session:
flask_socketio.emit('update', render_question_admin(admin.session, admin.session.question_num), room=admin.sid)
flask_socketio.emit('update_left', render_sidebar(admin, user.session), room=admin.sid)
+
+# Start server
+if __name__ == '__main__':
+ socketio.run(app, host='0.0.0.0')
diff --git a/pblive/templates/admin_session.html b/pblive/templates/admin_session.html
index efa944d..00e4c8e 100644
--- a/pblive/templates/admin_session.html
+++ b/pblive/templates/admin_session.html
@@ -28,7 +28,7 @@
<script src="{{ url_for('static', filename='vendor/socket-io/socket.io.min.js') }}"></script>
<script>
var session_name = '{{ session.name }}';
- var socket = io.connect('http://' + document.domain + ':' + location.port);
+ var socket = io.connect('ws://' + document.domain + ':' + location.port);
socket.on('connect', function() {
socket.emit('join_admin', session_name);
});
diff --git a/pblive/templates/session.html b/pblive/templates/session.html
index f139a8b..07169ed 100644
--- a/pblive/templates/session.html
+++ b/pblive/templates/session.html
@@ -28,7 +28,7 @@
<script src="{{ url_for('static', filename='vendor/socket-io/socket.io.min.js') }}"></script>
<script>
var session_name = '{{ session.name }}';
- var socket = io.connect('http://' + document.domain + ':' + location.port);
+ var socket = io.connect('ws://' + document.domain + ':' + location.port);
socket.on('connect', function() {
socket.emit('join', session_name);
});
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..f7311ca
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,17 @@
+appdirs==1.4.3
+click==6.7
+enum-compat==0.0.2
+eventlet==0.20.1
+Flask==0.12
+Flask-SocketIO==2.8.5
+greenlet==0.4.12
+itsdangerous==0.24
+Jinja2==2.9.5
+MarkupSafe==1.0
+packaging==16.8
+pyparsing==2.2.0
+python-engineio==1.3.0
+python-socketio==1.7.2
+PyYAML==3.12
+six==1.10.0
+Werkzeug==0.12
Contact (issues, pull requests, etc.) at git@yingtongli.me. Generated by cgit.