Skip to content

Commit

Permalink
fix: hide the video element when a placeholder is visible (#1094)
Browse files Browse the repository at this point in the history
Applies `display: none` to the `<video>` element when the participant's
video isn't playing and a placeholder is visible.
Enables building nicer user experience in designs that Video Placeholder
that utilize transparency.

Styling is done through `str-video__video--no-video` CSS selector that
allows an integrator to further customize the behavior and attach more
custom styles.

### Implementation notes
The `<video>` element needs to stay mounted as we need to be notified
about it's `play` or `pause` events that may occur in an uncontrolled
fashion in poor network conditions (e.g.: huge packet loss, the browser
may pause the video, and once the network is stable enough, will resume
playback).
  • Loading branch information
oliverlaz authored Sep 18, 2023
1 parent 4b523f4 commit 9efd84c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ export const DefaultVideoPlaceholder = forwardRef<
VideoPlaceholderProps
>(({ participant, style }, ref) => {
const [error, setError] = useState(false);

const name = participant?.name || participant?.userId;

const name = participant.name || participant.userId;
return (
<div className="str-video__video-placeholder" style={style} ref={ref}>
{(!participant.image || error) &&
Expand Down
25 changes: 12 additions & 13 deletions packages/react-sdk/src/core/components/Video/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,18 @@ export const Video = ({
const [isWideMode, setIsWideMode] = useState(true);

const stream =
trackType === 'none'
? undefined
: trackType === 'videoTrack'
trackType === 'videoTrack'
? videoStream
: screenShareStream;
: trackType === 'screenShareTrack'
? screenShareStream
: undefined;

const isPublishingTrack =
trackType === 'none'
? false
: publishedTracks.includes(
trackType === 'videoTrack'
? SfuModels.TrackType.VIDEO
: SfuModels.TrackType.SCREEN_SHARE,
);
trackType === 'videoTrack'
? publishedTracks.includes(SfuModels.TrackType.VIDEO)
: trackType === 'screenShareTrack'
? publishedTracks.includes(SfuModels.TrackType.SCREEN_SHARE)
: false;

const isInvisible =
trackType === 'none' ||
Expand Down Expand Up @@ -118,14 +116,15 @@ export const Video = ({

if (!call) return null;

const mirrorVideo = isLocalParticipant && trackType === 'videoTrack';
return (
<>
<video
{...rest}
className={clsx(className, 'str-video__video', {
'str-video__video--no-video': displayPlaceholder,
'str-video__video--tall': !isWideMode,
'str-video__video--mirror':
isLocalParticipant && trackType === 'videoTrack',
'str-video__video--mirror': mirrorVideo,
'str-video__video--screen-share': trackType === 'screenShareTrack',
})}
data-user-id={userId}
Expand Down
4 changes: 4 additions & 0 deletions packages/styling/src/Video/Video-layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@
&--mirror {
transform: scaleX(-1);
}

&--no-video {
display: none;
}
}

0 comments on commit 9efd84c

Please sign in to comment.