give some details on the "on" method of the room o...
# ask-ai
w
give some details on the "on" method of the room object?
t
Thanks for reaching out, Arthur. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
on
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:
Copy code
@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