Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove peer, end room flow #1849

Merged
merged 5 commits into from
Sep 7, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-case-declarations */
import React, { useCallback, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { useNavigate, useParams } from 'react-router-dom';
import {
HMSNotificationTypes,
HMSRoomState,
Expand All @@ -10,7 +10,9 @@ import {
useHMSStore,
} from '@100mslive/react-sdk';
import { Button } from '../../../';
import { useHMSPrebuiltContext } from '../../AppContext';
import { useUpdateRoomLayout } from '../../provider/roomLayoutProvider';
import { PictureInPicture } from '../PIP/PIPManager';
import { ToastBatcher } from '../Toast/ToastBatcher';
import { ToastManager } from '../Toast/ToastManager';
import { AutoplayBlockedModal } from './AutoplayBlockedModal';
Expand All @@ -21,17 +23,21 @@ import { ReconnectNotifications } from './ReconnectNotifications';
import { TrackBulkUnmuteModal } from './TrackBulkUnmuteModal';
import { TrackNotifications } from './TrackNotifications';
import { TrackUnmuteModal } from './TrackUnmuteModal';
import { useRoomLayoutLeaveScreen } from '../../provider/roomLayoutProvider/hooks/useRoomLayoutScreen';
import { useIsNotificationDisabled, useSubscribedNotifications } from '../AppData/useUISettings';
import { getMetadata } from '../../common/utils';
import { ROLE_CHANGE_DECLINED } from '../../common/constants';

export function Notifications() {
const notification = useHMSNotifications();
const navigate = useNavigate();
const params = useParams();
const subscribedNotifications = useSubscribedNotifications() || {};
const roomState = useHMSStore(selectRoomState);
const updateRoomLayoutForRole = useUpdateRoomLayout();
const isNotificationDisabled = useIsNotificationDisabled();
const { isLeaveScreenEnabled } = useRoomLayoutLeaveScreen();
const { onLeave } = useHMSPrebuiltContext();

const handleRoleChangeDenied = useCallback(request => {
ToastManager.addToast({
Expand All @@ -42,6 +48,20 @@ export function Notifications() {

useCustomEvent({ type: ROLE_CHANGE_DECLINED, onEvent: handleRoleChangeDenied });

const redirectToLeavePage = () => {
raviteja83 marked this conversation as resolved.
Show resolved Hide resolved
setTimeout(() => {
const prefix = isLeaveScreenEnabled ? '/leave/' : '/';
if (params.role) {
navigate(prefix + params.roomId + '/' + params.role);
} else {
navigate(prefix + params.roomId);
}
PictureInPicture.stop().catch(() => console.error('stopping pip'));
ToastManager.clearAllToast();
onLeave?.();
}, 1000);
};

useEffect(() => {
if (!notification || isNotificationDisabled) {
return;
Expand Down Expand Up @@ -80,7 +100,7 @@ export function Notifications() {
<Button
onClick={() => {
ToastManager.removeToast(toastId);
window.location.reload();
navigate(`/${params.roomCode || params.roomId}${params.role ? `/${params.role}` : ''}`);
}}
>
Rejoin
Expand All @@ -91,11 +111,7 @@ export function Notifications() {
}
// goto leave for terminal if any action is not performed within 2secs
// if network is still unavailable going to preview will throw an error
setTimeout(() => {
const previewLocation = window.location.pathname.replace('meeting', 'leave');
ToastManager.clearAllToast();
navigate(previewLocation);
}, 2000);
redirectToLeavePage();
return;
}
// Autoplay error or user denied screen share (cancelled browser pop-up)
Expand Down Expand Up @@ -133,11 +149,7 @@ export function Notifications() {
title: `${notification.message}.
${notification.data.reason && `Reason: ${notification.data.reason}`}`,
});
setTimeout(() => {
const leaveLocation = window.location.pathname.replace('meeting', 'leave');
navigate(leaveLocation);
ToastManager.clearAllToast();
}, 2000);
redirectToLeavePage();
break;
case HMSNotificationTypes.DEVICE_CHANGE_UPDATE:
ToastManager.addToast({
Expand Down
Loading