Skip to content
Draft
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
5 changes: 5 additions & 0 deletions meteor/__mocks__/defaultCollectionObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export function defaultRundownPlaylist(_id: RundownPlaylistId, studioId: StudioI
type: 'none' as any,
},
rundownIdsInOrder: [],
tTimers: [
{ index: 1, label: '', mode: null },
{ index: 2, label: '', mode: null },
{ index: 3, label: '', mode: null },
],
}
}
export function defaultRundown(
Expand Down
1 change: 1 addition & 0 deletions meteor/server/__tests__/cronjobs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,7 @@ describe('cronjobs', () => {
type: PlaylistTimingType.None,
},
activationId: protectString(''),
tTimers: [] as any,
})

return {
Expand Down
1 change: 1 addition & 0 deletions meteor/server/api/__tests__/externalMessageQueue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ describe('Test external message queue static methods', () => {
type: PlaylistTimingType.None,
},
rundownIdsInOrder: [protectString('rundown_1')],
tTimers: [] as any,
})
await Rundowns.mutableCollection.insertAsync({
_id: protectString('rundown_1'),
Expand Down
1 change: 1 addition & 0 deletions meteor/server/api/__tests__/peripheralDevice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
type: PlaylistTimingType.None,
},
rundownIdsInOrder: [rundownID],
tTimers: [] as any,
})
await Rundowns.mutableCollection.insertAsync({
_id: rundownID,
Expand Down Expand Up @@ -494,7 +495,7 @@
).rejects.toThrowMeteor(418, `Error thrown, as requested`)
})

