Skip to content

Commit df9e681

Browse files
cn0151mgamis-msft
authored andcommitted
Fix issues where together mode stream keeps loading unitl views are c… (#5724)
* Fix issues where together mode stream keeps loading unitl views are changed * Ensure the togethe mode view shows only in Teams call /Teams meeting
1 parent 10a9987 commit df9e681

File tree

4 files changed

+54
-40
lines changed

4 files changed

+54
-40
lines changed

packages/calling-component-bindings/src/utils/videoGalleryUtils.ts

+5
Original file line numberDiff line numberDiff line change
@@ -262,3 +262,8 @@ export const memoizeTogetherModeStreams = memoizeOne((togetherModeStreams) => ({
262262
streamSize: togetherModeStreams?.mainVideoStream?.streamSize
263263
}
264264
}));
265+
266+
/** @private */
267+
export const memoizeTogetherModeSeatingPositions = memoizeOne(
268+
(togetherModeSeatingCoordinates) => togetherModeSeatingCoordinates
269+
);

packages/calling-component-bindings/src/videoGallerySelector.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import {
3232
_dominantSpeakersWithFlatId,
3333
convertRemoteParticipantToVideoGalleryRemoteParticipant,
3434
memoizeLocalParticipant,
35-
/* @conditional-compile-remove(together-mode) */ memoizeTogetherModeStreams
35+
/* @conditional-compile-remove(together-mode) */ memoizeTogetherModeStreams,
36+
/* @conditional-compile-remove(together-mode) */ memoizeTogetherModeSeatingPositions
3637
} from './utils/videoGalleryUtils';
3738
import { memoizeSpotlightedParticipantIds } from './utils/videoGalleryUtils';
3839
import { getLocalParticipantRaisedHand } from './baseSelectors';
@@ -165,7 +166,7 @@ export const videoGallerySelector: VideoGallerySelector = createSelector(
165166
/* @conditional-compile-remove(together-mode) */
166167
togetherModeStreams: memoizeTogetherModeStreams(togetherModeCallFeature?.streams),
167168
/* @conditional-compile-remove(together-mode) */
168-
togetherModeSeatingCoordinates: togetherModeCallFeature?.seatingPositions,
169+
togetherModeSeatingCoordinates: memoizeTogetherModeSeatingPositions(togetherModeCallFeature?.seatingPositions),
169170
/* @conditional-compile-remove(together-mode) */
170171
isTogetherModeActive: togetherModeCallFeature?.isActive,
171172
/* @conditional-compile-remove(together-mode) */

packages/react-components/src/components/VideoGallery.tsx

+35-34
Original file line numberDiff line numberDiff line change
@@ -820,26 +820,37 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
820820
? localScreenShareStreamComponent
821821
: undefined;
822822

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+
823829
/* @conditional-compile-remove(together-mode) */
824830
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,
842850
[
851+
layout,
852+
screenShareComponent,
853+
canSwitchToTogetherModeLayout,
843854
startTogetherModeEnabled,
844855
isTogetherModeActive,
845856
onCreateTogetherModeStreamView,
@@ -855,11 +866,6 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
855866
containerHeight
856867
]
857868
);
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);
863869

864870
const layoutProps = useMemo<LayoutProps>(
865871
() => ({
@@ -877,7 +883,8 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
877883
pinnedParticipantUserIds: pinnedParticipants,
878884
overflowGalleryPosition,
879885
localVideoTileSize,
880-
spotlightedParticipantUserIds: spotlightedParticipants
886+
spotlightedParticipantUserIds: spotlightedParticipants,
887+
togetherModeStreamComponent
881888
}),
882889
[
883890
remoteParticipants,
@@ -895,7 +902,8 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
895902
pinnedParticipants,
896903
overflowGalleryPosition,
897904
localVideoTileSize,
898-
spotlightedParticipants
905+
spotlightedParticipants,
906+
togetherModeStreamComponent
899907
]
900908
);
901909

@@ -917,18 +925,11 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
917925
/* @conditional-compile-remove(together-mode) */
918926
// Teams users can switch to Together mode layout only if they have the capability,
919927
// 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} />;
922930
}
923931
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]);
932933

933934
return (
934935
<div

packages/react-components/src/components/VideoGallery/TogetherModeStream.tsx

+11-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
TogetherModeStreamViewResult,
1414
VideoGalleryLocalParticipant,
1515
VideoGalleryRemoteParticipant,
16-
VideoStreamOptions
16+
VideoStreamOptions,
17+
TogetherModeStreamOptions
1718
} from '../../types';
1819
/* @conditional-compile-remove(together-mode) */
1920
import { StreamMedia } from '../StreamMedia';
@@ -33,7 +34,9 @@ export const TogetherModeStream = memo(
3334
(props: {
3435
startTogetherModeEnabled?: boolean;
3536
isTogetherModeActive?: boolean;
36-
onCreateTogetherModeStreamView?: (options?: VideoStreamOptions) => Promise<void | TogetherModeStreamViewResult>;
37+
onCreateTogetherModeStreamView?: (
38+
options?: TogetherModeStreamOptions
39+
) => Promise<void | TogetherModeStreamViewResult>;
3740
onStartTogetherMode?: (options?: VideoStreamOptions) => Promise<void | TogetherModeStreamViewResult>;
3841
onDisposeTogetherModeStreamView?: () => Promise<void>;
3942
onSetTogetherModeSceneSize?: (width: number, height: number) => void;
@@ -73,10 +76,14 @@ export const TogetherModeStream = memo(
7376

7477
// Create stream view if not already created
7578
useEffect(() => {
76-
if (!togetherModeStreams?.mainVideoStream?.renderElement) {
79+
if (togetherModeStreams?.mainVideoStream?.isAvailable && !togetherModeStreams?.mainVideoStream?.renderElement) {
7780
onCreateTogetherModeStreamView?.();
7881
}
79-
}, [togetherModeStreams?.mainVideoStream?.renderElement, onCreateTogetherModeStreamView]);
82+
}, [
83+
togetherModeStreams?.mainVideoStream?.renderElement,
84+
togetherModeStreams?.mainVideoStream?.isAvailable,
85+
onCreateTogetherModeStreamView
86+
]);
8087

8188
// Update scene size only when container dimensions change
8289
useMemo(() => {

0 commit comments

Comments
 (0)