@@ -13,6 +13,7 @@ import {
1313 RundownPlaylistId ,
1414 SegmentId ,
1515} from '@sofie-automation/corelib/dist/dataModel/Ids'
16+ import { RundownTTimerIndex } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
1617import { Match , check } from '../../../lib/check'
1718import { PlaylistsRestAPI } from '../../../lib/rest/v1'
1819import { Meteor } from 'meteor/meteor'
@@ -544,6 +545,133 @@ class PlaylistsServerAPI implements PlaylistsRestAPI {
544545 }
545546 )
546547 }
548+
549+ async tTimerStartCountdown (
550+ connection : Meteor . Connection ,
551+ event : string ,
552+ rundownPlaylistId : RundownPlaylistId ,
553+ timerIndex : RundownTTimerIndex ,
554+ duration : number ,
555+ stopAtZero ?: boolean ,
556+ startPaused ?: boolean
557+ ) : Promise < ClientAPI . ClientResponse < void > > {
558+ return ServerClientAPI . runUserActionInLogForPlaylistOnWorker (
559+ this . context . getMethodContext ( connection ) ,
560+ event ,
561+ getCurrentTime ( ) ,
562+ rundownPlaylistId ,
563+ ( ) => {
564+ check ( rundownPlaylistId , String )
565+ check ( timerIndex , Number )
566+ check ( duration , Number )
567+ check ( stopAtZero , Match . Optional ( Boolean ) )
568+ check ( startPaused , Match . Optional ( Boolean ) )
569+ } ,
570+ StudioJobs . TTimerStartCountdown ,
571+ {
572+ playlistId : rundownPlaylistId ,
573+ timerIndex,
574+ duration,
575+ stopAtZero : ! ! stopAtZero ,
576+ startPaused : ! ! startPaused ,
577+ }
578+ )
579+ }
580+
581+ async tTimerStartFreeRun (
582+ connection : Meteor . Connection ,
583+ event : string ,
584+ rundownPlaylistId : RundownPlaylistId ,
585+ timerIndex : RundownTTimerIndex ,
586+ startPaused ?: boolean
587+ ) : Promise < ClientAPI . ClientResponse < void > > {
588+ return ServerClientAPI . runUserActionInLogForPlaylistOnWorker (
589+ this . context . getMethodContext ( connection ) ,
590+ event ,
591+ getCurrentTime ( ) ,
592+ rundownPlaylistId ,
593+ ( ) => {
594+ check ( rundownPlaylistId , String )
595+ check ( timerIndex , Number )
596+ check ( startPaused , Match . Optional ( Boolean ) )
597+ } ,
598+ StudioJobs . TTimerStartFreeRun ,
599+ {
600+ playlistId : rundownPlaylistId ,
601+ timerIndex,
602+ startPaused : ! ! startPaused ,
603+ }
604+ )
605+ }
606+
607+ async tTimerPause (
608+ connection : Meteor . Connection ,
609+ event : string ,
610+ rundownPlaylistId : RundownPlaylistId ,
611+ timerIndex : RundownTTimerIndex
612+ ) : Promise < ClientAPI . ClientResponse < void > > {
613+ return ServerClientAPI . runUserActionInLogForPlaylistOnWorker (
614+ this . context . getMethodContext ( connection ) ,
615+ event ,
616+ getCurrentTime ( ) ,
617+ rundownPlaylistId ,
618+ ( ) => {
619+ check ( rundownPlaylistId , String )
620+ check ( timerIndex , Number )
621+ } ,
622+ StudioJobs . TTimerPause ,
623+ {
624+ playlistId : rundownPlaylistId ,
625+ timerIndex,
626+ }
627+ )
628+ }
629+
630+ async tTimerResume (
631+ connection : Meteor . Connection ,
632+ event : string ,
633+ rundownPlaylistId : RundownPlaylistId ,
634+ timerIndex : RundownTTimerIndex
635+ ) : Promise < ClientAPI . ClientResponse < void > > {
636+ return ServerClientAPI . runUserActionInLogForPlaylistOnWorker (
637+ this . context . getMethodContext ( connection ) ,
638+ event ,
639+ getCurrentTime ( ) ,
640+ rundownPlaylistId ,
641+ ( ) => {
642+ check ( rundownPlaylistId , String )
643+ check ( timerIndex , Number )
644+ } ,
645+ StudioJobs . TTimerResume ,
646+ {
647+ playlistId : rundownPlaylistId ,
648+ timerIndex,
649+ }
650+ )
651+ }
652+
653+ async tTimerRestart (
654+ connection : Meteor . Connection ,
655+ event : string ,
656+ rundownPlaylistId : RundownPlaylistId ,
657+ timerIndex : RundownTTimerIndex
658+ ) : Promise < ClientAPI . ClientResponse < void > > {
659+ return ServerClientAPI . runUserActionInLogForPlaylistOnWorker (
660+ this . context . getMethodContext ( connection ) ,
661+ event ,
662+ getCurrentTime ( ) ,
663+ rundownPlaylistId ,
664+ ( ) => {
665+ check ( rundownPlaylistId , String )
666+ check ( timerIndex , Number )
667+ } ,
668+ StudioJobs . TTimerRestart ,
669+ {
670+ playlistId : rundownPlaylistId ,
671+ timerIndex,
672+ }
673+ )
674+ }
547675}
548676
549677class PlaylistsAPIFactory implements APIFactory < PlaylistsRestAPI > {
@@ -877,4 +1005,102 @@ export function registerRoutes(registerRoute: APIRegisterHook<PlaylistsRestAPI>)
8771005 return await serverAPI . recallStickyPiece ( connection , event , playlistId , sourceLayerId )
8781006 }
8791007 )
1008+
1009+ registerRoute <
1010+ { playlistId : string ; timerIndex : string } ,
1011+ { duration : number ; stopAtZero ?: boolean ; startPaused ?: boolean } ,
1012+ void
1013+ > (
1014+ 'post' ,
1015+ '/playlists/:playlistId/t-timers/:timerIndex/countdown' ,
1016+ new Map ( [ [ 404 , [ UserErrorMessage . RundownPlaylistNotFound ] ] ] ) ,
1017+ playlistsAPIFactory ,
1018+ async ( serverAPI , connection , event , params , body ) => {
1019+ const rundownPlaylistId = protectString < RundownPlaylistId > ( params . playlistId )
1020+ const timerIndex = Number . parseInt ( params . timerIndex ) as RundownTTimerIndex
1021+ logger . info ( `API POST: t-timer countdown ${ rundownPlaylistId } ${ timerIndex } ` )
1022+
1023+ check ( rundownPlaylistId , String )
1024+ check ( timerIndex , Number )
1025+ return await serverAPI . tTimerStartCountdown (
1026+ connection ,
1027+ event ,
1028+ rundownPlaylistId ,
1029+ timerIndex ,
1030+ body . duration ,
1031+ body . stopAtZero ,
1032+ body . startPaused
1033+ )
1034+ }
1035+ )
1036+
1037+ registerRoute < { playlistId : string ; timerIndex : string } , { startPaused ?: boolean } , void > (
1038+ 'post' ,
1039+ '/playlists/:playlistId/t-timers/:timerIndex/free-run' ,
1040+ new Map ( [ [ 404 , [ UserErrorMessage . RundownPlaylistNotFound ] ] ] ) ,
1041+ playlistsAPIFactory ,
1042+ async ( serverAPI , connection , event , params , body ) => {
1043+ const rundownPlaylistId = protectString < RundownPlaylistId > ( params . playlistId )
1044+ const timerIndex = Number . parseInt ( params . timerIndex ) as RundownTTimerIndex
1045+ logger . info ( `API POST: t-timer free-run ${ rundownPlaylistId } ${ timerIndex } ` )
1046+
1047+ check ( rundownPlaylistId , String )
1048+ check ( timerIndex , Number )
1049+ return await serverAPI . tTimerStartFreeRun (
1050+ connection ,
1051+ event ,
1052+ rundownPlaylistId ,
1053+ timerIndex ,
1054+ body . startPaused
1055+ )
1056+ }
1057+ )
1058+
1059+ registerRoute < { playlistId : string ; timerIndex : string } , never , void > (
1060+ 'post' ,
1061+ '/playlists/:playlistId/t-timers/:timerIndex/pause' ,
1062+ new Map ( [ [ 404 , [ UserErrorMessage . RundownPlaylistNotFound ] ] ] ) ,
1063+ playlistsAPIFactory ,
1064+ async ( serverAPI , connection , event , params , _ ) => {
1065+ const rundownPlaylistId = protectString < RundownPlaylistId > ( params . playlistId )
1066+ const timerIndex = Number . parseInt ( params . timerIndex ) as RundownTTimerIndex
1067+ logger . info ( `API POST: t-timer pause ${ rundownPlaylistId } ${ timerIndex } ` )
1068+
1069+ check ( rundownPlaylistId , String )
1070+ check ( timerIndex , Number )
1071+ return await serverAPI . tTimerPause ( connection , event , rundownPlaylistId , timerIndex )
1072+ }
1073+ )
1074+
1075+ registerRoute < { playlistId : string ; timerIndex : string } , never , void > (
1076+ 'post' ,
1077+ '/playlists/:playlistId/t-timers/:timerIndex/resume' ,
1078+ new Map ( [ [ 404 , [ UserErrorMessage . RundownPlaylistNotFound ] ] ] ) ,
1079+ playlistsAPIFactory ,
1080+ async ( serverAPI , connection , event , params , _ ) => {
1081+ const rundownPlaylistId = protectString < RundownPlaylistId > ( params . playlistId )
1082+ const timerIndex = Number . parseInt ( params . timerIndex ) as RundownTTimerIndex
1083+ logger . info ( `API POST: t-timer resume ${ rundownPlaylistId } ${ timerIndex } ` )
1084+
1085+ check ( rundownPlaylistId , String )
1086+ check ( timerIndex , Number )
1087+ return await serverAPI . tTimerResume ( connection , event , rundownPlaylistId , timerIndex )
1088+ }
1089+ )
1090+
1091+ registerRoute < { playlistId : string ; timerIndex : string } , never , void > (
1092+ 'post' ,
1093+ '/playlists/:playlistId/t-timers/:timerIndex/restart' ,
1094+ new Map ( [ [ 404 , [ UserErrorMessage . RundownPlaylistNotFound ] ] ] ) ,
1095+ playlistsAPIFactory ,
1096+ async ( serverAPI , connection , event , params , _ ) => {
1097+ const rundownPlaylistId = protectString < RundownPlaylistId > ( params . playlistId )
1098+ const timerIndex = Number . parseInt ( params . timerIndex ) as RundownTTimerIndex
1099+ logger . info ( `API POST: t-timer restart ${ rundownPlaylistId } ${ timerIndex } ` )
1100+
1101+ check ( rundownPlaylistId , String )
1102+ check ( timerIndex , Number )
1103+ return await serverAPI . tTimerRestart ( connection , event , rundownPlaylistId , timerIndex )
1104+ }
1105+ )
8801106}
0 commit comments