@fibercom/routeros-api
Version:
Robust MikroTik RouterOS API client for Node.js and TypeScript
70 lines (69 loc) • 2.56 kB
TypeScript
import { TlsOptions } from "tls";
import { IRosOptions } from "./IRosOptions";
import { RStream } from "./RStream";
import { EventEmitter } from "events";
import { IRosGenericResponse } from "./IRosGenericResponse";
/**
* Creates a connection object with the credentials provided
*/
export declare class RouterOSAPI extends EventEmitter {
/** Host to connect */
host: string;
/** Username to use */
user: string;
/** Password of the username */
password: string;
/** Port of the API */
port: number;
/** Timeout of the connection */
timeout: number;
/** TLS Options to use, if any */
tls: TlsOptions;
/** Debug mode enabled */
debug: boolean;
/** Connected flag */
connected: boolean;
/** Connecting flag */
connecting: boolean;
/** Closing flag */
closing: boolean;
/** Keep connection alive */
keepalive: boolean;
private connector;
private keptaliveby;
private channelsOpen;
private holdingConnectionWithKeepalive;
private connectionHoldInterval;
private registeredStreams;
constructor(options: IRosOptions);
setOptions(options: IRosOptions): void;
private initializeDebuggers;
/**
* Attempts to connect to the RouterOS device with retry logic.
*
* This method wraps the `.connect()` method and retries the connection
* multiple times if it fails, waiting a specified delay between each attempt.
*
* @param attempts - Maximum number of connection attempts (default: 3)
* @param delay - Delay (in ms) between retries (default: 1000 ms)
* @returns A Promise resolving to the Connector instance upon successful connection
* @throws The last encountered error if all retry attempts fail
*/
connectWithRetry(attempts?: number, delay?: number): Promise<RouterOSAPI>;
connect(): Promise<RouterOSAPI>;
write(params: string | string[], ...moreParams: Array<string | string[]>): Promise<IRosGenericResponse[]>;
writeStream(params: string | string[], ...moreParams: Array<string | string[]>): RStream;
stream(params?: string | string[], ...moreParams: any[]): RStream;
keepaliveBy(params?: string | string[], ...moreParams: any[]): void;
close(): Promise<RouterOSAPI>;
private openChannel;
private increaseChannelsOpen;
private decreaseChannelsOpen;
private registerStream;
private unregisterStream;
private stopAllStreams;
private holdConnection;
private releaseConnectionHold;
private login;
private concatParams;
}