Event Handlers
Your WebSocket function must define these event handlers:on_connect()
Called when a player connects to the WebSocket.on_message()
Called when a player sends a message to the server.on_disconnect()
Called when a player disconnects (closes WebSocket or loses connection).on_tick()
Called repeatedly at a fixed rate (default 20 times per second) for continuous game updates.To use
on_tick, you must start the game loop by calling room.start_game_loop() in your on_connect handler.Available Objects
session
Access player session data and information.Properties
string
Unique identifier for this player
object | null
Authenticated user object (if JWT token provided)
string
Current room ID the player is in
datetime
Timestamp when player connected
dict
Custom session metadata dictionary
Methods
function
Store custom session data
function
Retrieve custom session data
room
Manage rooms and broadcast messages to players.Properties
string
Current room ID
dict
Shared room state accessible to all players. Initialize this in
on_connect.dict
Room configuration (tick_rate, custom flags, etc.)
dict
Custom room metadata for room listing
Methods
function
Join a room (auto-created if doesn’t exist)
async function
Send message to all players in room
async function
Send message to a specific player
function
Get list of connected player IDs
function
Get number of connected players
function
Start the game loop (enables
on_tick calls)function
Stop the game loop
function
Destroy the room and disconnect all players
request
Access incoming message data from the client.Methods
function
Get value from incoming message
function
Get entire message as dictionary
db
Access your project’s database (same as HTTP functions).See the Database Documentation for full database API reference.
Built-in Modules
The following Python modules are available in your functions:module
Time-related functions
module
Random number generation
module
JSON encoding/decoding
module
UUID generation
module
Date and time handling
