def add_user_to_room(room_name, user_sid): """Add user to room and resume thread if requirement meet""" # Check if room_name is correct and if user isn't already inside if room_name in USERS_IN_ROOM and user_sid not in USERS_IN_ROOM[room_name]: USERS_IN_ROOM[room_name].append(user_sid) LOGGER.debug("[" + room_name + "] User joined the room. User SID: " + user_sid) # First user that joins room resumes thread if len(USERS_IN_ROOM[room_name]) == 1: ROOM_THREAD[room_name].resume() LOGGER.debug("[" + room_name + "] Thread resumed.")
def remove_user_from_room(room_name, user_sid): """Remove user from room and pause thread if requirement meet""" # Check if room_name is correct and if user is inside if room_name in USERS_IN_ROOM and user_sid in USERS_IN_ROOM[room_name]: USERS_IN_ROOM[room_name].remove(user_sid) LOGGER.debug("[" + room_name + "] User left the room. User SID: " + user_sid) # Last user that leaves room pauses thread if len(USERS_IN_ROOM[room_name]) == 0: ROOM_THREAD[room_name].pause() LOGGER.debug("[" + room_name + "] Thread paused.")
def remove_user_from_room(room_name, user_sid): """Remove user from room and pause thread if requirement meet""" # Check if room_name is correct and if user is inside if room_name in USERS_IN_ROOM and user_sid in USERS_IN_ROOM[room_name]: USERS_IN_ROOM[room_name].remove(user_sid) LOGGER.debug( "[" + room_name + "] User left the room. User SID: " + user_sid) # Last user that leaves room pauses thread if len(USERS_IN_ROOM[room_name]) == 0: ROOM_THREAD[room_name].pause() LOGGER.debug("[" + room_name + "] Thread paused.")
def add_user_to_room(room_name, user_sid): """Add user to room and resume thread if requirement meet""" # Check if room_name is correct and if user isn't already inside if room_name in USERS_IN_ROOM and user_sid not in USERS_IN_ROOM[room_name]: USERS_IN_ROOM[room_name].append(user_sid) LOGGER.debug( "[" + room_name + "] User joined the room. User SID: " + user_sid) # First user that joins room resumes thread if len(USERS_IN_ROOM[room_name]) == 1: ROOM_THREAD[room_name].resume() LOGGER.debug("[" + room_name + "] Thread resumed.")
def remove_user(user_sid): """Remove user from each room and pause thread if requirement meet""" # Iterate through each room for room_name in USERS_IN_ROOM.keys(): # Check if user inside room if user_sid in USERS_IN_ROOM[room_name]: USERS_IN_ROOM[room_name].remove(user_sid) LOGGER.debug("[" + room_name + "] User left the room. User SID: " + user_sid) # Last user that leaves room pauses thread if len(USERS_IN_ROOM[room_name]) == 0: ROOM_THREAD[room_name].pause() LOGGER.debug("[" + room_name + "] Thread paused.")
def remove_user(user_sid): """Remove user from each room and pause thread if requirement meet""" # Iterate through each room for room_name in USERS_IN_ROOM.keys(): # Check if user inside room if user_sid in USERS_IN_ROOM[room_name]: USERS_IN_ROOM[room_name].remove(user_sid) LOGGER.debug( "[" + room_name + "] User left the room. User SID: " + user_sid) # Last user that leaves room pauses thread if len(USERS_IN_ROOM[room_name]) == 0: ROOM_THREAD[room_name].pause() LOGGER.debug("[" + room_name + "] Thread paused.")
def run(self): """Send notifications when data provided""" while True: with self.state: if self.paused: self.state.wait() # block until notified # do stuff data = self.get_data() if data is not None: self.socket.emit(self.event_name, data, room=self.room_name, namespace='/kujira') LOGGER.debug("[" + self.room_name + "] Notification sent.") time.sleep(2)
def remove_user_from_room(room_name, user_sid): """ Remove user from given room :param room_name: room name :param user_sid: user SID """ if room_name not in USERS_IN_ROOM: raise InvalidRoomNameError() # Check if user is in room if user_sid in USERS_IN_ROOM[room_name]: USERS_IN_ROOM[room_name].remove(user_sid) LOGGER.debug( "[" + room_name + "] User left the room. User SID: " + user_sid) # Last user that leaves room pauses thread if len(USERS_IN_ROOM[room_name]) == 0: ROOM_THREAD[room_name].pause() LOGGER.debug("[" + room_name + "] Thread paused.")
def add_user_to_room(room_name, user_sid): """ Add user to room :param room_name: room name :param user_sid: user SID """ if room_name not in USERS_IN_ROOM: raise InvalidRoomNameError() # Check if user is already in room if user_sid not in USERS_IN_ROOM[room_name]: USERS_IN_ROOM[room_name].append(user_sid) LOGGER.debug( "[" + room_name + "] User joined the room. User SID: " + user_sid) # First user that joins room resumes thread if len(USERS_IN_ROOM[room_name]) == 1: ROOM_THREAD[room_name].resume() LOGGER.debug("[" + room_name + "] Thread resumed.")
def remove_user_from_room(room_name, user_sid): """ Remove user from given room :param room_name: room name :param user_sid: user SID """ if room_name not in USERS_IN_ROOM: raise InvalidRoomNameError() # Check if user is in room if user_sid in USERS_IN_ROOM[room_name]: USERS_IN_ROOM[room_name].remove(user_sid) LOGGER.debug("[" + room_name + "] User left the room. User SID: " + user_sid) # Last user that leaves room pauses thread if len(USERS_IN_ROOM[room_name]) == 0: ROOM_THREAD[room_name].pause() LOGGER.debug("[" + room_name + "] Thread paused.")
def add_user_to_room(room_name, user_sid): """ Add user to room :param room_name: room name :param user_sid: user SID """ if room_name not in USERS_IN_ROOM: raise InvalidRoomNameError() # Check if user is already in room if user_sid not in USERS_IN_ROOM[room_name]: USERS_IN_ROOM[room_name].append(user_sid) LOGGER.debug("[" + room_name + "] User joined the room. User SID: " + user_sid) # First user that joins room resumes thread if len(USERS_IN_ROOM[room_name]) == 1: ROOM_THREAD[room_name].resume() LOGGER.debug("[" + room_name + "] Thread resumed.")
def handle_data_source_exception(self, exception_message): """ Handle data source exception :param exception_message: exception message """ LOGGER.debug("[" + self.room_name + "] Exception occurred: " + exception_message) while True: try: self.check_connection() break except ConnectionError: self.send_message("ERROR", self.room_name, "Data source unreachable") LOGGER.debug("[" + self.room_name + "] Data source unreachable") time.sleep(10) self.send_message("NOTIFICATION", self.room_name, "Connection restored.") LOGGER.debug("[" + self.room_name + "] Connection restored.")
"graph": GraphNotificationThread} # Dictionary for each room thread ROOM_THREAD = {} # Dictionary for lists of users in each room USERS_IN_ROOM = {} # Initialize dictionaries for room in ROOM_DESCRIPTION: USERS_IN_ROOM[room["name"]] = [] # Depending on room type create different thread ROOM_THREAD[room["name"]] = ROOM_HANDLER[room["type"]](SOCKETIO, room) # Starts thread for each room for room_key in ROOM_THREAD.keys(): ROOM_THREAD[room_key].start() LOGGER.debug("[" + room_key + "] Thread started.") def add_user_to_room(room_name, user_sid): """ Add user to room :param room_name: room name :param user_sid: user SID """ if room_name not in USERS_IN_ROOM: raise InvalidRoomNameError() # Check if user is already in room if user_sid not in USERS_IN_ROOM[room_name]: USERS_IN_ROOM[room_name].append(user_sid) LOGGER.debug(
# Dictionary for lists of users in each room USERS_IN_ROOM = {} # Initialize dictionaries for room in ROOM_DESCRIPTION: USERS_IN_ROOM[room["name"]] = [] # Depending on room type start different thread if room["type"] is "event": ROOM_THREAD[room["name"]] = EventNotificationThread(SOCKETIO, room) elif room["type"] is "diagram": ROOM_THREAD[room["name"]] = DiagramNotificationThread(SOCKETIO, room) # Starts thread for each room. for room_key in ROOM_THREAD.keys(): ROOM_THREAD[room_key].start() LOGGER.debug("[" + room_key + "] Thread started.") def add_user_to_room(room_name, user_sid): """Add user to room and resume thread if requirement meet""" # Check if room_name is correct and if user isn't already inside if room_name in USERS_IN_ROOM and user_sid not in USERS_IN_ROOM[room_name]: USERS_IN_ROOM[room_name].append(user_sid) LOGGER.debug("[" + room_name + "] User joined the room. User SID: " + user_sid) # First user that joins room resumes thread if len(USERS_IN_ROOM[room_name]) == 1: ROOM_THREAD[room_name].resume() LOGGER.debug("[" + room_name + "] Thread resumed.")