Skip to content

Commit bd8dfc1

Browse files
authored
Merge pull request #2 from beef331/pip-sable
Allow user to control whether Picture In Picture is enabled or disabled
2 parents 9e76c62 + 49691e0 commit bd8dfc1

4 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/room/VideoPreview.tsx

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

14+
import { allowPipSetting, useSetting, } from "../settings/settings";
15+
1416
import { TileAvatar } from "../tile/TileAvatar";
1517
import styles from "./VideoPreview.module.css";
1618
import { type EncryptionSystem } from "../e2ee/sharedKeyManagement";
@@ -58,6 +60,7 @@ export const VideoPreview: FC<Props> = ({
5860
() => videoEnabled && !videoTrack,
5961
[videoEnabled, videoTrack],
6062
);
63+
const [allowPip] = useSetting(allowPipSetting);
6164

6265
return (
6366
<div className={classNames(styles.preview)} ref={previewRef}>
@@ -73,7 +76,7 @@ export const VideoPreview: FC<Props> = ({
7376
playsInline
7477
// There's no reason for this to be focusable
7578
tabIndex={-1}
76-
disablePictureInPicture
79+
disablePictureInPicture={!allowPip}
7780
/>
7881
{(!videoEnabled || cameraIsStarting) && (
7982
<>

src/settings/SettingsModal.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
soundEffectVolume as soundEffectVolumeSetting,
2525
backgroundBlur as backgroundBlurSetting,
2626
developerMode,
27+
allowPipSetting,
2728
} from "./settings";
2829
import { PreferencesSettingsTab } from "./PreferencesSettingsTab";
2930
import { Slider } from "../Slider";
@@ -169,11 +170,33 @@ export const SettingsModal: FC<Props> = ({
169170
),
170171
};
171172

173+
const PipSetting: React.FC = (): ReactNode => {
174+
const [allowPip, setAllowPip] = useSetting(allowPipSetting);
175+
176+
return (
177+
<>
178+
<FieldRow>
179+
<InputField
180+
id="allowPip"
181+
label={t(
182+
"settings.allow_pip_label",
183+
"Allow Browser Picture In Picture",
184+
)}
185+
type="checkbox"
186+
checked={allowPip}
187+
onChange={(e): void => setAllowPip(e.target.checked)}
188+
/>
189+
</FieldRow>
190+
</>
191+
);
192+
};
193+
172194
const videoTab: Tab<SettingsTab> = {
173195
key: "video",
174196
name: t("common.video"),
175197
content: (
176198
<>
199+
<PipSetting />
177200
<Form>
178201
<DeviceSelection
179202
device={devices.videoInput}

src/settings/settings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,8 @@ export const customLivekitUrl = new Setting<string | null>(
145145
"custom-livekit-url",
146146
null,
147147
);
148+
149+
export const allowPipSetting = new Setting<boolean>(
150+
"allow-pip",
151+
false
152+
);

src/tile/MediaView.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { RaisedHandIndicator } from "../reactions/RaisedHandIndicator";
2121
import {
2222
showConnectionStats as showConnectionStatsSetting,
2323
showHandRaisedTimer,
24+
allowPipSetting,
2425
useSetting,
2526
} from "../settings/settings";
2627
import { type ReactionOption } from "../reactions";
@@ -86,7 +87,7 @@ export const MediaView: FC<Props> = ({
8687
const { t } = useTranslation();
8788
const [handRaiseTimerVisible] = useSetting(showHandRaisedTimer);
8889
const [showConnectionStats] = useSetting(showConnectionStatsSetting);
89-
90+
const [allowPip] = useSetting(allowPipSetting);
9091
const avatarSize = Math.round(Math.min(targetWidth, targetHeight) / 2);
9192

9293
return (
@@ -114,7 +115,7 @@ export const MediaView: FC<Props> = ({
114115
trackRef={video}
115116
// There's no reason for this to be focusable
116117
tabIndex={-1}
117-
disablePictureInPicture
118+
disablePictureInPicture={!allowPip}
118119
style={{ display: video && videoEnabled ? "block" : "none" }}
119120
data-testid="video"
120121
/>

0 commit comments

Comments
 (0)