Join Notification

Poor Connection Notification

Notifications can be used to display toast to user about activities happening in the room, such as peer join/leave or new messages. It can also be used to know about any mid call sdk level error.

In order to subscribe for notifications we can use the hmsNotifications object created in the integration step.

import { hmsNotifications } from './hms'; hmsNotifications.onNotification((notification) => { // This function will be called when a notification is received console.log('notification type', notification.type); // The data in notification depends on the notification type console.log('data',; });

Notification types

The notification type is a string and can only take values from the list here. You can use it to check the type of the notification.

The data in notification depends on the notification type. You can use the switch construct to the handle the notification type.

import { hmsNotifications, HMSNotificationTypes } from '@100mslive/hms-video-store'; const unsubscribe = hmsNotifications.onNotification((notification) => { console.log('notification type', notification.type); console.log('data',; // you can use the following to show appropriate toast notifications for example switch (notification.type) { case HMSNotificationTypes.PEER_LIST: console.log(`${} are the peers in the room`); // received right after join break; case HMSNotificationTypes.PEER_JOINED: console.log(`${} joined`); break; case HMSNotificationTypes.PEER_LEFT: console.log(`${} left`); break; case HMSNotificationTypes.NEW_MESSAGE: console.log( `${} received from ${}` ); break; case HMSNotificationTypes.ERROR: console.log('[Error]',; console.log('[Error Code]',; break; case HMSNotificationTypes.RECONNECTING: console.log('[Reconnecting]',; break; case HMSNotificationTypes.RECONNECTED: console.log('[Reconnected]'); break; case HMSNotificationTypes.NAME_UPDATED: case HMSNotificationTypes.METADATA_UPDATED: case HMSNotificationTypes.ROLE_UPDATED: console.log(`peer updated(${notification.type}), new peer=`,; break; case HMSNotificationTypes.TRACK_DEGRADED: console.log(`track - ${} degraded due to poor network`); break; case HMSNotificationTypes.TRACK_RESTORED: console.log(`track - ${} recovered`); break; case HMSNotificationTypes.ROOM_ENDED: console.log(`room ended, reason - ${}`); break; case HMSNotificationTypes.REMOVED_FROM_ROOM: console.log(`removed from room, reason - ${}`); break; case HMSNotificationTypes.DEVICE_CHANGE_UPDATE: console.log(`device changed - ${}`); break; default: break; } });

Listening to specific notifications

You can pass a single notification or array of notifications from one of HMSNotificationTypes.

import { hmsNotifications } from './hms'; const unsubscribe = hmsNotifications.onNotification((notification) => { console.log('notification type', notification.type); console.log('data',; }, HMSNotificationTypes.PEER_JOINED); const unsubscribePeerNotifications = hmsNotifications.onNotification( (notification) => { if (!notification) { return; } // this will be called when one of HMSNotificationTypes.PEER_JOINED, HMSNotificationTypes.PEER_LEFT is arrived console.log('notification type', notification.type); console.log('data',; }, [HMSNotificationTypes.PEER_JOINED, HMSNotificationTypes.PEER_LEFT] );

Unsubscribing from notifications

You can unsubscribe to the notifications by calling the method returned by the hmsNotifications.onNotification function.

const unsubscribe = hmsNotifications.onNotification((notification) => { //... }); unsubscribe();


You can create notifications with buttons in them, to make it easier for the end user to respond to those notifications. For example -

Screenshare Notification

Have a suggestion? Recommend changes ->

Was this helpful?