Remove Peer

Someone's overstayed their welcome and now you need to remove a peer from the chat. Just call hmsActions.removePeer.

Remove Peer

Removing a peer

Use the selectPermissions selector to check whether the local peer has the removeOthers permission and then call hmsActions.removePeer to end the room with peerID of the HMSRemotePeer that you'd like to be removed from the call and the reason.

try { await hmsActions.removePeer(peer.id, 'Good bye'); } catch (error) { // Permission denied or invalid peer ID or not connected to room console.error(error); }

🚧 If the local peer doesn't have the required removeOthers permission, the hmsActions.removePeer call will throw an HMSException error.

Handling the remove peer notification

Once the peer with adequate permissions calls removePeer for the local peer, the local peer will receive a notification with type REMOVED_FROM_ROOM 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 dialog, redirect to a 'good-bye' page) on receiving this notification.

hmsNotifications.onNotification((notification) => { if (!notification) { return; } switch (notification.type) { // ...Other notification type cases case 'REMOVED_FROM_ROOM': // Redirect or Show toast to user toast('Reason: ', notification.data.reason); break; } });