lifxlan
Version:
TypeScript library for controlling LIFX products over LAN
54 lines • 2.35 kB
TypeScript
import type { RouterInstance, MessageHandler, Header } from './router.js';
import type { Device } from './devices.js';
import type { Command } from './commands/index.js';
declare const RESPONSE_MODES: readonly ["auto", "ack-only", "response", "both"];
export type ResponseMode = typeof RESPONSE_MODES[number];
type SendReturnType<T, A extends ResponseMode | undefined> = A extends 'ack-only' ? Promise<void> : A extends 'response' | 'both' | 'auto' ? Promise<T> : Promise<T>;
export interface SendOptions<A extends ResponseMode = ResponseMode> {
/**
* Controls response behavior for the command.
*
* Available options:
* - 'auto': Use the command's default behavior (recommended)
* - 'ack-only': Wait for acknowledgment packet (confirms receipt)
* - 'response': Wait for response data packet (Get commands)
* - 'both': Wait for both ack and response (maximum reliability)
*/
responseMode?: A;
signal?: AbortSignal;
}
export interface ClientOptions {
router: RouterInstance;
defaultTimeoutMs?: number;
source?: number;
onMessage?: MessageHandler;
}
export interface ClientInstance {
readonly router: RouterInstance;
readonly source: number;
dispose(): void;
broadcast<T>(command: Command<T>): void;
unicast<T>(command: Command<T>, device: Device): void;
send<T>(command: Command<T>, device: Device): Promise<T>;
send<T, A extends ResponseMode>(command: Command<T>, device: Device, options: SendOptions<A>): SendReturnType<T, A>;
onMessage(header: Header, payload: Uint8Array, serialNumber: string): void;
}
/**
* Creates a high-level client for communicating with LIFX devices.
*
* The Client provides methods for sending commands to devices with automatic
* timeout handling, retry logic, and response correlation. It uses the Router
* for message routing and supports both acknowledged and unacknowledged messaging patterns.
*
* @param options Configuration options
* @returns A new client instance
* @example
* ```javascript
* const client = Client({ router });
* const response = await client.send(GetColorCommand(), device);
* ```
* @performance Optimized for high-throughput scenarios with minimal allocations
*/
export declare function Client(options: ClientOptions): ClientInstance;
export {};
//# sourceMappingURL=client.d.ts.map