UNPKG

ive-connect

Version:

A universal haptic device control library for interactive experiences

182 lines (181 loc) 5.48 kB
/** * Handy Device Implementation */ import { DeviceCapability, DeviceInfo, DeviceScriptLoadResult, Funscript, HapticDevice } from "../../core/device-interface"; import { EventEmitter } from "../../core/events"; import { HandyApi } from "./handy-api"; import { HandySettings, HspState, HspPoint } from "./types"; /** * Handy configuration options */ export interface HandyConfig { connectionKey?: string; baseV3Url?: string; baseV2Url?: string; applicationId?: string; } /** * Handy device implementation */ export declare class HandyDevice extends EventEmitter implements HapticDevice { private _api; private _config; private _connectionState; private _deviceInfo; private _isPlaying; private _eventSource; private _scriptPrepared; private _hspState; private _hspStreamIndex; readonly id: string; readonly name: string; readonly type: string; readonly capabilities: DeviceCapability[]; /** * Create a new Handy device instance * @param config Optional configuration */ constructor(config?: HandyConfig); /** * Get the API instance for direct access */ get api(): HandyApi; /** * Get device connection state */ get isConnected(): boolean; /** * Get device playback state */ get isPlaying(): boolean; /** * Get current HSP state */ get hspState(): HspState | null; /** * Connect to the device * @param config Optional configuration override */ connect(config?: Partial<HandySettings>): Promise<boolean>; /** * Disconnect from the device */ disconnect(): Promise<boolean>; /** * Get current device configuration */ getConfig(): HandySettings; /** * Update device configuration * @param config Partial configuration to update */ updateConfig(config: Partial<HandySettings>): Promise<boolean>; /** * Prepare a script for playback (upload to Handy server) * The funscript is already parsed - we just need to upload it * * @param funscript The parsed funscript content * @param _options Script options (inversion already applied by DeviceManager) */ prepareScript(funscript: Funscript): Promise<DeviceScriptLoadResult>; /** * Play the loaded script at the specified time (HSSP) * @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 (works for both HSSP and HSP) */ stop(): Promise<boolean>; /** * Synchronize device time with provided time * @param timeMs Current time in milliseconds */ syncTime(timeMs: number, filter?: number): Promise<boolean>; /** * Get device-specific information */ getDeviceInfo(): DeviceInfo | null; /** * Initialize a new HSP session. * This clears any existing session state and prepares the device for streaming. * @param streamId Optional custom stream ID */ hspSetup(streamId?: number): Promise<HspState | null>; /** * Get the current HSP state from the device */ hspGetState(): Promise<HspState | null>; /** * Add points to the HSP buffer. * Points are {t, x} where: * - t: timestamp in ms relative to start (t=0) * - x: position 0-100 (0=bottom, 100=top) * * @param points Array of points to add (max 100 per call) * @param flush If true, clear buffer before adding */ hspAddPoints(points: HspPoint[], flush?: boolean): Promise<HspState | null>; /** * Start HSP playback * @param startTime Time to start from (in ms, relative to points) * @param options Playback options */ hspPlay(startTime?: number, options?: { playbackRate?: number; pauseOnStarving?: boolean; loop?: boolean; }): Promise<HspState | null>; /** * Stop HSP playback */ hspStop(): Promise<HspState | null>; /** * Pause HSP playback */ hspPause(): Promise<HspState | null>; /** * Resume HSP playback * @param pickUp If true, resumes from current live position. If false, from paused position. */ hspResume(pickUp?: boolean): Promise<HspState | null>; /** * Flush the HSP buffer (remove all points) */ hspFlush(): Promise<HspState | null>; /** * Set HSP loop mode */ hspSetLoop(loop: boolean): Promise<HspState | null>; /** * Set HSP playback rate */ hspSetPlaybackRate(rate: number): Promise<HspState | null>; /** * Sync HSP time with external source */ hspSyncTime(currentTime: number, filter?: number): Promise<HspState | null>; /** * Set pause-on-starving flag * When enabled, device clock pauses when buffer runs out and resumes when points are added */ hspSetPauseOnStarving(pause: boolean): Promise<HspState | null>; /** * Get the current stream index for tracking */ getHspStreamIndex(): number; /** * Reset the stream index (call after hspSetup) */ resetHspStreamIndex(): void; /** * Set up event handlers for the device */ private _setupEventHandlers; /** * Load device settings after connection */ private _loadDeviceSettings; }