ive-connect
Version:
A universal haptic device control library for interactive experiences
132 lines (131 loc) • 3.15 kB
TypeScript
/**
* Core interfaces for haptic devices
*/
/**
* The connection state of a device
*/
export declare enum ConnectionState {
DISCONNECTED = "disconnected",
CONNECTING = "connecting",
CONNECTED = "connected"
}
/**
* Common device capabilities
*/
export declare enum DeviceCapability {
VIBRATE = "vibrate",
ROTATE = "rotate",
LINEAR = "linear",
STROKE = "stroke"
}
/**
* Generic device information
*/
export interface DeviceInfo {
id: string;
name: string;
type: string;
firmware?: string;
hardware?: string;
[key: string]: any;
}
/**
* Device settings interface
* Base interface for device-specific settings
*/
export interface DeviceSettings {
id: string;
name: string;
enabled: boolean;
[key: string]: any;
}
/**
* Script data interface
*/
export interface ScriptData {
type: string;
url?: string;
content?: any;
}
/**
* Script options interface
*/
export type ScriptOptions = {
invertScript?: boolean;
};
/**
* Common interface for all haptic devices
*/
export interface HapticDevice {
/**
* Device information
*/
readonly id: string;
readonly name: string;
readonly type: string;
readonly capabilities: DeviceCapability[];
/**
* Connection state
*/
readonly isConnected: boolean;
readonly isPlaying: boolean;
/**
* Connect to the device
* @param config Optional configuration
*/
connect(config?: any): Promise<boolean>;
/**
* Disconnect from the device
*/
disconnect(): Promise<boolean>;
/**
* Get current device configuration
*/
getConfig(): DeviceSettings;
/**
* Update device configuration
* @param config Partial configuration to update
*/
updateConfig(config: Partial<DeviceSettings>): Promise<boolean>;
/**
* Load a script for playback
* @param scriptData Script data to load
*/
loadScript(scriptData: ScriptData, options?: ScriptOptions): Promise<{
success: boolean;
scriptContent?: ScriptData;
}>;
/**
* Play the loaded script at the specified time
* @param timeMs Current time in milliseconds
* @param playbackRate Playback rate (1.0 = normal speed)
* @param loop Whether to loop the script
*/
play(timeMs: number, playbackRate?: number, loop?: boolean): Promise<boolean>;
/**
* Stop playback
*/
stop(): Promise<boolean>;
/**
* Synchronize device time with provided time
* @param timeMs Current time in milliseconds
* @param filter Time filter for synchronization
*/
syncTime(timeMs: number, filter?: number): Promise<boolean>;
/**
* Get device-specific information
*/
getDeviceInfo(): DeviceInfo | null;
/**
* Add event listener
* @param event Event name
* @param callback Callback function
*/
on(event: string, callback: (data: any) => void): void;
/**
* Remove event listener
* @param event Event name
* @param callback Callback function
*/
off(event: string, callback: (data: any) => void): void;
}