Skip to content

Commit

Permalink
wip: type up config interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ianshade committed Oct 4, 2023
1 parent 10c0db2 commit b9676eb
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/CasparCG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ import {
RestartParameters,
InfoChannelParameters,
InfoLayerParameters,
} from './parameters'
} from './parameterAndReturnTypes'

export class CasparCG extends BasicCasparCGAPI {
async loadbg(params: LoadbgParameters): Promise<APIRequest<Commands.Loadbg>> {
Expand Down
106 changes: 103 additions & 3 deletions src/__tests__/deserializers.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// import { Version } from '../enums'
import { Commands } from '../commands'
import { deserializers } from '../deserializers'
import { Version } from '../enums'
import { LogLevel, Version } from '../enums'
import { literal } from '../lib'
import { InfoChannelEntry, InfoEntry } from '../parameters'
import { ConsumerType, InfoChannelEntry, InfoConfig, InfoEntry } from '../parameterAndReturnTypes'

describe('serializers', () => {
describe('deserializers', () => {
it('should deserialize CINF', async () => {
// "AMB" MOVIE size datetime frames rate
const input = '"AMB" MOVIE 1234 20230609070542 12 1/25'
Expand Down Expand Up @@ -202,4 +202,104 @@ describe('serializers', () => {
})
)
})
it('should deserialize INFO Config', async () => {
const input = [
`<?xml version="1.0" encoding="utf-8"?>
<configuration>
<log-level>debug</log-level>
<paths>
<media-path>media/</media-path>
<log-path>log/</log-path>
<data-path>data/</data-path>
<template-path>templates/</template-path>
</paths>
<lock-clear-phrase>secret</lock-clear-phrase>
<channels>
<channel>
<video-mode>1080p5000</video-mode>
<consumers>
<screen>
<device>1</device>
<aspect-ratio>default</aspect-ratio>
<stretch>fill</stretch>
<windowed>true</windowed>
</screen>
</consumers>
</channel>
<channel>
<video-mode>1080p2500</video-mode>
<consumers>
<decklink>
<device>1</device>
<latency>normal</latency>
</screen>
</consumers>
</channel>
</channels>
<controllers>
<tcp>
<port>5250</port>
<protocol>AMCP</protocol>
</tcp>
</controllers>
<amcp>
<media-server>
<host>localhost</host>
<port>8000</port>
</media-server>
</amcp>
</configuration>`,
]

const output = await deserializers[Commands.InfoConfig](input)

expect(output).toMatchObject(
literal<InfoConfig>({
logLevel: LogLevel.Debug,
paths: {
media: 'media/',
data: 'data/',
log: 'log/',
template: 'template/',
},
channels: [
{
videoMode: '1080p5000',
consumers: [
{
type: ConsumerType.SCREEN,
device: 1,
aspectRatio: 'default',
windowed: true,
},
],
},
{
videoMode: '1080p2500',
consumers: [
{
type: ConsumerType.DECKLINK,
device: 1,
latency: 'normal',
},
],
},
],
controllers: {
tcp: {
port: 5250,
protocol: 'AMCP',
},
},
amcp: {
mediaServer: {
host: 'localhost',
port: 8000,
},
},
rawXml: input[0],
})
)
})
})
2 changes: 1 addition & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import {
InfoEntry,
InfoChannelEntry,
InfoLayerEntry,
} from './parameters'
} from './parameterAndReturnTypes'

export enum Commands {
Loadbg = 'LOADBG',
Expand Down
2 changes: 1 addition & 1 deletion src/deserializers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CReturnType, Commands } from './commands'
import { Version } from './enums'
import { ClipInfo, InfoChannelEntry, InfoEntry, InfoLayerEntry } from './parameters'
import { ClipInfo, InfoChannelEntry, InfoEntry, InfoLayerEntry } from './parameterAndReturnTypes'
import { parseStringPromise } from 'xml2js'

function deserializeClipInfo(line: string): ClipInfo | undefined {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export * from './CasparCG'
export * from './api'
export * as Enum from './enums'
export * from './commands'
export * from './parameters'
export * from './parameterAndReturnTypes'
150 changes: 150 additions & 0 deletions src/parameters.ts → src/parameterAndReturnTypes.ts
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,157 @@ export type InfoLayerEntry = InfoChannelEntry
export interface InfoTemplateParameters {
template: string
}

export type InfoConfigParameters = Empty
export const enum ConsumerType {
DECKLINK = 'decklink',
BLUEFISH = 'bluefish',
SYSTEM_AUDIO = 'system-audio',
SCREEN = 'screen',
NEWTEK_IVGA = 'newtek-ivga',
NDI = 'ndi',
FFMPEG = 'ffmpeg',
}
export interface ConsumerConfig {
type: ConsumerType
}
export interface DeckLinkConsumerConfig extends ConsumerConfig {
type: ConsumerType.DECKLINK
device: number
keyDevice?: number
embeddedAudio?: boolean
latency?: string
keyer?: string
keyOnly?: string
bufferDepth?: number
videoMode?: string
subregion?: {
srcX: number
srcY: number
destX: number
destY: number
width: number
height: number
}
}
export interface BluefishConsumerConfig extends ConsumerConfig {
type: ConsumerType.BLUEFISH
device: number
sdiStream?: number
embeddedAudio?: boolean
keyer?: string
internalKeyerAudioSource?: string
watchdog?: number
uhdMode?: number
}
export interface SystemAudioConsumerConfig extends ConsumerConfig {
type: ConsumerType.SYSTEM_AUDIO
channelLayout?: string
latency?: number
}
export interface ScreenConsumerConfig extends ConsumerConfig {
type: ConsumerType.SCREEN
device?: number
aspectRatio?: string
stretch?: number
windowed?: boolean
keyOnly?: boolean
vsync?: boolean
borderless?: string
interactive?: boolean
alwaysOnTop?: boolean
x?: number
y?: number
width?: number
height?: number
sbsKey?: boolean
colourSpace?: string
}
export interface IVgaConsumerConfig extends ConsumerConfig {
type: ConsumerType.NEWTEK_IVGA
}
export interface NdiConsumerConfig extends ConsumerConfig {
type: ConsumerType.NDI
name?: string
allowFields?: boolean
}
export interface FFmpegConsumerConfig extends ConsumerConfig {
type: ConsumerType.FFMPEG
path?: string
args?: string
}
export type ConsumerConfigAny =
| DeckLinkConsumerConfig
| BluefishConsumerConfig
| SystemAudioConsumerConfig
| ScreenConsumerConfig
| IVgaConsumerConfig
| NdiConsumerConfig
| FFmpegConsumerConfig
export interface InfoChannelConfig {
videoMode: string
consumers: ConsumerConfigAny[]
}
export interface TemplateHostConfig {
videoMode?: string
fileName?: string
width?: number
height?: number
}
export interface InfoVideoModeConfig {
id: string
width: number
height: number
timeScale: number
duration: number
cadence: number
}
export interface InfoConfig {
logLevel?: LogLevel
paths: {
media: string
log: string
data: string
template: string
}
lockClearPhrase?: string
channels: InfoChannelConfig[]
templateHosts?: TemplateHostConfig[]
ffmpeg?: {
producer?: {
autoDeinterlace?: string
threads?: number
}
}
html?: {
remoteDebuggingPort?: number
enableGpu?: boolean
}
ndi?: {
autoLoad?: boolean
}
osc?: {
defaulPort?: number
disableSendToAmcpClients?: boolean
predefinedClients?: Array<{ address: string; port: number }>
}
controllers?: {
tcp?: {
port?: number
protocol?: string
}
}
amcp?: {
mediaServer?: {
host?: string
port?: number
}
}
videoModes?: InfoVideoModeConfig[]
// Unparsed contents of the config file
rawXml: string
}

export type InfoPathsParameters = Empty
export type InfoSystemParameters = Empty
export type InfoServerParameters = Empty
Expand Down
2 changes: 1 addition & 1 deletion src/serializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
RemoveParameters,
RouteParameters,
TransitionParameters,
} from './parameters'
} from './parameterAndReturnTypes'

const commandNameSerializer = (command: Commands): string => command
const splitCommandSerializer = (command: Commands): string => command.split(' ')[0]
Expand Down

0 comments on commit b9676eb

Please sign in to comment.