-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
28 lines (23 loc) · 922 Bytes
/
app.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
from flask import Flask, render_template
from flask_socketio import SocketIO, emit
app = Flask(__name__)
app.config['SECRET_KEY'] = '10c3f66f2155dbb76bb54c73c4a94bde0890a8d632599f92'
socketio = SocketIO(app)
@app.route('/')
def index():
return render_template('index.html')
@socketio.on('message')
def handle_message(data):
username = data['username']
message = data['message']
timestamp = data['timestamp']
print(f'Message from {username} at {timestamp}: {message}')
emit('message', {'username': username, 'timestamp': timestamp, 'message': message}, broadcast=True)
@socketio.on('reaction')
def handle_reaction(data):
username = data['username']
reaction = data['reaction']
print(f'{username} reacted with {reaction}')
emit('reaction', {'username': username, 'reaction': reaction}, broadcast=True)
if __name__ == '__main__':
socketio.run(app, host='127.0.0.1', port=5000)