Skip to content
This repository was archived by the owner on Aug 24, 2023. It is now read-only.
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
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