From 700aa8663b15a76aba7ff64ad7ac804efa251525 Mon Sep 17 00:00:00 2001 From: Sandra Larsson Date: Thu, 7 Nov 2024 10:51:29 +0100 Subject: [PATCH] fix: remove sources from pipelines + syncInventory (#80) --- src/api/manager/job/syncInventory.ts | 42 +++++++++++++++-- .../production/sources/ProductionSources.tsx | 47 ++++++++++++++++--- 2 files changed, 77 insertions(+), 12 deletions(-) diff --git a/src/api/manager/job/syncInventory.ts b/src/api/manager/job/syncInventory.ts index f92186bd..757120b0 100644 --- a/src/api/manager/job/syncInventory.ts +++ b/src/api/manager/job/syncInventory.ts @@ -81,6 +81,34 @@ export async function runSyncInventory() { } }; + const updateSrtMetadata = ( + inventorySource: WithId, + apiSource: SourceWithoutLastConnected + ) => { + if ( + apiSource.status === 'new' && + apiSource.ingest_type === 'SRT' && + apiSource.srt && + apiSource.srt.video_format && + inventorySource.srt + ) { + const updatedSrt = { + ...inventorySource.srt, + video_format: apiSource.srt.video_format + }; + + return updatedSrt; + } else if ( + apiSource.ingest_type === 'SRT' && + !inventorySource.srt && + apiSource.srt + ) { + return apiSource.srt; + } else { + return inventorySource.srt; + } + }; + // Update status of all sources in the inventory to the status found in API. // If a source is not found in the API, it is marked as gone. const dbInventoryWithCorrectStatus = dbInventory.map((inventorySource) => { @@ -105,12 +133,16 @@ export async function runSyncInventory() { ...inventorySource, status: statusUpdateCheck(inventorySource, apiSource, lastConnected), lastConnected: lastConnected, + video_stream: + apiSource.ingest_type === 'SRT' && apiSource.status === 'gone' + ? inventorySource.video_stream + : apiSource.video_stream, + audio_stream: + apiSource.ingest_type === 'SRT' && apiSource.status === 'gone' + ? inventorySource.audio_stream + : apiSource.audio_stream, // Add srt metadata if missing from SRT sources - srt: - (apiSource.ingest_type === 'SRT' && - !inventorySource.srt && - apiSource.srt) || - inventorySource.srt + srt: updateSrtMetadata(inventorySource, apiSource) } satisfies WithId; }); diff --git a/src/components/production/sources/ProductionSources.tsx b/src/components/production/sources/ProductionSources.tsx index 887aab0e..20117167 100644 --- a/src/components/production/sources/ProductionSources.tsx +++ b/src/components/production/sources/ProductionSources.tsx @@ -43,7 +43,6 @@ import { PipelineSettings } from '../../../interfaces/pipeline'; import { useGetFirstEmptySlot } from '../../../hooks/useGetFirstEmptySlot'; import useEffectNotOnMount from '../../../hooks/utils/useEffectNotOnMount'; import { LoadingCover } from '../../loader/LoadingCover'; -import { Production } from '../../../interfaces/production'; interface ProductionSourcesProps { sources: SourceReference[]; @@ -154,11 +153,26 @@ const ProductionSources: React.FC = (props) => { setSelectedSource(undefined); }; - const removeSource = (source: SourceReference) => { + const removeSource = (source: SourceReference, ingestSourceId?: number) => { const tempItems = selectedSources.filter( (tempItem) => tempItem._id !== source._id ); + + let updatedPipelines = pipelines; + + if (ingestSourceId !== undefined) { + updatedPipelines = pipelines.map((pipeline) => ({ + ...pipeline, + sources: pipeline.sources + ? pipeline.sources.filter( + (pipelineSource) => pipelineSource.source_id !== ingestSourceId + ) + : [] + })); + } + setSelectedSources(tempItems); + updatePipelines(updatedPipelines); }; const updatePipelinesWithSource = async (source: SourceWithId) => { @@ -336,7 +350,7 @@ const ProductionSources: React.FC = (props) => { } }; - const handleRemoveSource = async () => { + const handleRemoveSource = async (ingestSource?: SourceWithId) => { if (isProductionActive && selectedSourceRef) { if (!multiviews || multiviews.length === 0) return; @@ -440,9 +454,18 @@ const ProductionSources: React.FC = (props) => { } } - removeSource(selectedSourceRef); + const ingestSourceId = + ingestSource !== undefined + ? await getIngestSourceId( + ingestSource.ingest_name, + ingestSource.ingest_source_name + ) + : undefined; + + removeSource(selectedSourceRef, ingestSourceId); setRemoveSourceModal(false); setSelectedSourceRef(undefined); + setSelectedSource(undefined); } }; @@ -576,12 +599,22 @@ const ProductionSources: React.FC = (props) => { onSourceUpdate={(source: SourceReference) => { updateSource(source); }} - onSourceRemoval={(source: SourceReference) => { + onSourceRemoval={async ( + source: SourceReference, + ingestSource?: ISource + ) => { if (isProductionActive) { + setSelectedSource(ingestSource); setSelectedSourceRef(source); setRemoveSourceModal(true); } else { - removeSource(source); + const ingestSourceId = ingestSource + ? await getIngestSourceId( + ingestSource.ingest_name, + ingestSource.ingest_source_name + ) + : undefined; + removeSource(source, ingestSourceId); setRemoveSourceModal(false); setSelectedSourceRef(undefined); } @@ -593,7 +626,7 @@ const ProductionSources: React.FC = (props) => { name={selectedSourceRef.label} open={removeSourceModal} onAbort={handleAbortRemoveSource} - onConfirm={handleRemoveSource} + onConfirm={() => handleRemoveSource(selectedSource)} status={deleteSourceStatus} loading={ loadingDeleteStream ||