Skip to content

Commit

Permalink
fix: CasparCG: add listMedia action (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
nytamin committed Oct 13, 2023
1 parent 43efbed commit f4277ad
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 4 deletions.
19 changes: 17 additions & 2 deletions packages/timeline-state-resolver-types/src/generated/casparCG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,28 @@ export enum MappingCasparCGType {

export type SomeMappingCasparCG = MappingCasparCGLayer

export interface ListMediaPayload {
subDirectory?: string
}

export type ListMediaReturnData = {
clip: string
type: 'MOVIE' | 'STILL' | 'AUDIO'
size: number
dateTime: number
frames: number
framerate: number
}[]

export enum CasparCGActions {
ClearAllChannels = 'clearAllChannels',
RestartServer = 'restartServer'
RestartServer = 'restartServer',
ListMedia = 'listMedia'
}
export interface CasparCGActionExecutionResults {
clearAllChannels: () => void,
restartServer: () => void
restartServer: () => void,
listMedia: (payload: ListMediaPayload) => ListMediaReturnData
}
export type CasparCGActionExecutionPayload<A extends keyof CasparCGActionExecutionResults> = Parameters<
CasparCGActionExecutionResults[A]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,60 @@
"id": "restartServer",
"name": "Restart Server",
"destructive": true
},
{
"id": "listMedia",
"name": "List items in media folder",
"destructive": false,
"payload": {
"type": "object",
"properties": {
"subDirectory": {
"type": "string"
}
},
"additionalProperties": false
},
"returnData": {
"type": "array",
"items": {
"type": "object",
"properties": {
"clip": {
"type": "string",
},
"type": {
"type": "string",
"enum": [
"MOVIE",
"STILL",
"AUDIO"
]
},
"size": {
"type": "number"
},
"dateTime": {
"type": "number"
},
"frames": {
"type": "number"
},
"framerate": {
"type": "number"
}
},
"required": [
"clip",
"type",
"size",
"dateTime",
"frames",
"framerate"
],
"additionalProperties": false
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as _ from 'underscore'
import * as deepMerge from 'deepmerge'
import { DeviceWithState, CommandWithContext, DeviceStatus, StatusCode, literal } from '../../devices/device'
import { AMCPCommand, BasicCasparCGAPI, ClearCommand, Commands, Response } from 'casparcg-connection'
import { AMCPCommand, BasicCasparCGAPI, ClearCommand, ClsCommand, Commands, Response } from 'casparcg-connection'
import {
DeviceType,
TimelineContentTypeCasparCg,
Expand Down Expand Up @@ -48,6 +48,8 @@ import got from 'got'
import { InternalTransitionHandler } from '../../devices/transitions/transitionHandler'
import Debug from 'debug'
import { actionNotFoundMessage, endTrace, startTrace, t } from '../../lib'
import { ListMediaReturnData } from 'timeline-state-resolver-types'
import { ClsParameters } from 'casparcg-connection/dist/parameters'
const debug = Debug('timeline-state-resolver:casparcg')

const MEDIA_RETRY_INTERVAL = 10 * 1000 // default time in ms between checking whether a file needs to be retried loading
Expand Down Expand Up @@ -669,13 +671,15 @@ export class CasparCGDevice extends DeviceWithState<State, DeviceOptionsCasparCG
}
async executeAction<A extends CasparCGActions>(
actionId: A,
_payload: CasparCGActionExecutionPayload<A>
payload: CasparCGActionExecutionPayload<A>
): Promise<CasparCGActionExecutionResult<A>> {
switch (actionId) {
case CasparCGActions.ClearAllChannels:
return this.clearAllChannels() as Promise<CasparCGActionExecutionResult<A>>
case CasparCGActions.RestartServer:
return this.restartCasparCG() as Promise<CasparCGActionExecutionResult<A>>
case CasparCGActions.ListMedia:
return this.listMedia(payload) as Promise<CasparCGActionExecutionResult<A>>
default:
return actionNotFoundMessage(actionId)
}
Expand Down Expand Up @@ -730,6 +734,34 @@ export class CasparCGDevice extends DeviceWithState<State, DeviceOptionsCasparCG
}
})
}
private async listMedia(query: ClsParameters = {}): Promise<ActionExecutionResult<ListMediaReturnData>> {
const result = await this._ccg.executeCommand(
literal<ClsCommand>({
command: Commands.Cls,
params: query,
})
)
if (result.error)
return {
result: ActionExecutionResultCode.Error,
response: t(`Error message from CasparCG: {{message}}`, { message: `${result.error}` }),
}

const request = await result.request

if (request.responseCode === 200) {
// TODO: implement return data
return {
result: ActionExecutionResultCode.Ok,
returnData: [],
}
} else {
return {
result: ActionExecutionResultCode.Error,
response: t(`Error code {{code}} from CasparCG`, { code: request.responseCode }),
}
}
}
getStatus(): DeviceStatus {
let statusCode = StatusCode.GOOD
const messages: Array<string> = []
Expand Down

0 comments on commit f4277ad

Please sign in to comment.