feat: Make cameras optional (#2343)

This commit is contained in:
Dermot Duffy
2026-02-13 20:21:05 -08:00
committed by GitHub
parent 21f9469784
commit 93f1f08e51
61 changed files with 1312 additions and 557 deletions
+22 -6
View File
@@ -1,18 +1,31 @@
import { View } from '../view/view';
export const getStreamCameraID = (view: View, cameraID?: string): string => {
return (
view.context?.live?.overrides?.get(cameraID ?? view.camera) ??
cameraID ??
view.camera
);
/**
* Get the effective camera ID for streaming, considering substream overrides.
* Returns null if the view has no camera.
*/
export const getStreamCameraID = (
view: View,
cameraID?: string | null,
): string | null => {
const baseCameraID = cameraID ?? view.camera;
if (!baseCameraID) {
return null;
}
return view.context?.live?.overrides?.get(baseCameraID) ?? baseCameraID;
};
export const hasSubstream = (view: View): boolean => {
if (!view.camera) {
return false;
}
return getStreamCameraID(view) !== view.camera;
};
export const setSubstream = (view: View, substreamID: string): void => {
if (!view.camera) {
return;
}
const overrides: Map<string, string> = view.context?.live?.overrides ?? new Map();
overrides.set(view.camera, substreamID);
view.mergeInContext({
@@ -21,6 +34,9 @@ export const setSubstream = (view: View, substreamID: string): void => {
};
export const removeSubstream = (view: View): void => {
if (!view.camera) {
return;
}
const overrides: Map<string, string> | undefined = view.context?.live?.overrides;
if (overrides && overrides.has(view.camera)) {
view.context?.live?.overrides?.delete(view.camera);