Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove sources from pipelines + syncInventory #80

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 37 additions & 5 deletions src/api/manager/job/syncInventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,34 @@ export async function runSyncInventory() {
}
};

const updateSrtMetadata = (
inventorySource: WithId<Source>,
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) => {
Expand All @@ -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<Source>;
});

Expand Down
47 changes: 40 additions & 7 deletions src/components/production/sources/ProductionSources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down Expand Up @@ -154,11 +153,26 @@ const ProductionSources: React.FC<ProductionSourcesProps> = (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) => {
Expand Down Expand Up @@ -336,7 +350,7 @@ const ProductionSources: React.FC<ProductionSourcesProps> = (props) => {
}
};

const handleRemoveSource = async () => {
const handleRemoveSource = async (ingestSource?: SourceWithId) => {
if (isProductionActive && selectedSourceRef) {
if (!multiviews || multiviews.length === 0) return;

Expand Down Expand Up @@ -440,9 +454,18 @@ const ProductionSources: React.FC<ProductionSourcesProps> = (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);
}
};

Expand Down Expand Up @@ -576,12 +599,22 @@ const ProductionSources: React.FC<ProductionSourcesProps> = (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);
}
Expand All @@ -593,7 +626,7 @@ const ProductionSources: React.FC<ProductionSourcesProps> = (props) => {
name={selectedSourceRef.label}
open={removeSourceModal}
onAbort={handleAbortRemoveSource}
onConfirm={handleRemoveSource}
onConfirm={() => handleRemoveSource(selectedSource)}
status={deleteSourceStatus}
loading={
loadingDeleteStream ||
Expand Down
Loading