Skip to content

Commit

Permalink
wip: SOF-752 support multiple showIds
Browse files Browse the repository at this point in the history
  • Loading branch information
ianshade committed Feb 18, 2022
1 parent 3047e39 commit 212b302
Show file tree
Hide file tree
Showing 5 changed files with 466 additions and 371 deletions.
2 changes: 1 addition & 1 deletion packages/timeline-state-resolver-types/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@tv2media/timeline-state-resolver-types",
"name": "timeline-state-resolver-types",
"version": "1.0.0-release37.4",
"description": "Have timeline, control stuff",
"main": "dist/index.js",
Expand Down
51 changes: 45 additions & 6 deletions packages/timeline-state-resolver-types/src/vizMSE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export enum TimelineContentTypeVizMSE {
CONTINUE = 'continue',
LOAD_ALL_ELEMENTS = 'load_all_elements',
CLEAR_ALL_ELEMENTS = 'clear_all_elements',
ALL_SHOWS = 'all_shows',
INITIALIZE_SHOWS = 'initialize_shows',
}

export type TimelineObjVIZMSEAny =
Expand All @@ -59,6 +61,8 @@ export type TimelineObjVIZMSEAny =
| TimelineObjVIZMSEElementContinue
| TimelineObjVIZMSELoadAllElements
| TimelineObjVIZMSEClearAllElements
| TimelineObjVIZMSEInitializeShows
| TimelineObjVIZMSEAllShows

export interface TimelineObjVIZMSEBase extends TSRTimelineObjBase {
content: {
Expand Down Expand Up @@ -105,6 +109,8 @@ export interface TimelineObjVIZMSEElementInternal extends TimelineObjVIZMSEBase
templateName: string
/** Data to be fed into the template */
templateData: Array<string>
/** Which Show to place this element in */
showId: string
/** Whether this element should have its take delayed until after an out transition has finished */
delayTakeAfterOutTransition?: boolean
}
Expand Down Expand Up @@ -160,6 +166,27 @@ export interface TimelineObjVIZMSEClearAllElements extends TSRTimelineObjBase {

/** Names of the channels to send the special clear commands to */
channelsToSendCommands?: string[]

/** IDs of the Show to use for taking the special template */
showId: string
}
}
export interface TimelineObjVIZMSEInitializeShows extends TSRTimelineObjBase {
content: {
deviceType: DeviceType.VIZMSE
type: TimelineContentTypeVizMSE.INITIALIZE_SHOWS

/** IDs of the Shows to initialize */
showIds?: string[]
}
}
export interface TimelineObjVIZMSEAllShows extends TSRTimelineObjBase {
content: {
deviceType: DeviceType.VIZMSE
type: TimelineContentTypeVizMSE.ALL_SHOWS

/** IDs of all the Shows that Sofie manages, that might need to be cleaned up at some point */
showIds?: string[]
}
}

