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 issues where together mode stream keeps loading unitl views are c… #5724

Merged
merged 4 commits into from
Mar 26, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -262,3 +262,8 @@ export const memoizeTogetherModeStreams = memoizeOne((togetherModeStreams) => ({
streamSize: togetherModeStreams?.mainVideoStream?.streamSize
}
}));

/** @private */
export const memoizeTogetherModeSeatingPositions = memoizeOne(
(togetherModeSeatingCoordinates) => togetherModeSeatingCoordinates
);
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
_dominantSpeakersWithFlatId,
convertRemoteParticipantToVideoGalleryRemoteParticipant,
memoizeLocalParticipant,
/* @conditional-compile-remove(together-mode) */ memoizeTogetherModeStreams
/* @conditional-compile-remove(together-mode) */ memoizeTogetherModeStreams,
/* @conditional-compile-remove(together-mode) */ memoizeTogetherModeSeatingPositions
} from './utils/videoGalleryUtils';
import { memoizeSpotlightedParticipantIds } from './utils/videoGalleryUtils';
import { getLocalParticipantRaisedHand } from './baseSelectors';
Expand Down Expand Up @@ -165,7 +166,7 @@ export const videoGallerySelector: VideoGallerySelector = createSelector(
/* @conditional-compile-remove(together-mode) */
togetherModeStreams: memoizeTogetherModeStreams(togetherModeCallFeature?.streams),
/* @conditional-compile-remove(together-mode) */
togetherModeSeatingCoordinates: togetherModeCallFeature?.seatingPositions,
togetherModeSeatingCoordinates: memoizeTogetherModeSeatingPositions(togetherModeCallFeature?.seatingPositions),
/* @conditional-compile-remove(together-mode) */
isTogetherModeActive: togetherModeCallFeature?.isActive,
/* @conditional-compile-remove(together-mode) */
Expand Down
69 changes: 35 additions & 34 deletions packages/react-components/src/components/VideoGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -820,26 +820,37 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
? localScreenShareStreamComponent
: undefined;

/* @conditional-compile-remove(together-mode) */
// Current implementation of capabilities is only based on user role.
// This logic checks for the user role and if the user is a Teams user.
const canSwitchToTogetherModeLayout =
isTogetherModeActive || (_isIdentityMicrosoftTeamsUser(localParticipant.userId) && startTogetherModeEnabled);

/* @conditional-compile-remove(together-mode) */
const togetherModeStreamComponent = useMemo(
() => (
<TogetherModeStream
startTogetherModeEnabled={startTogetherModeEnabled}
isTogetherModeActive={isTogetherModeActive}
onCreateTogetherModeStreamView={onCreateTogetherModeStreamView}
onStartTogetherMode={onStartTogetherMode}
onDisposeTogetherModeStreamView={onDisposeTogetherModeStreamView}
onSetTogetherModeSceneSize={onSetTogetherModeSceneSize}
togetherModeStreams={togetherModeStreams}
seatingCoordinates={togetherModeSeatingCoordinates}
localParticipant={localParticipant}
remoteParticipants={remoteParticipants}
reactionResources={reactionResources}
containerWidth={containerWidth}
containerHeight={containerHeight}
/>
),
() =>
// Avoids unnecessary rendering of TogetherModeStream component when it is not needed
!screenShareComponent && canSwitchToTogetherModeLayout && layout === 'togetherMode' ? (
<TogetherModeStream
startTogetherModeEnabled={startTogetherModeEnabled}
isTogetherModeActive={isTogetherModeActive}
onCreateTogetherModeStreamView={onCreateTogetherModeStreamView}
onStartTogetherMode={onStartTogetherMode}
onDisposeTogetherModeStreamView={onDisposeTogetherModeStreamView}
onSetTogetherModeSceneSize={onSetTogetherModeSceneSize}
togetherModeStreams={togetherModeStreams}
seatingCoordinates={togetherModeSeatingCoordinates}
localParticipant={localParticipant}
remoteParticipants={remoteParticipants}
reactionResources={reactionResources}
containerWidth={containerWidth}
containerHeight={containerHeight}
/>
) : undefined,
[
layout,
screenShareComponent,
canSwitchToTogetherModeLayout,
startTogetherModeEnabled,
isTogetherModeActive,
onCreateTogetherModeStreamView,
Expand All @@ -855,11 +866,6 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
containerHeight
]
);
/* @conditional-compile-remove(together-mode) */
// Current implementation of capabilities is only based on user role.
// This logic checks for the user role and if the user is a Teams user.
const canSwitchToTogetherModeLayout =
isTogetherModeActive || (_isIdentityMicrosoftTeamsUser(localParticipant.userId) && startTogetherModeEnabled);

const layoutProps = useMemo<LayoutProps>(
() => ({
Expand All @@ -877,7 +883,8 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
pinnedParticipantUserIds: pinnedParticipants,
overflowGalleryPosition,
localVideoTileSize,
spotlightedParticipantUserIds: spotlightedParticipants
spotlightedParticipantUserIds: spotlightedParticipants,
togetherModeStreamComponent
}),
[
remoteParticipants,
Expand All @@ -895,7 +902,8 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
pinnedParticipants,
overflowGalleryPosition,
localVideoTileSize,
spotlightedParticipants
spotlightedParticipants,
togetherModeStreamComponent
]
);

Expand All @@ -917,18 +925,11 @@ export const VideoGallery = (props: VideoGalleryProps): JSX.Element => {
/* @conditional-compile-remove(together-mode) */
// Teams users can switch to Together mode layout only if they have the capability,
// while ACS users can do so only if Together mode is enabled.
if (!screenShareComponent && layout === 'togetherMode' && canSwitchToTogetherModeLayout) {
return <TogetherModeLayout togetherModeStreamComponent={togetherModeStreamComponent} />;
if (layoutProps.togetherModeStreamComponent && layout === 'togetherMode') {
return <TogetherModeLayout togetherModeStreamComponent={layoutProps.togetherModeStreamComponent} />;
}
return <DefaultLayout {...layoutProps} />;
}, [
/* @conditional-compile-remove(together-mode) */ canSwitchToTogetherModeLayout,
layout,
layoutProps,
screenShareComponent,
screenShareParticipant,
/* @conditional-compile-remove(together-mode) */ togetherModeStreamComponent
]);
}, [layout, layoutProps, screenShareParticipant]);

