From c96f86e0564ace0fc85a84850b2a1bc051be95e2 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 22 Mar 2022 04:35:12 +0200 Subject: [PATCH] chat --- files/routes/chat.py | 24 +++- files/templates/chat.html | 240 ++++++++++++++++++++++++++--------- files/templates/default.html | 2 +- requirements.txt | 1 + supervisord.conf | 2 +- 5 files changed, 207 insertions(+), 62 deletions(-) diff --git a/files/routes/chat.py b/files/routes/chat.py index 57892b816..3d4eaa752 100644 --- a/files/routes/chat.py +++ b/files/routes/chat.py @@ -13,6 +13,7 @@ if SITE in ('pcmemes.net', 'localhost'): import sys socketio = SocketIO(app, async_mode='gevent') + typing = [] @app.get("/chat") @auth_required @@ -38,10 +39,27 @@ if SITE in ('pcmemes.net', 'localhost'): def connect(): global count count += 1 - emit("count", count) + emit("count", count, broadcast=True) + + emit('typing', typing) + return '', 204 @socketio.on('disconnect') - def disconnect(): + @auth_required + def disconnect(v): global count count -= 1 - emit("count", count) \ No newline at end of file + emit("count", count, broadcast=True) + if v.username in typing: typing.remove(v.username) + emit('typing', typing, broadcast=True) + return '', 204 + + @socketio.on('typing') + @auth_required + def typing_indicator(data, v): + + if data and v.username not in typing: typing.append(v.username) + elif not data and v.username in typing: typing.remove(v.username) + + emit('typing', typing, broadcast=True) + return '', 204 \ No newline at end of file diff --git a/files/templates/chat.html b/files/templates/chat.html index d8284de51..17f148a3f 100644 --- a/files/templates/chat.html +++ b/files/templates/chat.html @@ -1,83 +1,209 @@ {% extends "default.html" %} {% block title %} - Chat - + Chat + {% endblock %} {% block content %}
- - - 0 - + + + 0 +
-
-
- - - -
-
- - -
- -
-
-
-
-
+
+
+ + + +
+
+ + +
+ +
+
+
+
+
-
-
-
-
-
-

-
-
-
-
-
- - -
- - -
+
+
+
+
+
+

+
+
+
+
+
+ + +
+ + +
- + + {% endblock %} \ No newline at end of file diff --git a/files/templates/default.html b/files/templates/default.html index af0a86fb6..46c9b082f 100644 --- a/files/templates/default.html +++ b/files/templates/default.html @@ -83,7 +83,7 @@ - + diff --git a/requirements.txt b/requirements.txt index 11f442799..a0093943e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,6 +7,7 @@ Flask-Limiter Flask-Mail Flask-Socketio gevent +gevent-websocket greenlet gunicorn lxml diff --git a/supervisord.conf b/supervisord.conf index 7e2992d02..64b74eb6a 100644 --- a/supervisord.conf +++ b/supervisord.conf @@ -5,7 +5,7 @@ logfile=/tmp/supervisord.log [program:service] directory=/service -command=gunicorn files.__main__:app -k gevent -w 1 --reload -b 0.0.0.0:80 --max-requests 1000 --max-requests-jitter 500 +command=gunicorn files.__main__:app -k geventwebsocket.gunicorn.workers.GeventWebSocketWorker -w 1 --reload -b 0.0.0.0:80 --max-requests 1000 --max-requests-jitter 500 stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr