Skip to content

Commit

Permalink
make compatible with unsopported browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
toger5 committed Nov 27, 2024
1 parent 52b0b84 commit ed96588
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
18 changes: 14 additions & 4 deletions src/livekit/useLiveKit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,24 @@ export function useLiveKit(
const initialMuteStates = useRef<MuteStates>(muteStates);
const devices = useMediaDevices();
const initialDevices = useRef<MediaDevices>(devices);
// eslint-disable-next-line new-cap
const blur = useMemo(() => BackgroundBlur(15), []);
const blur = useMemo(() => {
let b = undefined;
try {
// eslint-disable-next-line new-cap
b = BackgroundBlur(15);
} catch (e) {
logger.error("disable background blur", e);
}
return b;
}, []);
const roomOptions = useMemo(
(): RoomOptions => ({
...defaultLiveKitOptions,
videoCaptureDefaults: {
...defaultLiveKitOptions.videoCaptureDefaults,
deviceId: initialDevices.current.videoInput.selectedId,
// eslint-disable-next-line new-cap
processor: BackgroundBlur(15),
processor: blur,
},
audioCaptureDefaults: {
...defaultLiveKitOptions.audioCaptureDefaults,
Expand All @@ -103,7 +111,7 @@ export function useLiveKit(
},
e2ee: e2eeOptions,
}),
[e2eeOptions],
[blur, e2eeOptions],
);

// Store if audio/video are currently updating. If to prohibit unnecessary calls
Expand Down Expand Up @@ -143,6 +151,8 @@ export function useLiveKit(
>(undefined);

useEffect(() => {
// Fon't even try if we cannot blur on this platform
if (!blur) return;
if (!room || videoTrackPromise.current) return;
const update = async (): Promise<void> => {
let publishCallback: undefined | ((track: LocalTrackPublication) => void);
Expand Down
13 changes: 12 additions & 1 deletion src/room/LobbyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,16 @@ export const LobbyView: FC<Props> = ({
);

// eslint-disable-next-line new-cap
const blur = useMemo(() => BackgroundBlur(15), []);
const blur = useMemo(() => {
let b = undefined;
try {
// eslint-disable-next-line new-cap
b = BackgroundBlur(15);
} catch (e) {
logger.error("disable background blur", e);
}
return b;
}, []);

const localTrackOptions = useMemo(
() => ({
Expand Down Expand Up @@ -158,6 +167,8 @@ export const LobbyView: FC<Props> = ({
const [showBackgroundBlur] = useSetting(backgroundBlurSettings);

useEffect(() => {
// Fon't even try if we cannot blur on this platform
if (!blur) return;
const updateBlur = async (showBlur: boolean): Promise<void> => {
if (showBlur && !videoTrack?.getProcessor()) {
// eslint-disable-next-line new-cap
Expand Down
17 changes: 15 additions & 2 deletions src/settings/SettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
Text,
Tooltip,
} from "@vector-im/compound-web";
import { BackgroundBlur } from "@livekit/track-processors";
import { logger } from "matrix-js-sdk/src/logger";

import { Modal } from "../Modal";
import styles from "./SettingsModal.module.css";
Expand Down Expand Up @@ -79,7 +81,18 @@ export const SettingsModal: FC<Props> = ({
// Generate a `Checkbox` input to turn blur on or off.
const BlurCheckbox: React.FC = (): ReactNode => {
const [blur, setBlur] = useSetting(backgroundBlurSetting);
return (
let canBlur = true;
try {
// eslint-disable-next-line new-cap
BackgroundBlur(15);
} catch (e) {
logger.debug(
"Cannot blur, so we do not show the option in settings. error: ",
e,
);
canBlur = false;
}
return canBlur ? (
<>
<h4>{t("settings.background_blur_header")}</h4>
<FieldRow>
Expand All @@ -100,7 +113,7 @@ export const SettingsModal: FC<Props> = ({
</Tooltip>
</FieldRow>
</>
);
) : null;
};

const optInDescription = (
Expand Down

0 comments on commit ed96588

Please sign in to comment.