/*

Check warning on line 498 in meteor/server/api/__tests__/peripheralDevice.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck and Lint Core

Some tests seem to be commented

Check warning on line 498 in meteor/server/api/__tests__/peripheralDevice.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck and Lint Core

Some tests seem to be commented
test('timelineTriggerTime', () => {
if (DEBUG) setLogLevel(LogLevel.DEBUG)
let timelineTriggerTimeResult: PeripheralDeviceAPI.TimelineTriggerTimeResult = [
Expand Down Expand Up @@ -562,7 +563,7 @@
})

// Note: this test fails, due to a backwards-compatibility hack in #c579c8f0
// test('initialize with bad arguments', () => {

Check warning on line 566 in meteor/server/api/__tests__/peripheralDevice.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck and Lint Core

Some tests seem to be commented

Check warning on line 566 in meteor/server/api/__tests__/peripheralDevice.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck and Lint Core

Some tests seem to be commented
// let options: PeripheralDeviceInitOptions = {
// category: PeripheralDeviceCategory.INGEST,
// type: PeripheralDeviceType.MOS,
Expand All @@ -583,7 +584,7 @@
// }
// })

// test('setStatus with bad arguments', () => {

Check warning on line 587 in meteor/server/api/__tests__/peripheralDevice.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck and Lint Core

Some tests seem to be commented

Check warning on line 587 in meteor/server/api/__tests__/peripheralDevice.test.ts

View workflow job for this annotation

GitHub Actions / Typecheck and Lint Core

Some tests seem to be commented
// try {
// Meteor.call(PeripheralDeviceAPIMethods.setStatus, 'wibbly', device.token, { statusCode: 0 })
// fail('expected to throw')
Expand Down
77 changes: 77 additions & 0 deletions meteor/server/api/rest/v1/__tests__/playlists.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { registerRoutes } from '../playlists'
import { ClientAPI } from '@sofie-automation/meteor-lib/dist/api/client'
import { protectString } from '@sofie-automation/corelib/dist/protectedString'
import { PlaylistsRestAPI } from '../../../../lib/rest/v1'

describe('Playlists REST API Routes', () => {
let mockRegisterRoute: jest.Mock
let mockServerAPI: jest.Mocked<PlaylistsRestAPI>

beforeEach(() => {
mockRegisterRoute = jest.fn()
mockServerAPI = {
tTimerStartCountdown: jest.fn().mockResolvedValue(ClientAPI.responseSuccess(undefined)),
tTimerStartFreeRun: jest.fn().mockResolvedValue(ClientAPI.responseSuccess(undefined)),
tTimerPause: jest.fn().mockResolvedValue(ClientAPI.responseSuccess(undefined)),
tTimerResume: jest.fn().mockResolvedValue(ClientAPI.responseSuccess(undefined)),
tTimerRestart: jest.fn().mockResolvedValue(ClientAPI.responseSuccess(undefined)),
} as any

registerRoutes(mockRegisterRoute)
})

test('should register T-timer countdown route', () => {
const countdownRoute = mockRegisterRoute.mock.calls.find(
(call) => call[1] === '/playlists/:playlistId/t-timers/:timerIndex/countdown'
)
expect(countdownRoute).toBeDefined()
expect(countdownRoute[0]).toBe('post')
})

test('T-timer countdown handler should call serverAPI.tTimerStartCountdown', async () => {
const countdownRoute = mockRegisterRoute.mock.calls.find(
(call) => call[1] === '/playlists/:playlistId/t-timers/:timerIndex/countdown'
)
const handler = countdownRoute[4]

const params = { playlistId: 'playlist0', timerIndex: '1' }
const body = { duration: 60, stopAtZero: true, startPaused: false }
const connection = {} as any
const event = 'test-event'

await handler(mockServerAPI, connection, event, params, body)

expect(mockServerAPI.tTimerStartCountdown).toHaveBeenCalledWith(
connection,
event,
protectString('playlist0'),
1,
60,
true,
false
)
})

test('should register T-timer pause route', () => {
const pauseRoute = mockRegisterRoute.mock.calls.find(
(call) => call[1] === '/playlists/:playlistId/t-timers/:timerIndex/pause'
)
expect(pauseRoute).toBeDefined()
expect(pauseRoute[0]).toBe('post')
})

test('T-timer pause handler should call serverAPI.tTimerPause', async () => {
const pauseRoute = mockRegisterRoute.mock.calls.find(
(call) => call[1] === '/playlists/:playlistId/t-timers/:timerIndex/pause'
)
const handler = pauseRoute[4]

const params = { playlistId: 'playlist0', timerIndex: '2' }
const connection = {} as any
const event = 'test-event'

await handler(mockServerAPI, connection, event, params, {})

expect(mockServerAPI.tTimerPause).toHaveBeenCalledWith(connection, event, protectString('playlist0'), 2)
})
})
226 changes: 226 additions & 0 deletions meteor/server/api/rest/v1/playlists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
RundownPlaylistId,
SegmentId,
} from '@sofie-automation/corelib/dist/dataModel/Ids'
import { RundownTTimerIndex } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
import { Match, check } from '../../../lib/check'
import { PlaylistsRestAPI } from '../../../lib/rest/v1'
import { Meteor } from 'meteor/meteor'
Expand Down Expand Up @@ -544,6 +545,133 @@ class PlaylistsServerAPI implements PlaylistsRestAPI {
}
)
}

async tTimerStartCountdown(
connection: Meteor.Connection,
event: string,
rundownPlaylistId: RundownPlaylistId,
timerIndex: RundownTTimerIndex,
duration: number,
stopAtZero?: boolean,
startPaused?: boolean
): Promise<ClientAPI.ClientResponse<void>> {
return ServerClientAPI.runUserActionInLogForPlaylistOnWorker(
this.context.getMethodContext(connection),
event,
getCurrentTime(),
rundownPlaylistId,
() => {
check(rundownPlaylistId, String)
check(timerIndex, Number)
check(duration, Number)
check(stopAtZero, Match.Optional(Boolean))
check(startPaused, Match.Optional(Boolean))
},
StudioJobs.TTimerStartCountdown,
{
playlistId: rundownPlaylistId,
timerIndex,
duration,
stopAtZero: !!stopAtZero,
startPaused: !!startPaused,
}
)
}

async tTimerStartFreeRun(
connection: Meteor.Connection,
event: string,
rundownPlaylistId: RundownPlaylistId,
timerIndex: RundownTTimerIndex,
startPaused?: boolean
): Promise<ClientAPI.ClientResponse<void>> {
return ServerClientAPI.runUserActionInLogForPlaylistOnWorker(
this.context.getMethodContext(connection),
event,
getCurrentTime(),
rundownPlaylistId,
() => {
check(rundownPlaylistId, String)
check(timerIndex, Number)
check(startPaused, Match.Optional(Boolean))
},
StudioJobs.TTimerStartFreeRun,
{
playlistId: rundownPlaylistId,
timerIndex,
startPaused: !!startPaused,
}
)
}

async tTimerPause(
connection: Meteor.Connection,
event: string,
rundownPlaylistId: RundownPlaylistId,
timerIndex: RundownTTimerIndex
): Promise<ClientAPI.ClientResponse<void>> {
return ServerClientAPI.runUserActionInLogForPlaylistOnWorker(
this.context.getMethodContext(connection),
event,
getCurrentTime(),
rundownPlaylistId,
() => {
check(rundownPlaylistId, String)
check(timerIndex, Number)
},
StudioJobs.TTimerPause,
{
playlistId: rundownPlaylistId,
timerIndex,
}
)
}

async tTimerResume(
connection: Meteor.Connection,
event: string,
rundownPlaylistId: RundownPlaylistId,
timerIndex: RundownTTimerIndex
): Promise<ClientAPI.ClientResponse<void>> {
return ServerClientAPI.runUserActionInLogForPlaylistOnWorker(
this.context.getMethodContext(connection),
event,
getCurrentTime(),
rundownPlaylistId,
() => {
check(rundownPlaylistId, String)
check(timerIndex, Number)
},
StudioJobs.TTimerResume,
{
playlistId: rundownPlaylistId,
timerIndex,
}
)
}

async tTimerRestart(
connection: Meteor.Connection,
event: string,
rundownPlaylistId: RundownPlaylistId,
timerIndex: RundownTTimerIndex
): Promise<ClientAPI.ClientResponse<void>> {
return ServerClientAPI.runUserActionInLogForPlaylistOnWorker(
this.context.getMethodContext(connection),
event,
getCurrentTime(),
rundownPlaylistId,
() => {
check(rundownPlaylistId, String)
check(timerIndex, Number)
},
StudioJobs.TTimerRestart,
{
playlistId: rundownPlaylistId,
timerIndex,
}
)
}
}

class PlaylistsAPIFactory implements APIFactory<PlaylistsRestAPI> {
Expand Down Expand Up @@ -877,4 +1005,102 @@ export function registerRoutes(registerRoute: APIRegisterHook<PlaylistsRestAPI>)
return await serverAPI.recallStickyPiece(connection, event, playlistId, sourceLayerId)
}
)

registerRoute<
{ playlistId: string; timerIndex: string },
{ duration: number; stopAtZero?: boolean; startPaused?: boolean },
void
>(
'post',
'/playlists/:playlistId/t-timers/:timerIndex/countdown',
new Map([[404, [UserErrorMessage.RundownPlaylistNotFound]]]),
playlistsAPIFactory,
async (serverAPI, connection, event, params, body) => {
const rundownPlaylistId = protectString<RundownPlaylistId>(params.playlistId)
const timerIndex = Number.parseInt(params.timerIndex) as RundownTTimerIndex
logger.info(`API POST: t-timer countdown ${rundownPlaylistId} ${timerIndex}`)

check(rundownPlaylistId, String)
check(timerIndex, Number)
return await serverAPI.tTimerStartCountdown(
connection,
event,
rundownPlaylistId,
timerIndex,
body.duration,
body.stopAtZero,
body.startPaused
)
}
)

registerRoute<{ playlistId: string; timerIndex: string }, { startPaused?: boolean }, void>(
'post',
'/playlists/:playlistId/t-timers/:timerIndex/free-run',
new Map([[404, [UserErrorMessage.RundownPlaylistNotFound]]]),
playlistsAPIFactory,
async (serverAPI, connection, event, params, body) => {
const rundownPlaylistId = protectString<RundownPlaylistId>(params.playlistId)
const timerIndex = Number.parseInt(params.timerIndex) as RundownTTimerIndex
logger.info(`API POST: t-timer free-run ${rundownPlaylistId} ${timerIndex}`)

check(rundownPlaylistId, String)
check(timerIndex, Number)
return await serverAPI.tTimerStartFreeRun(
connection,
event,
rundownPlaylistId,
timerIndex,
body.startPaused
)
}
)

registerRoute<{ playlistId: string; timerIndex: string }, never, void>(
'post',
'/playlists/:playlistId/t-timers/:timerIndex/pause',
new Map([[404, [UserErrorMessage.RundownPlaylistNotFound]]]),
playlistsAPIFactory,
async (serverAPI, connection, event, params, _) => {
const rundownPlaylistId = protectString<RundownPlaylistId>(params.playlistId)
const timerIndex = Number.parseInt(params.timerIndex) as RundownTTimerIndex
logger.info(`API POST: t-timer pause ${rundownPlaylistId} ${timerIndex}`)

check(rundownPlaylistId, String)
check(timerIndex, Number)
return await serverAPI.tTimerPause(connection, event, rundownPlaylistId, timerIndex)
}
)

registerRoute<{ playlistId: string; timerIndex: string }, never, void>(
'post',
'/playlists/:playlistId/t-timers/:timerIndex/resume',
new Map([[404, [UserErrorMessage.RundownPlaylistNotFound]]]),
playlistsAPIFactory,
async (serverAPI, connection, event, params, _) => {
const rundownPlaylistId = protectString<RundownPlaylistId>(params.playlistId)
const timerIndex = Number.parseInt(params.timerIndex) as RundownTTimerIndex
logger.info(`API POST: t-timer resume ${rundownPlaylistId} ${timerIndex}`)

check(rundownPlaylistId, String)
check(timerIndex, Number)
return await serverAPI.tTimerResume(connection, event, rundownPlaylistId, timerIndex)
}
)

registerRoute<{ playlistId: string; timerIndex: string }, never, void>(
'post',
'/playlists/:playlistId/t-timers/:timerIndex/restart',
new Map([[404, [UserErrorMessage.RundownPlaylistNotFound]]]),
playlistsAPIFactory,
async (serverAPI, connection, event, params, _) => {
const rundownPlaylistId = protectString<RundownPlaylistId>(params.playlistId)
const timerIndex = Number.parseInt(params.timerIndex) as RundownTTimerIndex
logger.info(`API POST: t-timer restart ${rundownPlaylistId} ${timerIndex}`)

check(rundownPlaylistId, String)
check(timerIndex, Number)
return await serverAPI.tTimerRestart(connection, event, rundownPlaylistId, timerIndex)
}
)
}
Loading
Loading