@@ -40,10 +40,12 @@ import { PlayoutRundownModel } from './model/PlayoutRundownModel.js'
4040import { convertNoteToNotification } from '../notifications/util.js'
4141import { PersistentPlayoutStateStore } from '../blueprints/context/services/PersistantStateStore.js'
4242
43+ import { TakeNextPartResult } from '@sofie-automation/corelib/dist/worker/studio'
44+
4345/**
4446 * Take the currently Next:ed Part (start playing it)
4547 */
46- export async function handleTakeNextPart ( context : JobContext , data : TakeNextPartProps ) : Promise < void > {
48+ export async function handleTakeNextPart ( context : JobContext , data : TakeNextPartProps ) : Promise < TakeNextPartResult > {
4749 const now = getCurrentTime ( )
4850
4951 return runJobWithPlayoutModel (
@@ -77,17 +79,29 @@ export async function handleTakeNextPart(context: JobContext, data: TakeNextPart
7779 }
7880 }
7981 if ( lastTakeTime && now - lastTakeTime < context . studio . settings . minimumTakeSpan ) {
82+ const nextTakeTime = lastTakeTime + context . studio . settings . minimumTakeSpan
8083 logger . debug (
8184 `Time since last take is shorter than ${ context . studio . settings . minimumTakeSpan } for ${
8285 playlist . currentPartInfo ?. partInstanceId
8386 } : ${ now - lastTakeTime } `
8487 )
85- throw UserError . create ( UserErrorMessage . TakeRateLimit , {
86- duration : context . studio . settings . minimumTakeSpan ,
87- } )
88+ throw UserError . create (
89+ UserErrorMessage . TakeRateLimit ,
90+ {
91+ duration : context . studio . settings . minimumTakeSpan ,
92+ nextAllowedTakeTime : nextTakeTime ,
93+ } ,
94+ 429
95+ )
8896 }
8997
90- return performTakeToNextedPart ( context , playoutModel , now , undefined )
98+ const nextTakeTime = now + context . studio . settings . minimumTakeSpan
99+
100+ await performTakeToNextedPart ( context , playoutModel , now , undefined )
101+
102+ return {
103+ nextTakeTime,
104+ }
91105 }
92106 )
93107}
@@ -159,7 +173,14 @@ export async function performTakeToNextedPart(
159173 logger . debug (
160174 `Take is blocked until ${ currentPartInstance . partInstance . blockTakeUntil } . Which is in: ${ remainingTime } `
161175 )
162- throw UserError . create ( UserErrorMessage . TakeBlockedDuration , { duration : remainingTime } )
176+ throw UserError . create (
177+ UserErrorMessage . TakeBlockedDuration ,
178+ {
179+ duration : remainingTime ,
180+ nextAllowedTakeTime : currentPartInstance . partInstance . blockTakeUntil ,
181+ } ,
182+ 425
183+ )
163184 }
164185
165186 // If there was a transition from the previous Part, then ensure that has finished before another take is permitted
@@ -171,11 +192,17 @@ export async function performTakeToNextedPart(
171192 start &&
172193 now < start + currentPartInstance . partInstance . part . inTransition . blockTakeDuration
173194 ) {
174- throw UserError . create ( UserErrorMessage . TakeDuringTransition )
195+ throw UserError . create (
196+ UserErrorMessage . TakeDuringTransition ,
197+ {
198+ nextAllowedTakeTime : start + currentPartInstance . partInstance . part . inTransition . blockTakeDuration ,
199+ } ,
200+ 425
201+ )
175202 }
176203
177204 if ( currentPartInstance . isTooCloseToAutonext ( true ) ) {
178- throw UserError . create ( UserErrorMessage . TakeCloseToAutonext )
205+ throw UserError . create ( UserErrorMessage . TakeCloseToAutonext , undefined , 425 )
179206 }
180207 }
181208
0 commit comments