End Room
Done with talking and it's time to end the call for everyone not just yourself? You may be looking to end the room.
Ending the Room
Use the selectPermissions
selector to check whether the local peer has the endRoom
permission to end the room and then call hmsActions.endRoom
to end the room with lock
(true
to prevent rejoining) and reason
.
function renderEndRoomButton(permissions) { const endRoomButton = document.getElementById('end-room-button'); if (permissions.endRoom) { endRoomButton.addEventListener('click', function () { try { await hmsActions.endRoom(lock, 'Reason goes here'); } catch (error) { // Permission denied or not connected to room console.error(error); } }); endRoomButton.style.display = 'inline-block'; } else { endRoomButton.style.display = 'none'; } } // subscribe to the permissions, so render is called whenever there is a change due to role change hmsStore.subscribe(renderEndRoomButton, selectPermissions);
💡 After calling endRoom the local peer needs to dispose of the video calling UI as well.
🚧 If the local peer doesn't have the required endRoom
permission, the hmsActions.endRoom
call will throw an HMSException error.
Handling end room by a remote peer
Once the peer with adequate permissions calls endRoom
, all other peers in the room will receive a notification with type ROOM_ENDED
with a HMSLeaveRoomRequest object as the data.
The SDK automatically calls leave and performs necessary clean ups immediately after this notification is sent, clients should show the appropriate UI(show a toast, redirect to a 'good-bye' page) within this period.
hmsNotifications.onNotification((notification) => { if (!notification) { return; } switch (notification.type) { // ...Other notification type cases case 'ROOM_ENDED': // Redirect or Show toast to user toast(notification.data.reason); break; } });