1- import React from 'react' ;
1+ import React , { useEffect } from 'react' ;
2+ import BackgroundSelectionDialog from '../BackgroundSelectionDialog/BackgroundSelectionDialog' ;
3+ import ChatWindow from '../ChatWindow/ChatWindow' ;
24import clsx from 'clsx' ;
5+ import { GridView } from '../GridView/GridView' ;
6+ import { MobileGridView } from '../MobileGridView/MobileGridView' ;
7+ import MainParticipant from '../MainParticipant/MainParticipant' ;
38import { makeStyles , Theme , useMediaQuery , useTheme } from '@material-ui/core' ;
4- import ChatWindow from '../ChatWindow/ChatWindow' ;
9+ import { Participant , Room as IRoom } from 'twilio-video' ;
10+ import { ParticipantAudioTracks } from '../ParticipantAudioTracks/ParticipantAudioTracks' ;
511import ParticipantList from '../ParticipantList/ParticipantList' ;
6- import MainParticipant from '../MainParticipant/MainParticipant' ;
7- import BackgroundSelectionDialog from '../BackgroundSelectionDialog/BackgroundSelectionDialog' ;
12+ import { useAppState } from '../../state' ;
813import useChatContext from '../../hooks/useChatContext/useChatContext' ;
14+ import useScreenShareParticipant from '../../hooks/useScreenShareParticipant/useScreenShareParticipant' ;
915import useVideoContext from '../../hooks/useVideoContext/useVideoContext' ;
10- import { ParticipantAudioTracks } from '../ParticipantAudioTracks/ParticipantAudioTracks' ;
11- import { GridView } from '../GridView/GridView' ;
12- import { MobileGridView } from '../MobileGridView/MobileGridView' ;
13- import { useAppState } from '../../state' ;
1416
1517const useStyles = makeStyles ( ( theme : Theme ) => {
1618 const totalMobileSidebarHeight = `${ theme . sidebarMobileHeight +
@@ -32,13 +34,30 @@ const useStyles = makeStyles((theme: Theme) => {
3234 } ;
3335} ) ;
3436
37+ export function useSetCollaborationViewOnScreenShare (
38+ screenShareParticipant : Participant | undefined ,
39+ room : IRoom | null ,
40+ setIsGridModeActive : React . Dispatch < React . SetStateAction < boolean > >
41+ ) {
42+ useEffect ( ( ) => {
43+ if ( screenShareParticipant && screenShareParticipant !== room ! . localParticipant ) {
44+ setIsGridModeActive ( false ) ;
45+ }
46+ } , [ screenShareParticipant , setIsGridModeActive , room ] ) ;
47+ }
48+
3549export default function Room ( ) {
3650 const classes = useStyles ( ) ;
3751 const { isChatWindowOpen } = useChatContext ( ) ;
38- const { isBackgroundSelectionOpen } = useVideoContext ( ) ;
39- const { isGridModeActive } = useAppState ( ) ;
52+ const { isBackgroundSelectionOpen, room } = useVideoContext ( ) ;
53+ const { isGridModeActive, setIsGridModeActive } = useAppState ( ) ;
4054 const theme = useTheme ( ) ;
4155 const isMobile = useMediaQuery ( theme . breakpoints . down ( 'sm' ) ) ;
56+ const screenShareParticipant = useScreenShareParticipant ( ) ;
57+
58+ // Here we switch to collaboration view when a participant starts sharing their screen, but
59+ // the user is still free to switch back to grid mode.
60+ useSetCollaborationViewOnScreenShare ( screenShareParticipant , room , setIsGridModeActive ) ;
4261
4362 return (
4463 < div
0 commit comments