wide-dress-57902
08/11/2025, 11:13 PMtall-airline-16756
08/11/2025, 11:13 PMtall-airline-16756
08/11/2025, 11:15 PMon
method of the Room object in LiveKit is a handy way to set up event handlers for different happenings inside a room. It works just like the EventEmitter pattern, letting you listen for specific events and run your own custom code when they pop up.
Here’s a quick rundown:
• Method Signature: def on(self, event: EventTypes, callback: Optional[Callable] = None) -> Callable
• How It Works: This method hooks up event listeners that fire off whenever certain events happen in the room. All the callbacks you register for an event will be called with the right info.
• Available Events: You can listen for things like participant_connected
, track_subscribed
, room_metadata_changed
, and more. Each event gives you useful details, like info about the participant or track.
For example, here’s how you’d handle someone joining the room:
@room.on("participant_connected")
def on_participant_connected(participant):
print(f"Participant {participant.identity} has connected.")
If you want to dive into any specific events or need a hand with anything else, just let me know—I’m here to help!
Sources: examples/basic_room.py