Expand All @@ -176,14 +203,26 @@ export interface VIZMSETransitionDelay {
// For how long to delay the take out (ms)
delay: number
}
export interface VIZMSEPlayoutItemContent {
/** Name of the element, or Pilot Element */
templateName: string | number // if number, it's a vizPilot element
/** Data fields of the element (for internal elements only) */
templateData?: string[]
export interface VIZMSEPlayoutItemContentBase {
/** What channel to use for the element */
channelName?: string
channel?: string

/** If true, won't be preloaded (cued) automatically */
noAutoPreloading?: boolean
}

export interface VIZMSEPlayoutItemContentInternal extends VIZMSEPlayoutItemContentBase {
/** Name of the template that this element uses */
templateName: string
/** Data fields of the element */
templateData?: string[]
/** Which Show to place this element in */
showId: string
}

export interface VIZMSEPlayoutItemContentExternal extends VIZMSEPlayoutItemContentBase {
/** Id of the Pilot Element */
vcpid: number
}

export type VIZMSEPlayoutItemContent = VIZMSEPlayoutItemContentExternal | VIZMSEPlayoutItemContentInternal
101 changes: 54 additions & 47 deletions packages/timeline-state-resolver/src/__mocks__/v-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
ExternalElement,
VElement,
ExternalElementId,
InternalElementId,
ElementId,
isInternalElement,
isExternalElement,
} from '@tv2media/v-connection'
import { EventEmitter } from 'events'
import { CommandResult } from '@tv2media/v-connection/dist/msehttp'
Expand Down Expand Up @@ -76,9 +80,9 @@ export class MSEMock extends EventEmitter implements MSE {
async listShows(): Promise<string[]> {
return []
}
async getShow(showName: string): Promise<VShow> {
async getShow(showID: string): Promise<VShow> {
return {
id: 'mockshowid_' + showName,
id: 'mockshowid_' + showID,
}
}
async listPlaylists(): Promise<string[]> {
Expand All @@ -94,14 +98,9 @@ export class MSEMock extends EventEmitter implements MSE {
},
}
}
async createRundown(
showID: string,
profile: string,
playlistId?: string,
description?: string
): Promise<VRundownMock> {
async createRundown(profile: string, playlistId?: string, description?: string): Promise<VRundownMock> {
if (!playlistId) playlistId = 'mockrandomPlaylist' + Date.now()
const rundown = new VRundownMock(showID, profile, playlistId, description)
const rundown = new VRundownMock(profile, playlistId, description)

this.rundowns[playlistId] = rundown

Expand Down Expand Up @@ -166,12 +165,7 @@ export type VRundownMocked = MockClass<VRundown>
export class VRundownMock implements VRundown {
private elements: { [key: string]: VElement } = {}
private _isActive = false
constructor(
public readonly show: string,
public readonly profile: string,
public readonly playlist: string,
public readonly description?: string
) {
constructor(public readonly profile: string, public readonly playlist: string, public readonly description?: string) {
// Hack: replace methods with jest-ified ones
_.each(Object.getOwnPropertyNames(VRundownMock.prototype), (key) => {
if (key !== 'prototype') {
Expand All @@ -182,6 +176,24 @@ export class VRundownMock implements VRundown {
})
}

private static getElementHash(elementId: ElementId): string {
if (isInternalElement(elementId)) {
return `${elementId.instanceName}_${elementId.showId}`
} else {
return `${elementId.vcpid}_${elementId.channel}`
}
}

listInternalElements(_showId: string): Promise<InternalElementId[]> {
throw new Error('Method not implemented.')
}
async initializeShow(_showId: string): Promise<CommandResult> {
return { path: '', status: 200, response: 'mock' }
}
async cleanupShow(_showId: string): Promise<CommandResult> {
return { path: '', status: 200, response: 'mock' }
}

async listTemplates(): Promise<string[]> {
return []
}
Expand All @@ -191,27 +203,26 @@ export class VRundownMock implements VRundown {
defaultAlternatives: {}, // any
}
}
async createElement(vcpid: number, channel?: string, alias?: string): Promise<ExternalElement>
async createElement(elementId: ExternalElementId): Promise<ExternalElement>
async createElement(
elementId: InternalElementId,
templateName: string,
elementName: string,
textFields: string[],
channel?: string
): Promise<InternalElement>
async createElement(
templateNameOrVcpid: any,
elementNameOrChannel?: any,
textFieldsOrAlias?: any,
elementId: ElementId,
templateName?: string,
textFields?: string[],
channel?: string
): Promise<ExternalElement | InternalElement> {
if (typeof templateNameOrVcpid === 'number') {
const vcpid = templateNameOrVcpid
const channel = elementNameOrChannel
const hash = VRundownMock.getElementHash(elementId)
if (isExternalElement(elementId)) {
// const alias = textFieldsOrAlias

const el: ExternalElement = {
channel: channel,
vcpid: '' + vcpid,
channel: elementId.channel,
vcpid: elementId.vcpid.toString(),
// available?: string,
// is_loading?: string,
// loaded?: string,
Expand All @@ -221,35 +232,31 @@ export class VRundownMock implements VRundown {
// name?: string
}

this.elements['' + vcpid] = el
this.elements[hash] = el
return el
} else {
const templateName = templateNameOrVcpid
const elementName = elementNameOrChannel
const textFields = textFieldsOrAlias

const data: any = {}
_.each(textFields, (val, key) => {
_.each(textFields!, (val, key) => {
data['v' + key] = val
})
const el: InternalElement = {
channel: channel,
name: elementName,
template: templateName,
name: elementId.instanceName,
template: templateName!,
data: data,
}
this.elements[elementName] = el
this.elements[hash] = el
return el
}
}
async listElements(): Promise<Array<string | ExternalElementId>> {
async listExternalElements(): Promise<Array<ExternalElementId>> {
return []
}
async getElement(elementName: string | number): Promise<VElement> {
return this.elements[elementName]
async getElement(elementId: ElementId): Promise<VElement> {
return this.elements[VRundownMock.getElementHash(elementId)]
}
async deleteElement(elementName: string | number): Promise<PepResponse> {
delete this.elements[elementName]
async deleteElement(elementId: ElementId): Promise<PepResponse> {
delete this.elements[VRundownMock.getElementHash(elementId)]

return {
id: '*',
Expand All @@ -258,23 +265,23 @@ export class VRundownMock implements VRundown {
body: 'mock',
}
}
async cue(_elementName: string | number): Promise<CommandResult> {
async cue(_elementId: ElementId): Promise<CommandResult> {
return { path: '', status: 200, response: 'mock' }
}
async take(_elementName: string | number): Promise<CommandResult> {
async take(_elementId: ElementId): Promise<CommandResult> {
return { path: '', status: 200, response: 'mock' }
}
async continue(_elementName: string | number): Promise<CommandResult> {
async continue(_elementId: ElementId): Promise<CommandResult> {
return { path: '', status: 200, response: 'mock' }
}
async continueReverse(_elementName: string | number): Promise<CommandResult> {
async continueReverse(_elementId: ElementId): Promise<CommandResult> {
return { path: '', status: 200, response: 'mock' }
}
async out(_elementName: string | number): Promise<CommandResult> {
async out(_elementId: ElementId): Promise<CommandResult> {
return { path: '', status: 200, response: 'mock' }
}
async initialize(_elementName: number): Promise<CommandResult> {
const el = this.elements[_elementName]
async initialize(elementId: ExternalElementId): Promise<CommandResult> {
const el = this.elements[VRundownMock.getElementHash(elementId)]
if (!el) throw new Error('Element not found')

// available?: string,
Expand All @@ -299,7 +306,7 @@ export class VRundownMock implements VRundown {
async cleanup(): Promise<CommandResult> {
return { path: '', status: 200, response: 'mock' }
}
async purge(_elementsToKeep?: ExternalElementId[]): Promise<PepResponse> {
async purge(_showIds: string[], _elementsToKeep?: ExternalElementId[]): Promise<PepResponse> {
return { id: '*', status: 'ok', body: 'mock' }
}
async isActive(): Promise<boolean> {
Expand Down
Loading

0 comments on commit 212b302

Please sign in to comment.