Skip to content

Commit

Permalink
fix: send role in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
KaustubhKumar05 committed Aug 12, 2024
1 parent cadc7ef commit 774f96b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/react-sdk/src/hooks/useAwayNotifications.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
// write a hook to use the MDN notifications API to show a notification when the user is away from the page
import { useCallback } from 'react';
import { selectLocalPeerRoleName } from '@100mslive/hms-video-store';
import { useHMSVanillaStore } from '../primitives/HmsRoomProvider';
import { useHMSActions, useHMSVanillaStore } from '../primitives/HmsRoomProvider';

// Do not prompt if preview is not available. Skips for beam
export const useAwayNotifications = () => {
const vanillaStore = useHMSVanillaStore();
const hmsActions = useHMSActions();
const requestPermission = useCallback(async () => {
if (!Notification || Notification?.permission === 'granted') {
if (!Notification || Notification?.permission === 'granted' || Notification?.permission === 'denied') {
return;
}
const unsubscribe = vanillaStore.subscribe(async role => {
if (role && role !== '__internal_recorder') {
hmsActions?.sendBroadcastMessage(role);
await Notification.requestPermission();
unsubscribe?.();
}
}, selectLocalPeerRoleName);
}, [vanillaStore]);
}, [vanillaStore, hmsActions]);

const showNotification = useCallback((title: string, options?: NotificationOptions) => {
if (
Expand Down

0 comments on commit 774f96b

Please sign in to comment.