-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
39 lines (29 loc) · 918 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
29
30
31
32
33
34
35
36
37
38
39
from flask import Flask, render_template
from datetime import datetime
from flask_socketio import SocketIO, send, emit
app = Flask(__name__)
app.config['SECRET_KEY'] = 'AFPurmxhSC06jlHwDbZzBvFs'
socketio = SocketIO(app)
clients = set()
@app.route('/')
def index():
return render_template('index.html')
@socketio.on('send')
def message_recieved(data):
data['timestamp'] = datetime.now().strftime('%I:%M')
emit('recieve', data, broadcast=True)
@socketio.on('connection')
def update_count(client_id):
global clients
clients.add(client_id)
emit('connected', len(clients), broadcast=True)
@socketio.on('disconnection')
def update_count(client_id):
global clients
clients.remove(client_id)
emit('disconnected', len(clients), broadcast=True)
@socketio.on('typesend')
def typing(data):
emit('typerecieve', data, broadcast=True)
if __name__ == '__main__':
socketio.run(app)