From 0aab004a58c616bbd01005fb4dd2339d57cb4f5e Mon Sep 17 00:00:00 2001 From: Ravi Tripathi <ravi89@uab.edu> Date: Thu, 5 Mar 2020 19:02:56 +0000 Subject: [PATCH] Adding on_room fuction taht gets triggered when connection is made, and we need to join a room for the communcation to take place between client and server --- run.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/run.py b/run.py index 6c3e8d6..7f0f6f9 100644 --- a/run.py +++ b/run.py @@ -10,6 +10,9 @@ from flask_socketio import SocketIO, join_room from app import create_app +from gevent import monkey +monkey.patch_all(subprocess=True) + config_name = os.getenv('FLASK_CONFIG') app = create_app(config_name) app.config['SECRET_KEY'] = 'vnkdjnfjknfl1232#' @@ -21,6 +24,10 @@ socketio = SocketIO(app, message_queue='amqp://reggie:reggie@ohpc:5672/socketio' # global room_global +@socketio.on('connect') +def socket_connect(): + pass + def create_account(username, fullname, reason): # Todo: Ravi's and Louis's code goes here print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' added to queue') @@ -51,19 +58,26 @@ def user_connected(json, methods=['GET', 'POST']): print(time.strftime("%m-%d-%Y_%H:%M:%S") + '\tUser ' + username + ' connected.') print('\t\t\t|-----Room ID: ' + room) +@socketio.on('join_room') +def on_room(): + + room = str(session['uid']) + join_room(room) + print('\t\t\t|-----Room ID: ' + room) + @socketio.on('request account') def request_account(json, methods=['GET', 'POST']): print (time.strftime("%m-%d-%Y_%H:%M:%S") + '\tQueue request received: ' + str(json)) #print(json) - room = str(session['uid']) - join_room(room) - print("Room: {}".format(room)) - #socketio.emit("creating account") + sid = str(session['uid']) + #join_room(room) + print("Room: {}".format(sid)) + #socketio.emit("creating account", room=sid) try: # create_account(json['username'], json['fullname'], json['reason']) #tasks.celery_create_account.delay(json['username'], json['fullname'], json['reason'], room, socketio, session=room) - tasks.celery_create_account.delay(json['username'], json['fullname'], json['reason'], room) + tasks.celery_create_account.delay(json['username'], json['fullname'], json['reason'], session=sid) except Exception as e: print(time.strftime("%m-%d-%Y_%H:%M:%S") + "\tError in account creation: ", e) socketio.emit("Account creation failed", room) -- GitLab