Action Result Listeners
HMSActionResultListener
is a listener to listen to success or failure callback for methods.
Whenever an instance of HMSActionResultListener
is passed with a method then it's status i.e whether it succeeded or failed
can be listened using HMSActionResultListener's onSuccess
& onException
callbacks respectively.
HMSActionResultListener
should be implemented in the class where HMSActionResultListener methods are called.
We can implement HMSUpdateListener
,HMSActionResultListener
,HMSStatsListener
etc. on a single class
checkout the example here
How to add an HMSActionResultListener
This section contains info about how we can add HMSActionResultListener to our class:
Implement HMSActionResultListener
Implement HMSActionResultListener in a class wherever you wish to call the HMSSDK methods and add override methods.
class Meeting implements HMSActionResultListener{ void onSuccess( {HMSActionResultListenerMethod methodType = HMSActionResultListenerMethod.unknown, Map<String, dynamic>? arguments}) {} void onException( {HMSActionResultListenerMethod methodType = HMSActionResultListenerMethod.unknown, Map<String, dynamic>? arguments, required HMSException hmsException}) {} }
Pass HMSActionResultListener instance in methods
To get the onSuccess
or onException
callbacks we need to pass the HMSActionResultListener
instance while calling methods as:
class Meeting implements HMSActionResultListener{ ... void leave() async { //this is the instance of class which implements HMSActionResultListener await hmsSDK.leave(hmsActionResultListener: this); } void sendBroadcastMessage(){ //this is the instance of class which implements HMSActionResultListener hmsSDK.sendBroadcastMessage( message: message, type: type, hmsActionResultListener: this); } void onSuccess( {HMSActionResultListenerMethod methodType = HMSActionResultListenerMethod.unknown, Map<String, dynamic>? arguments}) { switch (methodType) { case HMSActionResultListenerMethod.leave: // Room leaved successfully // Clear the local room state break; case HMSActionResultListenerMethod.sendBroadcastMessage: //Do the needful actions here break; ... } } void onException( {HMSActionResultListenerMethod methodType = HMSActionResultListenerMethod.unknown, Map<String, dynamic>? arguments, required HMSException hmsException}) { switch (methodType) { case HMSActionResultListenerMethod.leave: // Check the HMSException object for details about error break; case HMSActionResultListenerMethod.sendBroadcastMessage: // Check the HMSException object for details about error break; ... } } ... }
Other methods can be implemented in similar fashion.
Supplementary bytes
This section explains HMSActionResultListener
class methods. We implement this class to listen to method callbacks.
///100ms HMSActionResultListener /// ///Whenever an instance of [HMSActionResultListener] is passed with a method then it's status i.e whether it succeeded or failed can be listened using HMSActionResultListener's onSuccess & onException callbacks respectively. abstract class HMSActionResultListener { void onSuccess( {HMSActionResultListenerMethod methodType, Map<String, dynamic>? arguments}); void onException( {HMSActionResultListenerMethod methodType, Map<String, dynamic>? arguments, required HMSException hmsException}); }
💡 HMSActionResultListener
: A class conforming to HMSActionResultListener interface.
The methods of HMSActionResultListener are invoked to notify the status of the api's whether it failed or succedded.
HMSActionResultListenerMethod
HMSActionResultListenerMethod
is an enum which can be used to segregate the HMSActionResultListener
method type similar to what we did in above example.
enum HMSActionResultListenerMethod { leave, changeTrackState, changeMetadata, endRoom, removePeer, acceptChangeRole, changeRoleOfPeer, changeTrackStateForRole, startRtmpOrRecording, stopRtmpAndRecording, changeName, sendBroadcastMessage, sendGroupMessage, sendDirectMessage, hlsStreamingStarted, hlsStreamingStopped, startScreenShare, stopScreenShare, startAudioShare, stopAudioShare, setSessionMetadata, switchCamera, changeRoleOfPeersWithRoles, setSessionMetadataForKey, sendHLSTimedMetadata, lowerLocalPeerHand, lowerRemotePeerHand, raiseLocalPeerHand, quickStartPoll, addSingleChoicePollResponse, addMultiChoicePollResponse, //default case unknown }