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
Unique identifier for this player
Authenticated user object (if JWT token provided)
Current room ID the player is in
Timestamp when player connected
Custom session metadata dictionary
Methods
Store custom session data
Retrieve custom session data
room
Manage rooms and broadcast messages to players.Properties
Current room ID
Shared room state accessible to all players. Initialize this in
on_connect.Room configuration (tick_rate, custom flags, etc.)
Custom room metadata for room listing
Methods
Join a room (auto-created if doesn’t exist)
Send message to all players in room
Send message to a specific player
Get list of connected player IDs
Get number of connected players
Start the game loop (enables
on_tick calls)Stop the game loop
Destroy the room and disconnect all players
request
Access incoming message data from the client.Methods
Get value from incoming message
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:Time-related functions
Random number generation
JSON encoding/decoding
UUID generation
Date and time handling
