import type { WebSocket as WsWebSocket } from 'ws'; import type { Control } from './entities/Control.js'; import type { Component } from './entities/Component.js'; /** * QRC RPC types */ interface IRpcMeta { jsonrpc: '2.0'; id: string; } interface IRpcResponseBody extends IRpcMeta { result: T; } export interface IRpcError extends IRpcMeta { error: { code: number; message: string; }; } export interface IRpcRequest extends IRpcMeta { apiKey?: string; method: string; params: IRpcRequestParams; } export type IRpcRequestParams = Parameters[0]; export type IRpcResponse = IRpcResponseBody>; export interface IJsonRpcMessageTypeMap { 'Component.GetComponents': (arg: IComponentGetComponentsRequest) => IComponentGetComponentsResult[]; 'Component.GetControls': (arg: IComponentGetControlsRequest) => IComponentGetControlsResult; 'Component.Set': (arg: IComponentSetRequest) => IControlChange[]; 'ChangeGroup.Poll': (arg: IChangeGroupPollRequest) => IChangeGroupPollResult; 'ChangeGroup.AddComponentControl': (arg: IChangeGroupAddComponentControlRequest) => IChangeGroupAddComponentControlResult; StatusGet: () => IStatusGetResult; } export interface IStatusGetResult { Platform: string; State: 'Active' | 'Idle' | 'Standby'; DesignName: string; DesignCode: string; IsRedundant: boolean; IsEmulator: boolean; Status: { Code: number; String: string; }; } export type IEngineStatus = { State: 'Idle' | 'Active' | 'Standby' | 'Disconnected'; DesignName?: string; DesignCode?: string; IsRedundant?: boolean; IsEmulator?: boolean; Platform?: string; Status?: { Code: number; String: string; }; }; /** * Component.GetComponents RPC types */ export interface IComponentGetComponentsResult { Properties: Readonly; ID: string; Name: string; Type: string; Controls: null; ControlSource: number; } export interface IComponentGetComponentsProperty { Name: string; Value: string; PrettyName: string; } export type IComponentGetComponentsRequest = 'test'; export type IComponentGetComponentsResponse = IRpcResponseBody; /** * Component.GetControls RPC */ export interface IComponentGetControlsRequest { Name: string; } export type IComponentGetControlsResponse = IRpcResponseBody; export interface IComponentGetControlsResult { Name: string; Controls: IComponentGetControlsControl[]; } export interface IComponentGetControlsControl { Name: string; Type: string; Choices?: string[]; Value?: number; String?: string; Direction: string; Position?: number; ValueMin?: number; ValueMax?: number; StringMin?: string; StringMax?: string; } /** * ChangeGroup.AddComponentControl types */ export interface IChangeGroupAddComponentControlRequest { Id: string; Component: { Name: string; Controls: { Name: string; }[]; }; } export interface IChangeGroupAddComponentControlResult { Id: string; Controls: string[]; } export type IChangeGroupAddComponentControlResponse = IRpcResponseBody; /** * ChangeGroup.Poll RPC types */ export interface IChangeGroupPollRequest { Id: string; } export interface IChangeGroupPollResult { Id: string; Changes: IControlChange[]; } export type IChangeGroupPollResponse = IRpcResponseBody; /** * Component.Set RPC types */ export interface IComponentSetRequest { ResponseValues: boolean; Name: string; Controls: ({ Name: string; } & IControlUpdate)[]; } export type IComponentSetResponse = IRpcResponseBody; export interface IControlChange { Component: string; Name: string; String: string; Value: number; Position: number; Choices?: string[]; Color?: string; Indeterminate?: boolean; Invisible?: boolean; Disabled?: boolean; Legend?: string; CssClass?: string; Strings?: string[]; Values?: number[]; Positions?: number[]; } export interface IControlUpdate { String?: string; Value?: string | number; Position?: number; Strings?: string[]; Values?: number[]; Positions?: number[]; Bool?: boolean; } /** * EventEmitter event types * These are used to define the listeners for each EventEmitter * based on the supplied event */ export interface IEventEmitter { on(event: U, listener: T[U]): void; emit(event: U, ...args: T[U] extends (...args: any[]) => void ? Parameters : never): void; removeListener(event: U, listener: T[U]): void; removeAllListeners(): void; } export interface IComponentEvents { update: (control: Control, state: Control['state']) => void; error: (error: Error) => void; } export interface IControlEvents { update: (state: Control['state']) => void; error: (error: Error) => void; } export interface IQrwcEvents { update: (component: Component, control: Control, state: Control['state']) => void; error: (event: Error) => void; disconnected: (reason: string) => void; reconnected: () => void; engineStatus: (status: IEngineStatus) => void; } export interface IConnectionEvents { message: (raw: string) => void; error: (error: Error) => void; disconnected: (reason: string) => void; reconnected: () => void; closed: (reason: string) => void; engineStatus: (status: IEngineStatus) => void; } export interface IQrcClientEvents { message: (message: unknown) => void; error: (error: Error) => void; disconnected: (reason: string) => void; reconnected: () => void; closed: (reason: string) => void; engineStatus: (status: IEngineStatus) => void; } export interface IConnection extends IEventEmitter { send: (data: string) => void; close: () => void; readonly engineStatus: IEngineStatus; } /** * Miscellaneous Types * Not sure where to put these :) */ export type Prettify = { [K in keyof T]: T[K]; } & {}; export type IComponentState = Readonly & { Controls: Readonly; }>; export type IControlState = Readonly & { Bool: boolean; }>; export type IWebSocket = WebSocket | WsWebSocket; export interface IReconnectOptions { maxAttempts?: number; delay?: number; maxDelay?: number; backoffFactor?: number; } interface IStartOptionsBase { apiKey?: string; pollingInterval?: number; componentFilter?: (componentState: IComponentGetComponentsResult) => boolean; timeout?: number; logger?: Partial; } export interface IUnmanagedStartOptions extends IStartOptionsBase { socket: IWebSocket; host?: never; } export interface IManagedStartOptions extends IStartOptionsBase { host: string; dispatcher?: unknown; reconnect?: IReconnectOptions; socket?: never; } export type IStartOptions = IUnmanagedStartOptions | IManagedStartOptions; export type ILogger = Pick; export interface IControlGenericParameter { state: IControlState; } export interface IComponentGenericParameter { controls: Record; } export interface IQrwcExpandedGenericParameter { components: Record; } /** * The simplified generic parameter format: a map of component name to a union * of that component's control names. * e.g. { Gain: 'gain' | 'mute', Gain_1: 'gain' } */ export type IQrwcSimpleGenericParameter = Record; /** * Converts the simplified {@link IQrwcSimpleGenericParameter} format into the detailed * {@link IQrwcExpandedGenericParameter} format, giving every control the generic * IControlState. */ export type ISimpleToExpanded = { components: { [ComponentName in keyof T]: { controls: { [ControlName in Extract]: { state: IControlState; }; }; }; }; }; /** * Accepts either the detailed {@link IQrwcExpandedGenericParameter} format or the * simplified {@link IQrwcSimpleGenericParameter} format, and resolves to the detailed * format used internally. The detailed format is checked first because it is * the more specific of the two shapes. */ export type INormalizedQrwcParameter = T extends IQrwcExpandedGenericParameter ? T : T extends IQrwcSimpleGenericParameter ? ISimpleToExpanded : never; export type ReadOnlyControl = Omit, 'update'>; export {}; //# sourceMappingURL=index.interface.d.ts.map