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'