Fix a resource leak in the track processor code
This commit is contained in:
@@ -28,6 +28,7 @@ import {
|
|||||||
} from "../settings/settings";
|
} from "../settings/settings";
|
||||||
import { BlurBackgroundTransformer } from "./BlurBackgroundTransformer";
|
import { BlurBackgroundTransformer } from "./BlurBackgroundTransformer";
|
||||||
import { type Behavior } from "../state/Behavior";
|
import { type Behavior } from "../state/Behavior";
|
||||||
|
import { type ObservableScope } from "../state/ObservableScope";
|
||||||
|
|
||||||
//TODO-MULTI-SFU: This is not yet fully there.
|
//TODO-MULTI-SFU: This is not yet fully there.
|
||||||
// it is a combination of exposing observable and react hooks.
|
// it is a combination of exposing observable and react hooks.
|
||||||
@@ -63,13 +64,17 @@ export function useTrackProcessorObservable$(): Observable<ProcessorState> {
|
|||||||
return state$;
|
return state$;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates your video tracks to always use the given processor.
|
||||||
|
*/
|
||||||
export const trackProcessorSync = (
|
export const trackProcessorSync = (
|
||||||
|
scope: ObservableScope,
|
||||||
videoTrack$: Behavior<LocalVideoTrack | null>,
|
videoTrack$: Behavior<LocalVideoTrack | null>,
|
||||||
processor$: Behavior<ProcessorState>,
|
processor$: Behavior<ProcessorState>,
|
||||||
): void => {
|
): void => {
|
||||||
// TODO-MULTI-SFU: Bind to an ObservableScope to avoid leaking resources.
|
combineLatest([videoTrack$, processor$])
|
||||||
combineLatest([videoTrack$, processor$]).subscribe(
|
.pipe(scope.bind())
|
||||||
([videoTrack, processorState]) => {
|
.subscribe(([videoTrack, processorState]) => {
|
||||||
if (!processorState) return;
|
if (!processorState) return;
|
||||||
if (!videoTrack) return;
|
if (!videoTrack) return;
|
||||||
const { processor } = processorState;
|
const { processor } = processorState;
|
||||||
@@ -79,8 +84,7 @@ export const trackProcessorSync = (
|
|||||||
if (!processor && videoTrack.getProcessor()) {
|
if (!processor && videoTrack.getProcessor()) {
|
||||||
void videoTrack.stopProcessor();
|
void videoTrack.stopProcessor();
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useTrackProcessorSync = (
|
export const useTrackProcessorSync = (
|
||||||
|
|||||||
@@ -320,6 +320,6 @@ export class Publisher {
|
|||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
);
|
);
|
||||||
trackProcessorSync(track$, trackerProcessorState$);
|
trackProcessorSync(scope, track$, trackerProcessorState$);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user