Skip to content

Commit

Permalink
feat: add ping, begin and commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mint-dewit committed Nov 9, 2023
1 parent f1d835f commit 29a7268
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/CasparCG.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ import {
RestartParameters,
InfoChannelParameters,
InfoLayerParameters,
PingParameters,
BeginParameters,
CommitParameters,
} from './parameters'

export class CasparCG extends BasicCasparCGAPI {
Expand Down Expand Up @@ -554,5 +557,23 @@ export class CasparCG extends BasicCasparCGAPI {
params,
})
}
async ping(params: PingParameters = {}): Promise<APIRequest<Commands.Ping>> {
return this.executeCommand({
command: Commands.Ping,
params,
})
}
async begin(params: BeginParameters = {}): Promise<APIRequest<Commands.Begin>> {
return this.executeCommand({
command: Commands.Begin,
params,
})
}
async commit(params: CommitParameters = {}): Promise<APIRequest<Commands.Commit>> {
return this.executeCommand({
command: Commands.Commit,
params,
})
}
}
export type APIRequest<C extends Commands> = SendResult<CReturnType<C>>
15 changes: 15 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ import {
InfoChannelEntry,
InfoLayerEntry,
InfoConfig,
BeginParameters,
CommitParameters,
PingParameters,
} from './parameters'

export enum Commands {
Expand Down Expand Up @@ -176,6 +179,9 @@ export enum Commands {
Bye = 'BYE',
Kill = 'KILL',
Restart = 'RESTART',
Ping = 'PING',
Begin = 'BEGIN',
Commit = 'COMMIT',
}

export interface Command<Cmd extends Commands, Params> {
Expand Down Expand Up @@ -289,6 +295,9 @@ export interface AllTypedCommands {
[Commands.Bye]: TypedResponseCommand<Commands.Bye, ByeParameters, unknown>
[Commands.Kill]: TypedResponseCommand<Commands.Kill, KillParameters, unknown>
[Commands.Restart]: TypedResponseCommand<Commands.Restart, RestartParameters, unknown>
[Commands.Ping]: TypedResponseCommand<Commands.Ping, PingParameters, unknown>
[Commands.Begin]: TypedResponseCommand<Commands.Begin, BeginParameters, unknown>
[Commands.Commit]: TypedResponseCommand<Commands.Commit, CommitParameters, unknown>
}

export type LoadbgCommand = AllTypedCommands[Commands.Loadbg]['command']
Expand Down Expand Up @@ -375,6 +384,9 @@ export type GlGcCommand = AllTypedCommands[Commands.GlGc]['command']
export type ByeCommand = AllTypedCommands[Commands.Bye]['command']
export type KillCommand = AllTypedCommands[Commands.Kill]['command']
export type RestartCommand = AllTypedCommands[Commands.Restart]['command']
export type PingCommand = AllTypedCommands[Commands.Ping]['command']
export type BeginCommand = AllTypedCommands[Commands.Begin]['command']
export type CommitCommand = AllTypedCommands[Commands.Commit]['command']

export type AMCPCommand =
| LoadbgCommand
Expand Down Expand Up @@ -461,3 +473,6 @@ export type AMCPCommand =
| ByeCommand
| KillCommand
| RestartCommand
| PingCommand
| BeginCommand
| CommitCommand
3 changes: 3 additions & 0 deletions src/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,3 +525,6 @@ export type GlGcParameters = Empty
export type ByeParameters = Empty
export type KillParameters = Empty
export type RestartParameters = Empty
export type PingParameters = Empty
export type BeginParameters = Empty
export type CommitParameters = Empty

0 comments on commit 29a7268

Please sign in to comment.