Skip to content

Commit e2236b5

Browse files
authored
Merge pull request #2 from beef331/pip
Add setting to control picture in picture setting for videos
2 parents ecef381 + ab42e6f commit e2236b5

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/room/VideoPreview.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import { facingModeFromLocalTrack, type LocalVideoTrack } from "livekit-client";
1111
import classNames from "classnames";
1212
import { useTranslation } from "react-i18next";
1313

14+
import {
15+
allowPipSetting,
16+
useSetting,
17+
} from "../settings/settings";
18+
1419
import { TileAvatar } from "../tile/TileAvatar";
1520
import styles from "./VideoPreview.module.css";
1621
import { type EncryptionSystem } from "../e2ee/sharedKeyManagement";
@@ -44,6 +49,8 @@ export const VideoPreview: FC<Props> = ({
4449

4550
const videoEl = useRef<HTMLVideoElement | null>(null);
4651

52+
const [allowPip] = useSetting(allowPipSetting);
53+
4754
useEffect(() => {
4855
// Effect to connect the videoTrack with the video element.
4956
if (videoEl.current) {
@@ -73,7 +80,7 @@ export const VideoPreview: FC<Props> = ({
7380
playsInline
7481
// There's no reason for this to be focusable
7582
tabIndex={-1}
76-
disablePictureInPicture
83+
disablePictureInPicture={allowPip}
7784
/>
7885
{(!videoEnabled || cameraIsStarting) && (
7986
<>

src/settings/SettingsModal.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
soundEffectVolume as soundEffectVolumeSetting,
2626
backgroundBlur as backgroundBlurSetting,
2727
developerMode,
28+
allowPipSetting,
2829
advancedScreenShare as advancedScreenShareSetting,
2930
screenShareResolution as screenShareResolutionSetting,
3031
screenShareFramerate as screenShareFramerateSetting,
@@ -298,6 +299,28 @@ export const SettingsModal: FC<Props> = ({
298299
);
299300
};
300301

302+
const PipSetting: React.FC = (): ReactNode => {
303+
const [allowPip, setAllowPip] = useSetting(allowPipSetting);
304+
305+
return (
306+
<>
307+
<FieldRow>
308+
<InputField
309+
id="allowPip"
310+
label={t(
311+
"settings.allow_pip_label",
312+
"Allow Browser Picture In Picture",
313+
)}
314+
type="checkbox"
315+
checked={allowPip}
316+
onChange={(e): void => setAllowPip(e.target.checked)}
317+
/>
318+
</FieldRow>
319+
</>
320+
);
321+
};
322+
323+
301324
const devices = useMediaDevices();
302325
useEffect(() => {
303326
if (open) devices.requestDeviceNames();
@@ -382,6 +405,7 @@ export const SettingsModal: FC<Props> = ({
382405
name: t("common.video"),
383406
content: (
384407
<>
408+
<PipSetting />
385409
<Form>
386410
<DeviceSelection
387411
device={devices.videoInput}

src/settings/settings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ export const autoGainControlSetting = new Setting<boolean>(
227227
true,
228228
);
229229

230+
export const allowPipSetting = new Setting<boolean>(
231+
"allow-pip",
232+
false
233+
);
234+
230235
/**
231236
* Seed setting defaults from config.json's media_quality section.
232237
* Call this after Config.init() has resolved.

src/tile/MediaView.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { RaisedHandIndicator } from "../reactions/RaisedHandIndicator";
2121
import {
2222
showConnectionStats,
2323
showHandRaisedTimer,
24+
allowPipSetting,
2425
useSetting,
2526
} from "../settings/settings";
2627
import { type ReactionOption } from "../reactions";
@@ -86,6 +87,7 @@ export const MediaView: FC<Props> = ({
8687
const { t } = useTranslation();
8788
const [handRaiseTimerVisible] = useSetting(showHandRaisedTimer);
8889
const [showConnectioStats] = useSetting(showConnectionStats);
90+
const [allowPip] = useSetting(allowPipSetting);
8991

9092
const avatarSize = Math.round(Math.min(targetWidth, targetHeight) / 2);
9193

@@ -114,7 +116,7 @@ export const MediaView: FC<Props> = ({
114116
trackRef={video}
115117
// There's no reason for this to be focusable
116118
tabIndex={-1}
117-
disablePictureInPicture
119+
disablePictureInPicture={!allowPip}
118120
style={{ display: video && videoEnabled ? "block" : "none" }}
119121
data-testid="video"
120122
/>

0 commit comments

Comments
 (0)