End Room

Done with talking and it's time to end the video call room for everyone not just yourself? You may be looking to end the room.

Permissions

Can't let just anyone end the video call room. First you need to create a role with the permissions to end a room.

The permission to end a room is called PermissionsParams.endRoom and you should check for that within the HMSRole of the peer to see if they have it.

Here's how to check whether the local peer has the permission to end the room:

fun isAllowedToEndMeeting(): Boolean { return hmsSDK.getLocalPeer()!! .hmsRole.permission? .endRoom == true }

hmsSdk.getLocalPeer() will not return null as long as you're in a preview or in a meeting. Since you likely won't need to check for permissions if you're not in one it would be ok.

Ending the Room

Once you're sure the peer has the permissions to end the room, they can end it by calling hmsSdk.endRoom.

endRoom takes three parameters.

  1. message: The String message you want to show people when they are forced to leave. This is a good place to thank them for joining the room and informing them that it has ended.
  2. lock: A Boolean for whether you want to prevent anyone from rejoining the room. If false, they will be allowed to enter the room again if the client called join. If this is true, they will NOT able to join this room again.
  3. hmsActionResultListener: These are the callbacks that let you know whether the room was ended successfully or not. If the room could be closed, onSuccess will be called. For any errors onError will be called with the appropriate HMSException.

💡 After calling endRoom the video calling UI should be disposed of as well since only the other peers will get the onPeerRemoved callback. The caller has to rely on the onSuccess callback for endRoom to decide when to terminate the meeting room UI locally.

val message = "Closing time. Thanks for coming!" val lock = false hmsSDK.endRoom(message, lock, object : HMSActionResultListener{ override fun onError(error: HMSException) { } override fun onSuccess() { } })

How to handle an end room callback for receivers

Once the peer with adequate permissions calls endRoom, all other peers in the room will receive a callback in HMSUpdateListener.onRemovedFromRoom.

The onRemovedFromRoom callback has a single parameter called HMSRemovedFromRoom with the following structure.

data class HMSRemovedFromRoom( val reason : String, val peerWhoRemoved : HMSRemotePeer?, val roomWasEnded : Boolean )

💡 This is the same callback that will be triggered if a peer was removed from a room as well. Except that roomEnded will be true when the entire room was ended.

  • reason: The string message detailing why the room was ended.
  • peerWhoRemoved: The details of the peer who called endRoom.
  • roomWasEnded: True if the entire room was ended. False if only the receiving peer was removed.

Clients should read this callback and show the appropriate UI.