100ms Logo

100ms

Docs

Search docs
/

Preview Listener

Now, let's take a look at the listener class to be implemented.

///[HMSPreviewListener] listens to updates when you preview. /// ///Just implement it and get the preview updates. /// /// Check out the [Sample App] how we are using it. abstract class HMSPreviewListener { ///when an error is caught [onError] will be called /// /// - Parameters: /// - error: error which you get. void onHMSError({required HMSException error}); ///when you want to preview listen to this callback /// /// - Parameters: /// - room: the room which was joined /// - localTracks: local audio/video tracks list void onPreview({required HMSRoom room, required List<HMSTrack> localTracks}); /// This is called when there is a change in any property of the Room /// /// - Parameters: /// - room: the room which was joined /// - update: the triggered update type. Should be used to perform different UI Actions void onRoomUpdate({required HMSRoom room, required HMSRoomUpdate update}); /// This will be called whenever there is an update on an existing peer /// or a new peer got added/existing peer is removed. /// /// This callback can be used to keep a track of all the peers in the room /// - Parameters: /// - peer: the peer who joined/left or was updated /// - update: the triggered update type. Should be used to perform different UI Actions void onPeerUpdate({required HMSPeer peer, required HMSPeerUpdate update}); ///whenever a new audio device is plugged in or audio output is changed we ///get the onAudioDeviceChanged update ///This callback is only fired on Android devices. On iOS, this callback will not be triggered. /// - Parameters: /// - currentAudioDevice: Current audio output route /// - availableAudioDevice: List of available audio output devices void onAudioDeviceChanged( {HMSAudioDevice? currentAudioDevice, List<HMSAudioDevice>? availableAudioDevice}); }

HMSPreviewListener : A class conforming to HMSPreviewListener interface. The methods of HMSPreviewListener are invoked to notify updates while in preview like a peer join,video mute/unmute, audio device selection etc.

Add this previewListener instance to

HMSSDK hmsSDK = HMSSDK(); hmsSDK.build(); hmsSDK.addPreviewListener(previewListener);

After calling preview your app will be provided an update from the 100ms SDK.

āœ… If successful, the onPreview({required HMSRoom room, required List<HMSTrack> localTracks}) method of HMSPreviewListener will be invoked with information about the room encapsulated in the HMSRoom object.

āŒ If failure, the onHMSError({required HMSException error}) method will be invoked with exact failure reason.

Remove the previewListener instance as:

hmsSDK.removePreviewListener(previewListener);