Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Config deserialization #193

Merged
merged 8 commits into from
Oct 16, 2023
Merged
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
192 changes: 189 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 '../parameters'

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,190 @@ describe('serializers', () => {
})
)
})
describe('INFO Config', () => {
it('should deserialize correctly formed 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>2</device>
<latency>normal</latency>
</decklink>
</consumers>
<producers>
<producer id="0">AMB LOOP</producer>
<producer id="10">DECKLINK DEVICE 2</producer>
</producers>
</channel>
</channels>
<controllers>
<tcp>
<port>5250</port>
<protocol>AMCP</protocol>
</tcp>
</controllers>
<amcp>
<media-server>
<host>localhost</host>
<port>8000</port>
</media-server>
</amcp>
<ffmpeg>
<producer>
<auto-deinterlace>interlaced</auto-deinterlace>
<threads>4</threads>
</producer>
</ffmpeg>
<html>
<remote-debugging-port>0</remote-debugging-port>
<enable-gpu> true </enable-gpu>
</html>
<ndi>
<auto-load>false</auto-load>
</ndi>
<video-modes>
<video-mode>
<id>1024x768p60</id>
<width>1024</width>
<height>768</height>
<time-scale>60000</time-scale>
<duration>1000</duration>
<cadence>800</cadence>
</video-mode>
</video-modes>
</configuration>`,
]

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

expect(output).toMatchObject(
literal<InfoConfig>({
logLevel: LogLevel.Debug,
paths: {
media: 'media/',
data: 'data/',
logs: 'log/',
templates: 'templates/',
},
channels: [
{
videoMode: '1080p5000',
consumers: [
{
type: ConsumerType.SCREEN,
device: 1,
aspectRatio: 'default',
windowed: true,
},
],
producers: [],
},
{
videoMode: '1080p2500',
consumers: [
{
type: ConsumerType.DECKLINK,
device: 2,
latency: 'normal',
},
],
producers: [
{
id: 0,
producer: 'AMB LOOP',
},
{
id: 10,
producer: 'DECKLINK DEVICE 2',
},
],
},
],
controllers: {
tcp: {
port: 5250,
protocol: 'AMCP',
},
},
amcp: {
mediaServer: {
host: 'localhost',
port: 8000,
},
},
ffmpeg: {
producer: {
autoDeinterlace: 'interlaced',
threads: 4,
},
},
html: {
enableGpu: true,
remoteDebuggingPort: 0,
},
videoModes: [
{ cadence: 800, duration: 1000, height: 768, id: '1024x768p60', timeScale: 60000, width: 1024 },
],
ndi: {
autoLoad: false,
},
raw: {},
rawXml: input[0],
})
)
})
it('should not crash on non-xml', async () => {
const input = [`NOT XML`]

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

expect(output).toEqual(
literal<InfoConfig>({
rawXml: input[0],
})
)
})
it('should not crash on non-config', async () => {
const input = [
`<?xml version="1.0" encoding="utf-8"?>

<something-else></something-else>`,
]

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

expect(output).toEqual(
literal<InfoConfig>({
raw: {
'something-else': '',
},
rawXml: input[0],
})
)
})
})
})
3 changes: 2 additions & 1 deletion src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import {
InfoEntry,
InfoChannelEntry,
InfoLayerEntry,
InfoConfig,
} from './parameters'

export enum Commands {
Expand Down Expand Up @@ -275,7 +276,7 @@ export interface AllTypedCommands {
>
[Commands.InfoLayer]: TypedResponseCommand<Commands.InfoLayer, InfoLayerParameters, InfoLayerEntry | undefined>
[Commands.InfoTemplate]: TypedResponseCommand<Commands.InfoTemplate, InfoTemplateParameters, unknown>
[Commands.InfoConfig]: TypedResponseCommand<Commands.InfoConfig, InfoConfigParameters, unknown>
[Commands.InfoConfig]: TypedResponseCommand<Commands.InfoConfig, InfoConfigParameters, InfoConfig>
[Commands.InfoPaths]: TypedResponseCommand<Commands.InfoPaths, InfoPathsParameters, unknown>
[Commands.InfoSystem]: TypedResponseCommand<Commands.InfoSystem, InfoSystemParameters, unknown>
[Commands.InfoServer]: TypedResponseCommand<Commands.InfoServer, InfoServerParameters, unknown>
Expand Down
167 changes: 0 additions & 167 deletions src/deserializers.ts

This file was deleted.

Loading