Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Commit

Permalink
Enable controlling local stream mirroring by introducing isMirrored
Browse files Browse the repository at this point in the history
…-prop (#82)

* Simplify code, reduce duplication, express intent clearer

* the `isLocal &&` logic was effectively duplicated in `isFrontFacing`,
  but does not semantically answer this yes/no question
* `isFrontFacing` was not the most appropriate name so far, as it is
  also `true` when `facingMode` or `mediaStreamTrack` are undefined,
  hence this is a better name

* Add `isMirrored`-prop to enable overriding the default behaviour

Closes #29

* Create wild-otters-complain.md

Co-authored-by: David Zhao <[email protected]>
  • Loading branch information
Philzen and davidzhao authored Aug 6, 2022
1 parent 7a2a96f commit d94b678
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/wild-otters-complain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@livekit/react-core": patch
---

Enable controlling local stream mirroring by introducing `isMirrored`-prop
15 changes: 12 additions & 3 deletions packages/core/src/components/VideoRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import React, { CSSProperties, useCallback, useEffect, useRef } from 'react';
export interface VideoRendererProps {
track: Track;
isLocal: boolean;
/**
* Mirror the video on the y axis.
* Is `true` by default for local, front-facing (and undetermined facing) media tracks,
* unless overriden by this setting */
isMirrored?: boolean;
objectFit?: Property.ObjectFit;
className?: string;
width?: Property.Width;
Expand All @@ -15,6 +20,7 @@ export interface VideoRendererProps {
export const VideoRenderer = ({
track,
isLocal,
isMirrored,
objectFit,
className,
onSizeChanged,
Expand Down Expand Up @@ -53,13 +59,16 @@ export const VideoRenderer = ({
};
}, [ref]);

const isFrontFacing =
isLocal && track.mediaStreamTrack?.getSettings().facingMode !== 'environment';
const style: CSSProperties = {
transform: isLocal && isFrontFacing ? 'rotateY(180deg)' : '',
width: width,
height: height,
};

const isFrontFacingOrUnknown = track.mediaStreamTrack?.getSettings().facingMode !== 'environment';
if (isMirrored || (isMirrored === undefined && isLocal && isFrontFacingOrUnknown)) {
style.transform = 'rotateY(180deg)';
}

if (objectFit) {
style.objectFit = objectFit;
}
Expand Down

0 comments on commit d94b678

Please sign in to comment.