return (
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
TogetherModeStreamViewResult,
VideoGalleryLocalParticipant,
VideoGalleryRemoteParticipant,
VideoStreamOptions
VideoStreamOptions,
TogetherModeStreamOptions
} from '../../types';
/* @conditional-compile-remove(together-mode) */
import { StreamMedia } from '../StreamMedia';
Expand All @@ -33,7 +34,9 @@ export const TogetherModeStream = memo(
(props: {
startTogetherModeEnabled?: boolean;
isTogetherModeActive?: boolean;
onCreateTogetherModeStreamView?: (options?: VideoStreamOptions) => Promise<void | TogetherModeStreamViewResult>;
onCreateTogetherModeStreamView?: (
options?: TogetherModeStreamOptions
) => Promise<void | TogetherModeStreamViewResult>;
onStartTogetherMode?: (options?: VideoStreamOptions) => Promise<void | TogetherModeStreamViewResult>;
onDisposeTogetherModeStreamView?: () => Promise<void>;
onSetTogetherModeSceneSize?: (width: number, height: number) => void;
Expand Down Expand Up @@ -73,10 +76,14 @@ export const TogetherModeStream = memo(

// Create stream view if not already created
useEffect(() => {
if (!togetherModeStreams?.mainVideoStream?.renderElement) {
if (togetherModeStreams?.mainVideoStream?.isAvailable && !togetherModeStreams?.mainVideoStream?.renderElement) {
onCreateTogetherModeStreamView?.();
}
}, [togetherModeStreams?.mainVideoStream?.renderElement, onCreateTogetherModeStreamView]);
}, [
togetherModeStreams?.mainVideoStream?.renderElement,
togetherModeStreams?.mainVideoStream?.isAvailable,
onCreateTogetherModeStreamView
]);

// Update scene size only when container dimensions change
useMemo(() => {
Expand Down
Loading