Skip to content
Snippets Groups Projects
Commit 0aab004a authored by Ravi Tripathi's avatar Ravi Tripathi
Browse files

Adding on_room fuction taht gets triggered when connection is made, and we...

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
parent aaa770d1
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment