Working with Events
Events are a fundamental aspect of working with the SDK. As introduced in the getting started section, events enable your application to respond to various changes and updates. For example, you can be notified when a RemotePeer AudioOutput
The SDK primarily revolves around three core Entities, each associated with a specific set of events:
Room
->RoomEvents
- Peer (
LocalPeer
andRemotePeer
) ->PeerEvents
- Media (
AudioInput
andAudioOutput
) ->MediaEvents
Room Events
The room is the main entity to work with. It's important to register its event handlers before joining. This ensures you capture all relevant events, particularly initial ones like the RoomStatus PeerJoined
As for all Events, there are two ways to register EventHandlers (callbacks). The obj.addEventlistener() and obj.onEvent approach. In the following examples, for simplicity, the onEvent property approach is used.
To prevent memory leaks when reusing a room instance for multiple connections, ensure that EventListeners are handled correctly. You should either:
- Remove event listeners when leaving the room.
- Ensure that event listeners are registered only once.
Alternatively, you can use the room.onPeerJoined syntax. This assigns a callback directly, overwriting any previous assignment, which can simplify event management and help avoid unintended multiple registrations.
Most relevant room events
Peer Events
There are two types of Peers, the LocalPeer RemotePeer PeerEvents Room
Most relevant peer events
Media (AudioInput / AudioOutput) Events
Similar to Peers, Medias are separated into AudioInput AudioOutput AudioInput RemotePeer
More details about configuring the AudioInput
Important Note: In the most apps, a Peer will always have one AudioInput AudioOutput MediaEvents