Make background blurring actually react to track restarts
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
|||||||
ConnectionState,
|
ConnectionState,
|
||||||
type E2EEManagerOptions,
|
type E2EEManagerOptions,
|
||||||
ExternalE2EEKeyProvider,
|
ExternalE2EEKeyProvider,
|
||||||
type LocalVideoTrack,
|
LocalVideoTrack,
|
||||||
Room,
|
Room,
|
||||||
type RoomOptions,
|
type RoomOptions,
|
||||||
Track,
|
Track,
|
||||||
@@ -18,6 +18,8 @@ import { useEffect, useMemo, useRef } from "react";
|
|||||||
import E2EEWorker from "livekit-client/e2ee-worker?worker";
|
import E2EEWorker from "livekit-client/e2ee-worker?worker";
|
||||||
import { logger } from "matrix-js-sdk/lib/logger";
|
import { logger } from "matrix-js-sdk/lib/logger";
|
||||||
import { type MatrixRTCSession } from "matrix-js-sdk/lib/matrixrtc";
|
import { type MatrixRTCSession } from "matrix-js-sdk/lib/matrixrtc";
|
||||||
|
import { useObservable, useObservableEagerState } from "observable-hooks";
|
||||||
|
import { map } from "rxjs";
|
||||||
|
|
||||||
import { defaultLiveKitOptions } from "./options";
|
import { defaultLiveKitOptions } from "./options";
|
||||||
import { type SFUConfig } from "./openIDSFU";
|
import { type SFUConfig } from "./openIDSFU";
|
||||||
@@ -39,6 +41,7 @@ import {
|
|||||||
useTrackProcessorSync,
|
useTrackProcessorSync,
|
||||||
} from "./TrackProcessorContext";
|
} from "./TrackProcessorContext";
|
||||||
import { useInitial } from "../useInitial";
|
import { useInitial } from "../useInitial";
|
||||||
|
import { observeTrackReference$ } from "../state/MediaViewModel";
|
||||||
|
|
||||||
interface UseLivekitResult {
|
interface UseLivekitResult {
|
||||||
livekitRoom?: Room;
|
livekitRoom?: Room;
|
||||||
@@ -132,21 +135,25 @@ export function useLiveKit(
|
|||||||
return r;
|
return r;
|
||||||
}, [roomOptions, e2eeSystem]);
|
}, [roomOptions, e2eeSystem]);
|
||||||
|
|
||||||
const videoTrack = useMemo(
|
// Sync the requested track processors with LiveKit
|
||||||
() =>
|
useTrackProcessorSync(
|
||||||
Array.from(room.localParticipant.videoTrackPublications.values()).find(
|
useObservableEagerState(
|
||||||
(v) => v.source === Track.Source.Camera,
|
useObservable(
|
||||||
)?.track as LocalVideoTrack | null,
|
(room$) =>
|
||||||
[
|
observeTrackReference$(
|
||||||
room.localParticipant.videoTrackPublications,
|
room$.pipe(map(([room]) => room.localParticipant)),
|
||||||
// We need to update on map changes
|
Track.Source.Camera,
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
).pipe(
|
||||||
room.localParticipant.videoTrackPublications.keys(),
|
map((trackRef) => {
|
||||||
],
|
const track = trackRef?.publication?.track;
|
||||||
|
return track instanceof LocalVideoTrack ? track : null;
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
[room],
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
useTrackProcessorSync(videoTrack);
|
|
||||||
|
|
||||||
const connectionState = useECConnectionState(
|
const connectionState = useECConnectionState(
|
||||||
{
|
{
|
||||||
deviceId: initialDevices.current.audioInput.selectedId,
|
deviceId: initialDevices.current.audioInput.selectedId,
|
||||||
|
|||||||
Reference in New Issue
Block a user