I wrote this small script to help make room management a little easier with Flask-SocketIO. As some of you who have worked with Miguel Grinberg's Flask-SocketIO , a large amount of the emitting is done through something called rooms. Hotelier tries to give a decent API for creating and joining rooms, maintaining owners and also maintaining rooms for each user that joins the socket to enable emitting to a specific user which was mentioned here
from hotelier import RoomManager
hotelier = RoomManager()
The create_room function will create a room using a request-sid and a room name as arguments:
from flask import request
# Create Room:
hotelier.create_room(request.sid, 'This is a Room')
# Destroy Room:
hotelier.destroy_room(request.sid)
This will create a room and register the current request.sid as the owner of said room. The destroy_room function takes the request.sid as an argument and destroys the room that the user was an owner to.
The join_room function takes the three arguments: the request.sid, Name of the room and the desired alias of the user inside of said room respectively. This will successfully join an already created room. The leave_room function leaves the current room the user is joined to.
from flask import request
# Join Room:
hotelier.join_room(request.sid, 'This is a Room', 'IAMUSER')
# Leave Room:
hotelier.leave_room(request.sid)
The following methods are some helper functions made:
get_participant_name
If the user is part of a room, this method will get the name of the participant using their request.sid as a parameter:
hotelier.get_participant_name(request.sid)
get_participant_sid_from_name
If the user is part of a room, this method will get the request.sid of the participant using their name as a parameter:
hotelier.get_participant_sid_from_name("IAMUSER")
get_room_from_participant
If the user is part of a room, this method will get the room name that they are part of using their request.sid as a parameter:
hotelier.get_room_from_participant(request.sid)
get_owner
Will get the owner of the room that the user is a participant of using their request.sid:
hotelier.get_owner(request.sid)
# returns owner's request.sid
I have only been using this in development for an application I am busy with. There is some more functionality I plan to add and some better API feel for the messaging part of it. This is also my first github repo so be nice please :). Any suggestions are always welcome.