collaboration
Collaboration rooms: the room page, its WebSocket and token fan-out.
A collaboration session is a normal session whose container also runs a control plane that accepts a table of tokens (controller, viewers, gamepad slots, mouse/keyboard owner). This module serves the room page, relays chat and control messages between participants over a WebSocket and pushes token changes down to every container of the session.
attributelogger= logging.getLogger(__name__)attributerouter= APIRouter()attributeROOM_CONNECTIONSdict[str, dict[str, Any]]= {}attributeTOKEN_ENDPOINT_CACHEdict[str, str]= {}func_absolutize_room_assets(html) -> strRewrite relative asset references in the room template to /ui/room/.
The page is served at /room/<session_id> while its hashed assets live
under the static /ui/room/ mount, so relative references would 404.
paramhtmlstrRaw room template.
Returns
strThe template with relative src/href values made absolute.
funccollaborative_room(request, session_id, collab_token=Query(None, alias='token')) -> ResponseServe the collaboration room page.
Authenticates the visitor as controller (session access token or controller token), existing viewer, or new participant/read-only viewer via an invite token. New viewers get a personal token and are redirected.
paramrequestRequestIncoming request.
paramsession_idUUIDCollaboration session id.
paramcollab_tokenstr | None= Query(None, alias='token')Controller, viewer or invite token.
Returns
fastapi.responses.ResponseThe room HTML, or a redirect for newly registered viewers.
funcbroadcast_token_state(session_id, session_data) -> NonePush the current token table to every container of a session.
paramsession_idstrSession id.
paramsession_datadict[str, Any]Session record.
Returns
Nonefunc_owner_group(username) -> strReturn the effective group of a user ("none" when unknown).
paramusernamestrReturns
strfuncbroadcast_to_room(session_id, payload) -> NoneSend a JSON payload to every participant of a room.
paramsession_idstrparampayloaddict[str, Any]Returns
Nonefuncbroadcast_binary_to_room(session_id, payload, sender_ws) -> NoneRelay a binary (audio/video) packet to every participant except the sender.
paramsession_idstrparampayloadbytesparamsender_wsWebSocketReturns
Nonefuncroom_websocket(websocket, session_id) -> NoneHandle a participant's WebSocket for the lifetime of the connection.
paramwebsocketWebSocketThe accepted socket.
paramsession_idUUIDCollaboration session id.
Returns
Nonefuncbroadcast_state(session_id) -> NoneSend the participant list and designated speaker to the room.
paramsession_idstrReturns
Nonefunchandle_assign_slot(session_id, viewer_token, slot) -> NoneAssign a gamepad slot to a participant (or clear it with None).
paramsession_idstrparamviewer_tokenstrparamslotint | NoneReturns
Nonefunchandle_assign_mk(session_id, target_token) -> NoneGive mouse and keyboard control to a participant (None = controller).
paramsession_idstrparamtarget_tokenstr | NoneReturns
Nonefuncnotify_session_ended(session_id) -> NoneTell every participant that the session ended and drop the room.
paramsession_idstrReturns
None