selkies
Token pushes to the selkies control plane.
Token pushes to the selkies control plane.
Selkies enforces input routing itself: it receives the full token map
{token: {role, slot, mk_control}} and decides per websocket connection
whether input goes to mouse/keyboard, a virtual gamepad slot, or nowhere. The
broker just keeps that map in sync with room state.
attributelog= logging.getLogger(__name__)attributeRETRY_DELAY_SECONDS= 0.25Pause before the one retry a fully failed sweep gets.
funcbuild_token_map(session) -> dict[str, dict[str, Any]]Build the token map selkies routes input by, from the session's room state.
The controller keeps mouse and keyboard control unless a viewer has been
handed it; a viewer holds it only while they are the mk_owner_token.
paramsessiondict[str, Any]The active session dict.
Returns
dictA mapping of streaming token to {"role", "slot", "mk_control"}, one
func_token_urls() -> list[str]Return the candidate token endpoints, last-known-good first.
Returns
listThe configured endpoints, with _active_url moved to the front when it
func_post(tokens, what) -> boolPOST a token set to selkies, trying each candidate endpoint in turn.
Every endpoint that refuses is logged with the endpoint that produced it and the traceback, since the cost of a lost push is silent: selkies keeps routing input by the map it already has, so a viewer holds a pad the room thinks it gave away. A sweep that fails everywhere is retried once against the last-known-good endpoint, which covers the common case of a single request losing a race with a selkies restart without making every room action wait out a second full sweep of timeouts. Nothing is queued for later: each call sends the whole map, so the next successful push is itself the reconciliation.
paramtokensdict[str, dict[str, Any]]The token map to send; empty disconnects every client.
paramwhatstrWhat this push is, for the log lines.
Returns
boolTrue when an endpoint accepted the push, False when none did (the
funcpush_tokens(session) -> boolPOST the current token set to selkies.
Replaces the whole active set: removed tokens disconnect their clients, changed permissions apply live. Each candidate endpoint is tried in turn and the first to accept is remembered for next time.
paramsessiondict[str, Any]The active session dict the token map is built from.
Returns
boolTrue when an endpoint accepted the push, False when every candidate
funcclear_tokens() -> boolPush an empty token set so every streaming client is disconnected.
Returns
boolTrue when an endpoint accepted the empty set, False when every candidate