@@ -820,26 +820,37 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
820
820
? localScreenShareStreamComponent
821
821
: undefined ;
822
822
823
+ /* @conditional -compile-remove(together-mode) */
824
+ // Current implementation of capabilities is only based on user role.
825
+ // This logic checks for the user role and if the user is a Teams user.
826
+ const canSwitchToTogetherModeLayout =
827
+ isTogetherModeActive || ( _isIdentityMicrosoftTeamsUser ( localParticipant . userId ) && startTogetherModeEnabled ) ;
828
+
823
829
/* @conditional -compile-remove(together-mode) */
824
830
const togetherModeStreamComponent = useMemo (
825
- ( ) => (
826
- < TogetherModeStream
827
- startTogetherModeEnabled = { startTogetherModeEnabled }
828
- isTogetherModeActive = { isTogetherModeActive }
829
- onCreateTogetherModeStreamView = { onCreateTogetherModeStreamView }
830
- onStartTogetherMode = { onStartTogetherMode }
831
- onDisposeTogetherModeStreamView = { onDisposeTogetherModeStreamView }
832
- onSetTogetherModeSceneSize = { onSetTogetherModeSceneSize }
833
- togetherModeStreams = { togetherModeStreams }
834
- seatingCoordinates = { togetherModeSeatingCoordinates }
835
- localParticipant = { localParticipant }
836
- remoteParticipants = { remoteParticipants }
837
- reactionResources = { reactionResources }
838
- containerWidth = { containerWidth }
839
- containerHeight = { containerHeight }
840
- />
841
- ) ,
831
+ ( ) =>
832
+ // Avoids unnecessary rendering of TogetherModeStream component when it is not needed
833
+ ! screenShareComponent && canSwitchToTogetherModeLayout && layout === 'togetherMode' ? (
834
+ < TogetherModeStream
835
+ startTogetherModeEnabled = { startTogetherModeEnabled }
836
+ isTogetherModeActive = { isTogetherModeActive }
837
+ onCreateTogetherModeStreamView = { onCreateTogetherModeStreamView }
838
+ onStartTogetherMode = { onStartTogetherMode }
839
+ onDisposeTogetherModeStreamView = { onDisposeTogetherModeStreamView }
840
+ onSetTogetherModeSceneSize = { onSetTogetherModeSceneSize }
841
+ togetherModeStreams = { togetherModeStreams }
842
+ seatingCoordinates = { togetherModeSeatingCoordinates }
843
+ localParticipant = { localParticipant }
844
+ remoteParticipants = { remoteParticipants }
845
+ reactionResources = { reactionResources }
846
+ containerWidth = { containerWidth }
847
+ containerHeight = { containerHeight }
848
+ />
849
+ ) : undefined ,
842
850
[
851
+ layout ,
852
+ screenShareComponent ,
853
+ canSwitchToTogetherModeLayout ,
843
854
startTogetherModeEnabled ,
844
855
isTogetherModeActive ,
845
856
onCreateTogetherModeStreamView ,
@@ -855,11 +866,6 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
855
866
containerHeight
856
867
]
857
868
) ;
858
- /* @conditional -compile-remove(together-mode) */
859
- // Current implementation of capabilities is only based on user role.
860
- // This logic checks for the user role and if the user is a Teams user.
861
- const canSwitchToTogetherModeLayout =
862
- isTogetherModeActive || ( _isIdentityMicrosoftTeamsUser ( localParticipant . userId ) && startTogetherModeEnabled ) ;
863
869
864
870
const layoutProps = useMemo < LayoutProps > (
865
871
( ) => ( {
@@ -877,7 +883,8 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
877
883
pinnedParticipantUserIds : pinnedParticipants ,
878
884
overflowGalleryPosition,
879
885
localVideoTileSize,
880
- spotlightedParticipantUserIds : spotlightedParticipants
886
+ spotlightedParticipantUserIds : spotlightedParticipants ,
887
+ togetherModeStreamComponent
881
888
} ) ,
882
889
[
883
890
remoteParticipants ,
@@ -895,7 +902,8 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
895
902
pinnedParticipants ,
896
903
overflowGalleryPosition ,
897
904
localVideoTileSize ,
898
- spotlightedParticipants
905
+ spotlightedParticipants ,
906
+ togetherModeStreamComponent
899
907
]
900
908
) ;
901
909
@@ -917,18 +925,11 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
917
925
/* @conditional -compile-remove(together-mode) */
918
926
// Teams users can switch to Together mode layout only if they have the capability,
919
927
// while ACS users can do so only if Together mode is enabled.
920
- if ( ! screenShareComponent && layout === 'togetherMode' && canSwitchToTogetherModeLayout ) {
921
- return < TogetherModeLayout togetherModeStreamComponent = { togetherModeStreamComponent } /> ;
928
+ if ( layoutProps . togetherModeStreamComponent && layout === 'togetherMode' ) {
929
+ return < TogetherModeLayout togetherModeStreamComponent = { layoutProps . togetherModeStreamComponent } /> ;
922
930
}
923
931
return < DefaultLayout { ...layoutProps } /> ;
924
- } , [
925
- /* @conditional -compile-remove(together-mode) */ canSwitchToTogetherModeLayout ,
926
- layout ,
927
- layoutProps ,
928
- screenShareComponent ,
929
- screenShareParticipant ,
930
- /* @conditional -compile-remove(together-mode) */ togetherModeStreamComponent
931
- ] ) ;
932
+ } , [ layout , layoutProps , screenShareParticipant ] ) ;
932
933
933
934
return (
934
935
< div
0 commit comments