From bc0504557bb200d22074b9963d335013b32fa4e6 Mon Sep 17 00:00:00 2001 From: Balte de Wit Date: Sat, 21 Sep 2019 09:46:50 +0200 Subject: [PATCH] feat: goto command --- src/commands/goTo.ts | 35 +++++++++++++++++++++++++++++++++++ src/commands/index.ts | 1 + 2 files changed, 36 insertions(+) create mode 100644 src/commands/goTo.ts diff --git a/src/commands/goTo.ts b/src/commands/goTo.ts new file mode 100644 index 0000000..9c2f1f4 --- /dev/null +++ b/src/commands/goTo.ts @@ -0,0 +1,35 @@ +import { NamedMessage } from '../message' +import { AbstractCommandNoResponse } from './abstractCommand' + +export class GoToCommand extends AbstractCommandNoResponse { + clip?: string + clipId?: number + timecode?: string + + constructor (clip?: string, clipId?: number, timecode?: string) { + super() + + this.clip = clip + this.clipId = clipId + this.timecode = timecode + } + + serialize () { + const res: NamedMessage = { + name: 'goto', + params: {} + } + + if (this.clip !== undefined) res.params.clip = this.clip + if (this.clipId !== undefined) res.params.clipId = this.clipId + '' + if (this.timecode !== undefined) res.params.timecode = this.timecode + + if (Object.keys(res.params).length === 0) { + throw new Error('GoToCommand needs at least one parameter') + } else if (Object.keys(res.params).length > 1) { + throw new Error('GoToCommand should have at most one parameter') + } + + return res + } +} diff --git a/src/commands/index.ts b/src/commands/index.ts index 5a2bee0..aeb442c 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -4,6 +4,7 @@ export * from './connect' export * from './configuration' export * from './deviceInfo' export * from './format' +export * from './goTo' export * from './notify' export * from './playCommand' export * from './record'