import { EventEmitter } from "events"; import LruCache from "lru-cache"; import { Song } from "./ns/song.js"; import { Internal } from "./ns/internal.js"; import { Application } from "./ns/application.js"; import { Midi } from "./ns/midi.js"; import { Cache } from "./util/cache.js"; import { Logger } from "./util/logger.js"; import { Session } from "./ns/session.js"; interface Command { uuid: string; ns: string; nsid?: string; name: string; etag?: string; cache?: boolean; args?: { [k: string]: any; }; } type DisconnectEventType = "realtime" | "heartbeat"; type ConnectEventType = DisconnectEventType | "start"; interface EventMap { connect: [ConnectEventType]; disconnect: [DisconnectEventType]; raw_message: [string]; message: [any]; error: [Error]; ping: [number]; } export interface EventListener { prop: string; eventId: string; listener: (data: any) => any; } export declare class TimeoutError extends Error { message: string; payload: Command; constructor(message: string, payload: Command); } export declare class DisconnectError extends Error { message: string; payload: Command; constructor(message: string, payload: Command); } export interface AbletonOptions { /** * Name of the file containing the port of the Remote Script. This * file is expected to be in the OS' tmp directory. * * @default ableton-js-server.port */ serverPortFile?: string; /** * Name of the file containing the port of the client. This file * is created in the OS' tmp directory if it doesn't exist yet. * * @default ableton-js-client.port */ clientPortFile?: string; /** * Defines how regularly ableton-js should ping the Remote Script * to check if it's still reachable, in milliseconds. * * @default 2000 */ heartbeatInterval?: number; /** * Defines how long ableton-js waits for an answer from the Remote * Script after sending a command before throwing a timeout error. * * @default 2000 */ commandTimeoutMs?: number; /** * Defines how long ableton-js waits for an answer from the Remote * Script after sending a command logging a warning about the delay. * * @default 1000 */ commandWarnMs?: number; /** * Options for the response cache. */ cacheOptions?: LruCache.Options; /** * Completely disables the cache. */ disableCache?: boolean; /** * Set this to allow ableton-js to log messages. If you set this to * `console`, log messages are printed to the standard output. */ logger?: Logger; } export declare class Ableton extends EventEmitter { private options?; private client; private msgMap; private timeoutMap; private eventListeners; private heartbeatInterval; private _isConnected; private buffer; private latency; private messageId; private serverPort; cache?: Cache; song: Song; session: Session; application: Application; internal: Internal; midi: Midi; private clientPortFile; private serverPortFile; private logger; private clientState; private cancelDisconnectEvents; constructor(options?: AbletonOptions | undefined); private handleConnect; private handleDisconnect; /** * If connected, returns immediately. Otherwise, * it waits for a connection event before returning. */ waitForConnection(): Promise; /** * Starts the server and waits for a connection with Live to be established. * * @param timeoutMs * If set, the function will throw an error if it can't establish a connection * in the given time. Should be higher than 2000ms to avoid false positives. */ start(timeoutMs?: number): Promise; /** Closes the client */ close(): Promise; /** * Returns the latency between the last command and its response. * This is a rough measurement, so don't rely too much on it. */ getPing(): number; private setPing; private handleIncoming; private handleUncompressedMessage; /** * Sends a raw command to Ableton. Usually, you won't need this. * A good starting point in general is the `song` prop. */ sendCommand(command: Omit): Promise; sendCachedCommand(command: Omit): Promise; getProp(ns: string, nsid: string | undefined, prop: string, cache?: boolean): Promise; setProp(ns: string, nsid: string | undefined, prop: string, value: any): Promise; addPropListener(ns: string, nsid: string | undefined, prop: string, listener: (data: any) => any): Promise<() => Promise>; removePropListener(ns: string, nsid: string | undefined, prop: string, eventId: string, listener: (data: any) => any): Promise; /** * Removes all event listeners that were attached to properties. * This is useful for clearing all listeners when Live * disconnects, for example. */ removeAllPropListeners(): void; sendRaw(msg: string, messageId: number): Promise; isConnected(): boolean; } export * from "./util/package-version.js";