36 lines
798 B
Python
36 lines
798 B
Python
import os
|
|
|
|
from flask import Flask, render_template
|
|
from flask_socketio import SocketIO, join_room, leave_room, send
|
|
|
|
app = Flask(__name__)
|
|
if 'CORS_ORIGIN' in os.environ and os.environ['CORS_ORIGIN'] is not None:
|
|
socketio = SocketIO(app, cors_allowed_origins=[os.environ['CORS_ORIGIN']])
|
|
else:
|
|
socketio = SocketIO(app)
|
|
|
|
if __name__ == 'main':
|
|
socketio.run(app)
|
|
|
|
@app.route('/')
|
|
def return_index_page():
|
|
return render_template('index.html')
|
|
|
|
@app.route('/<exchange>')
|
|
def return_exchange_page(exchange):
|
|
return render_template('exchange.html')
|
|
|
|
@socketio.on('join')
|
|
def on_join(data):
|
|
room = data['room']
|
|
join_room(room)
|
|
|
|
@socketio.on('leave')
|
|
def on_leave(data):
|
|
room = data['room']
|
|
leave_room(room)
|
|
|
|
@socketio.on('message')
|
|
def on_message(data):
|
|
room = data['room']
|
|
send(data, to=room) |