100ms Logo

100ms

Docs

Search docs
/

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.

How to End 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 permissions.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:

const localPeer = await hmsInstance.getLocalPeer(); const haveEndRoomPermission = localPeer.role?.permissions?.endRoom;

await hmsInstance.getLocalPeer() will not return null/undefined as long as you're in a preview or in a room. Since you likely won't need to check for permissions if you're not in one it would be safe to omit null check.

Ending the Room

Once you're sure the peer has the permissions to end the room, we can end the room by calling:

const reason = 'Host ended the room'; // Reason to end the room const lock = false; // whether to Lock room to prevent future joins try { // instance acquired from build() method await hmsInstance.endRoom(reason, lock); console.log('End Room Success'); // Navigate away from the Meeting screen, when end room is successful navigation.goBack(); } catch (error) { console.log('End Room Error: ', error); }

endRoom takes the following parameters -

  1. 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.
  2. reason: reason string is the text that is passed describing why the room is being ended.

💡 After calling endRoom, the video calling UI should be disposed of as well since only other peers will get the HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM event. The caller can terminate the meeting room UI locally when the promise returned from endRoom is resolved.

Handle App UI When Someone else Ends Room

This section explains how to handle the app UI when someone else ends the room.

Once the peer with adequate permissions calls endRoom, all other peers in the room will receive a HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM event.

You can update your apps' UI and Free Resources on receive of HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM event.

const onRemovedFromRoom = (data: { requestedBy: HMSPeer | null, reason: string, roomEnded: boolean }) => { // Free App resources and do cleanup destroy(); // Redirect to home screen or Navigate away from Meeting screen navigation.navigate('Home'); }; hmsInstance.addEventListener(HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM, onRemovedFromRoom);

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

Description of keys of data received from HMSUpdateListenerActions.ON_REMOVED_FROM_ROOM event:

  • reason: The string message detailing why the room was ended.
  • requestedBy: The details of the peer who called endRoom.
  • roomEnded: true if the entire room was ended. false if only the receiving peer(local peer) was removed.

Have a suggestion? Recommend changes ->

Was this helpful?

1234