def request_control(): """ """ @copy_current_request_context def handle_timeout_gives_control(sid, timeout=30): gevent.sleep(timeout) if mxcube.TIMEOUT_GIVES_CONTROL: user = loginutils.get_user_by_sid(sid) # Pass control to user if still waiting if user.get("requestsControl"): toggle_operator(sid, "Timeout expired, you have control") data = request.get_json() remote_addr = loginutils.remote_addr() # Is someone already asking for control for observer in loginutils.get_observers(): if observer["requestsControl"] and observer["host"] != remote_addr: msg = "Another user is already asking for control" return make_response(msg, 409) user = loginutils.get_user_by_sid(session.sid) user["name"] = data["name"] user["requestsControl"] = data["control"] user["message"] = data["message"] observers = loginutils.get_observers() gevent.spawn(handle_timeout_gives_control, session.sid, timeout=10) socketio.emit("observersChanged", observers, namespace="/hwr") return make_response("", 200)
def toggle_operator(new_op_sid, message): current_op = loginutils.get_operator() new_op = loginutils.get_user_by_sid(new_op_sid) loginutils.set_operator(new_op["sid"]) new_op["message"] = message observers = loginutils.get_observers() # Append the new data path so that it can be updated on the client new_op["rootPath"] = blcontrol.beamline.session.get_base_image_directory() # Current op might have logged out, while this is happening if current_op: current_op[ "rootPath"] = blcontrol.beamline.session.get_base_image_directory( ) current_op["message"] = message socketio.emit("setObserver", current_op, room=current_op["socketio_sid"], namespace="/hwr") socketio.emit("observersChanged", observers, namespace="/hwr") socketio.emit("setMaster", new_op, room=new_op["socketio_sid"], namespace="/hwr")
def observer_requesting_control(): observer = None for o in loginutils.get_observers(): if o["requestsControl"]: observer = o return observer
def observer_requesting_control(): observer = None for o in loginutils.get_observers(): if o["requestsControl"]: observer = o return observer
def set_observer(data): name = data.get("name", "") observers = loginutils.get_observers() observer = loginutils.get_user_by_sid(session.sid) if observer and name: observer["name"] = name socketio.emit("observerLogin", observer, include_self=False, namespace="/hwr") socketio.emit("observersChanged", observers, namespace="/hwr") return session.sid
def set_observer(data): name = data.get("name", "") observers = loginutils.get_observers() observer = loginutils.get_user_by_sid(session.sid) if observer and name: observer["name"] = name socketio.emit("observerLogin", observer, include_self=False, namespace="/hwr") socketio.emit("observersChanged", observers, namespace="/hwr") return session.sid
def observers(): """ """ data = { "observers": loginutils.get_observers(), "sid": session.sid, "master": loginutils.is_operator(session.sid), "observerName": loginutils.get_observer_name(), "allowRemote": mxcube.ALLOW_REMOTE, "timeoutGivesControl": mxcube.TIMEOUT_GIVES_CONTROL, } return jsonify(data=data)
def observers(): """ """ data = { "observers": loginutils.get_observers(), "sid": session.sid, "master": loginutils.is_operator(session.sid), "observerName": loginutils.get_observer_name(), "allowRemote": mxcube.ALLOW_REMOTE, "timeoutGivesControl": mxcube.TIMEOUT_GIVES_CONTROL, } return jsonify(data=data)
def request_control(): """ """ @copy_current_request_context def handle_timeout_gives_control(sid, timeout=30): gevent.sleep(timeout) if mxcube.TIMEOUT_GIVES_CONTROL: user = loginutils.get_user_by_sid(sid) # Pass control to user if still waiting if user.get("requestsControl"): toggle_operator(sid, "Timeout expired, you have control") data = request.get_json() remote_addr = loginutils.remote_addr() # Is someone already asking for control for observer in loginutils.get_observers(): if observer["requestsControl"] and observer["host"] != remote_addr: msg = "Another user is already asking for control" return make_response(msg, 409) user = loginutils.get_user_by_sid(session.sid) user["name"] = data["name"] user["requestsControl"] = data["control"] user["message"] = data["message"] observers = loginutils.get_observers() gevent.spawn(handle_timeout_gives_control, session.sid, timeout=10) socketio.emit("observersChanged", observers, namespace="/hwr") return make_response("", 200)
def toggle_operator(new_op_sid, message): current_op = loginutils.get_operator() new_op = loginutils.get_user_by_sid(new_op_sid) loginutils.set_operator(new_op["sid"]) new_op["message"] = message observers = loginutils.get_observers() # Append the new data path so that it can be updated on the client new_op["rootPath"] = blcontrol.session.get_base_image_directory() # Current op might have logged out, while this is happening if current_op: current_op["rootPath"] = blcontrol.session.get_base_image_directory() current_op["message"] = message socketio.emit( "setObserver", current_op, room=current_op["socketio_sid"], namespace="/hwr" ) socketio.emit("observersChanged", observers, namespace="/hwr") socketio.emit("setMaster", new_op, room=new_op["socketio_sid"], namespace="/hwr")