UNPKG

@fibercom/routeros-api

Version:

Robust MikroTik RouterOS API client for Node.js and TypeScript

51 lines (50 loc) 1.57 kB
import { EventEmitter } from "events"; import { Connector } from "./connector/Connector"; import { IRosGenericResponse } from "./IRosGenericResponse"; /** * Channel class is responsible for issuing commands with a unique tag, * and receiving corresponding replies via the RouterOS API. It listens for * specific reply types such as !re, !done, and !trap. */ export declare class Channel extends EventEmitter { private id; private connector; private data; private trapped; private streaming; constructor(connector: Connector); /** * Get the unique ID assigned to this channel. */ get Id(): string; /** * Get the underlying connector used by this channel. */ get Connector(): Connector; /** * Write a command to the RouterOS device with this channel's tag. * Always returns a promise that resolves/rejects on done/trap. */ write(params: string[], isStream?: boolean, returnPromise?: boolean): Promise<IRosGenericResponse[]>; /** * Close the channel and stop reading its tag. * Optionally force cleanup of event listeners. */ close(force?: boolean): void; /** * Bind a tag reader and issue the command. */ private readAndWrite; /** * Parse incoming replies and emit appropriate events. */ private processPacket; /** * Convert an array of lines like '=key=value' into an object. */ private parsePacket; /** * Handler for unexpected replies—emits and throws an error. */ private onUnknown; }