HandRaise, Peer count and Support for Large Rooms

Previously, you had to implement handRaise functionality with peer metadata. But that is no more required. We have made raising/lowering hand as first class API on HMSSDK.

How to raise hand

hmsSDK.raiseLocalPeerHand(object : HMSActionResultListener{ override fun onSuccess() { Log.d(TAG, "Successfully raised hand") } override fun onError(error: HMSException) { Log.e(TAG, "Error while raising hand $error") } })

How to lower hand

hmsSDK.lowerLocalPeerHand(object : HMSActionResultListener{ override fun onSuccess() { Log.d(TAG, "Successfully raised hand") } override fun onError(error: HMSException) { Log.e(TAG, "Error while raising hand $error") } })

How to lower hand of remote peer

val remotePeer: HMSPeer hmsSDK.lowerRemotePeerHand(forPeer = remotePeer, object : HMSActionResultListener{ override fun onSuccess() { Log.d(TAG, "Successfully raised hand") } override fun onError(error: HMSException) { Log.e(TAG, "Error while raising hand $error") } })

How to know when a peer raises hand

Listen to callbacks when local or remote peer’s hand raise status is changed in onPeerUpdate() callback of HMSUpdateListener:

override fun onPeerUpdate(type: HMSPeerUpdate, hmsPeer: HMSPeer) { if(type == HMSPeerUpdate.HAND_RAISED_CHANGED) { // Get the new hand raise State of HMSPeer val isHandRaised : Boolean = hmsPeer.isHandRaised // Update UI of hmsPeer ... } }

How to fetch the status of handRaise of any peer.

isHandRaised property is added in HMSPeer to denote if hand is raised for the peer.

hmsPeer.isHandRaised

How to get Total Peer count of the room

Use peerCount property of HMSRoom to get the latest peer count of the room. Whenever peer count is updated, SDK sends a peerCountUpdated notification to the app in onRoomUpdate() as well.

override fun onRoomUpdate(type: HMSRoomUpdate, hmsRoom: HMSRoom) { if(update == HMSRoomUpdate.ROOM_PEER_COUNT_UPDATED) { // Update UI of peer count val peerCount = hmsRoom.peerCount } }

Supporting Large Scale Room

You don't want to fetch every peer if the room is very large, use the peer list iterator instead.

How to get peer list iterator in a large room

You call getPeerListIterator method on HMSSDK instance to get HMSPeerListIterator.

val options = PeerListIteratorOptions(byRoleName: String? = null, byPeerIds: ArrayList<String>? = null, limit: Int = 10) let peerListIterator = hmsSDK.getPeerListIterator(options: options)

If you wish to filter peers based on role name or peer ids, you can pass them in HMSPeerListIteratorOptions. limit is the number of peers you want to fetch in one go.

Now with peerListIterator instance you can incrementally load peers, or check peer count without fetching the peers.

How to use peer iterator to load peers incrementally

You can use next method on HMSPeerListIterator to fetch the next set of peers.

peerListIterator.next(object : PeerListResultListener{ override fun onSuccess(result: ArrayList<HMSPeer>) { // store newly loaded peers to show in UI } override fun onError(error: HMSException) { // Got error } })

How to check if more peers are available to load

You use hasNext property on HMSPeerListIterator to check if there are more peers available to fetch.

if (peerListIterator.hasNext()) { // load next set of peers }

How to check the total count of peers in the peer list

You use totalCount property on HMSPeerListIterator to know how many peers are there in the peer list.

let totalPeerCount = peerListIterator.totalCount

Search for peers

To just search for peers without getting all of them use:

HMSSDK.searchPeerNameInLargeRoomsearchPeerNameInLargeRoom( query: String, limit: Int, offset: Long, listener: HmsTypedActionResultListener<PeerSearchResponse>) {
  • query - substring of the peer's name that you want to search for.
  • limit - the number of peers you want returned for this query, max 100
  • offset - when looking for more peers than the max limit, send an offset for the next set.
  • listener: will return PeerSearchResponse in the onSuccess callback in this interface.
data class PeerSearchResponse( val eof: Boolean val offset: Long val count: Long val limit: Int val peers: List<HMSPeer> )

The peer search response contains:

  • eof - true if there are no more results, false otherwise.
  • offset - the offset requested.
  • count - the number of results.
  • limit - the limit that was given, max 100.
  • peers - the list of HMSPeer that match the search query.

Have a suggestion? Recommend changes ->

Was this helpful?

1234