Skip to content

Commit

Permalink
fix: changed find to filter and maped through the results
Browse files Browse the repository at this point in the history
  • Loading branch information
malmen237 committed Sep 3, 2024
1 parent 9ffa7cd commit 0761a96
Showing 1 changed file with 49 additions and 48 deletions.
97 changes: 49 additions & 48 deletions src/api/agileLive/pipelines/streams/streams.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useCallback } from 'react';
import { ResourcesUUIDResponse } from '../../../../../types/agile-live';
import { AGILE_BASE_API_PATH } from '../../../../constants';
import {
Expand Down Expand Up @@ -47,6 +48,7 @@ export async function getPipelineStreams(
}
throw await response.json();
}

export async function createStream(
source: SourceWithId,
production: Production,
Expand Down Expand Up @@ -198,20 +200,15 @@ export async function createStream(
);
throw `Missing pipeline_id for: ${production.production_settings.pipelines[0].pipeline_name}`;
}
const multiviews = await getMultiviewsForPipeline(
const multiviewsResponse = await getMultiviewsForPipeline(
production.production_settings.pipelines[0].pipeline_id
);
// ! What is the consequence of this? Cannot see the effect ->
// const multiview = multiviews.find(
// (multiview) =>
// multiview.id ===
// production.production_settings.pipelines[0].multiview?.multiview_id
// );

// filter instead of find
const multiview = multiviews.find((multiview) => {
const multiviews = multiviewsResponse.filter((multiview) => {
const pipeline = production.production_settings.pipelines[0];
const multiviewArray = pipeline.multiview;
console.log('test multiview', multiview);
console.log('test multiviewArray', multiviewArray);

if (Array.isArray(multiviewArray)) {
return multiviewArray.some(
Expand All @@ -225,53 +222,57 @@ export async function createStream(

return false;
});
// ! <-

if (!multiview) {
if (multiviews.length === 0) {
Log().error(
`No multiview found for pipeline: ${production.production_settings.pipelines[0].pipeline_id}`
);
throw `No multiview found for pipeline: ${production.production_settings.pipelines[0].pipeline_id}`;
}
const views = multiview.layout.views;
const viewsForSource = views.filter(
(view) => view.input_slot === input_slot
);
if (!viewsForSource || viewsForSource.length === 0) {
Log().info(
`No view found for input slot: ${input_slot}. Will not connect source to view`
multiviews.map(async (multiview) => {
const views = multiview.layout.views;
const viewsForSource = views.filter(
(view) => view.input_slot === input_slot
);
if (!viewsForSource || viewsForSource.length === 0) {
Log().info(
`No view found for input slot: ${input_slot}. Will not connect source to view`
);
return {
ok: true,
value: {
success: true,
steps: [
{
step: 'add_stream',
success: true
},
{
step: 'update_multiview',
success: true
}
],
streams: sourceToPipelineStreams
}
};
// TODO Check if this can be cleaned out. This is an old code and dont know the purpose of it, therefor I dont want to remove it yet.
// return sourceToPipelineStreams;
}
const updatedViewsForSource = viewsForSource.map((v) => {
return { ...v, label: source.name };
});

const updatedViews = [
...views.filter((view) => view.input_slot !== input_slot),
...updatedViewsForSource
];

await updateMultiviewForPipeline(
production.production_settings.pipelines[0].pipeline_id!,
multiview.id,
updatedViews
);
return {
ok: true,
value: {
success: true,
steps: [
{
step: 'add_stream',
success: true
},
{
step: 'update_multiview',
success: true
}
],
streams: sourceToPipelineStreams
}
};
// return sourceToPipelineStreams;
}
const updatedViewsForSource = viewsForSource.map((v) => {
return { ...v, label: source.name };
});
const updatedViews = [
...views.filter((view) => view.input_slot !== input_slot),
...updatedViewsForSource
];
await updateMultiviewForPipeline(
production.production_settings.pipelines[0].pipeline_id!,
multiview.id,
updatedViews
);
} catch (e) {
Log().error('Could not update multiview after adding stream');
Log().error(e);
Expand Down

0 comments on commit 0761a96

Please sign in to comment.