@@ -34,6 +34,12 @@ import { getCurrentTime } from '../../../lib/lib'
3434import { TriggerReloadDataResponse } from '@sofie-automation/meteor-lib/dist/api/userActions'
3535import { ServerRundownAPI } from '../../rundown'
3636import { triggerWriteAccess } from '../../../security/securityVerify'
37+ import {
38+ ActivePlaylistEvent ,
39+ ActivePlaylistTiming ,
40+ ActivePlaylistTimingMode ,
41+ } from '@sofie-automation/live-status-gateway-api'
42+ import { PlaylistTimingType , RundownPlaylistTiming } from '@sofie-automation/blueprints-integration'
3743
3844class PlaylistsServerAPI implements PlaylistsRestAPI {
3945 constructor ( private context : ServerAPIContext ) { }
@@ -50,6 +56,75 @@ class PlaylistsServerAPI implements PlaylistsRestAPI {
5056 )
5157 }
5258
59+ async getActiveRundownPlaylist (
60+ _connection : Meteor . Connection ,
61+ _event : string
62+ ) : Promise < ClientAPI . ClientResponse < Omit < ActivePlaylistEvent , 'event' | 'currentSegment' > > > {
63+ const rundownPlaylist = (
64+ await RundownPlaylists . findFetchAsync (
65+ { activationId : { $exists : true , $ne : undefined } } ,
66+ {
67+ projection : {
68+ _id : 1 ,
69+ name : 1 ,
70+ rundownIdsInOrder : 1 ,
71+ currentPartInfo : 1 ,
72+ // segmentsStartedPlayback: 1, somehow get current segment,
73+ nextPartInfo : 1 ,
74+ publicData : 1 ,
75+ timing : 1 ,
76+ quickLoop : 1 ,
77+ } ,
78+ limit : 1 ,
79+ }
80+ )
81+ ) ?. [ 0 ] as Pick <
82+ DBRundownPlaylist ,
83+ | '_id'
84+ | 'name'
85+ | 'rundownIdsInOrder'
86+ | 'currentPartInfo'
87+ | 'nextPartInfo'
88+ | 'publicData'
89+ | 'timing'
90+ | 'quickLoop'
91+ >
92+ return ClientAPI . responseSuccess ( {
93+ id : unprotectString ( rundownPlaylist . _id ) ,
94+ name : rundownPlaylist . name ,
95+ rundownIds : rundownPlaylist . rundownIdsInOrder . map ( ( id ) => unprotectString ( id ) ) ,
96+ currentPart : rundownPlaylist . currentPartInfo ,
97+ nextPart : rundownPlaylist . nextPartInfo ,
98+ publicData : rundownPlaylist . publicData ,
99+ timing : this . convertTiming ( rundownPlaylist . timing ) ,
100+ quickLoop : rundownPlaylist . quickLoop ,
101+ } as Omit < ActivePlaylistEvent , 'event' | 'currentSegment' > )
102+ }
103+
104+ convertTiming ( timing : RundownPlaylistTiming ) : ActivePlaylistTiming {
105+ switch ( timing . type ) {
106+ case PlaylistTimingType . None :
107+ return {
108+ timingMode : ActivePlaylistTimingMode . NONE ,
109+ expectedDurationMs : timing . expectedDuration ,
110+ }
111+ case PlaylistTimingType . ForwardTime :
112+ return {
113+ timingMode : ActivePlaylistTimingMode . FORWARD_MINUS_TIME ,
114+ expectedStart : Number ( timing . expectedStart ) ,
115+ expectedDurationMs : timing . expectedDuration ,
116+ expectedEnd : timing . expectedEnd ? Number ( timing . expectedEnd ) : undefined ,
117+ }
118+ case PlaylistTimingType . BackTime :
119+ return {
120+ timingMode : ActivePlaylistTimingMode . BACK_MINUS_TIME ,
121+ expectedStart : timing . expectedStart ? Number ( timing . expectedStart ) : undefined ,
122+ expectedDurationMs : timing . expectedDuration ,
123+ expectedEnd : Number ( timing . expectedEnd ) ,
124+ }
125+ }
126+ }
127+
53128 async activate (
54129 connection : Meteor . Connection ,
55130 event : string ,
@@ -548,6 +623,17 @@ export function registerRoutes(registerRoute: APIRegisterHook<PlaylistsRestAPI>)
548623 }
549624 )
550625
626+ registerRoute < never , never , Omit < ActivePlaylistEvent , 'event' | 'currentSegment' > > (
627+ 'get' ,
628+ '/playlists/active' , // should we use '/playlist'?
629+ new Map ( ) ,
630+ playlistsAPIFactory ,
631+ async ( serverAPI , connection , event , _params , _body ) => {
632+ logger . info ( `API GET: Active playlist` )
633+ return await serverAPI . getActiveRundownPlaylist ( connection , event )
634+ }
635+ )
636+
551637 registerRoute < { playlistId : string } , { rehearsal : boolean } , void > (
552638 'put' ,
553639 '/playlists/:playlistId/activate' ,
0 commit comments