import { RouterOSAPI , IRosOptions , RosException } from "node-routeros" ; import { RosApiMenu } from "./RosApiMenu" ; import { EventEmitter } from "events" ; export class RouterOSClient extends EventEmitter { /**
     * Options of the connection
     */ private options : IRosOptions ; /**
     * The raw API which this class wraps around
     */ private rosApi : RouterOSAPI ; param options constructor ( options ) { super ( ) ; this . options = options ; this . rosApi = new RouterOSAPI ( this . options ) ; } /**
     * If it is connected or not
     */ public isConnected ( ) { return this . rosApi . connected ; } /**
     * Connects to the routerboard with the options provided
     */ public connect ( ) { const api = this . api ( ) ; if ( this . rosApi . connected ) return Promise . resolve ( api ) ; return this . rosApi . connect ( ) . then ( ( ) => { this . emit ( "connected" , api ) ; this . rosApi . once ( "error" , ( err ) => this . emit ( "error" , err ) ) ; this . rosApi . once ( "close" , ( ) => this . emit ( "close" ) ) ; return Promise . resolve ( api ) ; } ) . catch ( ( err ) => { this . emit ( "error" , err ) ; return Promise . reject ( err ) ; } ) ; } param options public setOptions ( options ) { Object . assign ( this . options , options ) ; this . rosApi . setOptions ( this . options ) ; return this ; } /**
     * Get an instance of the API to handle operations
     */ public api ( ) { return new RosApiMenu ( this . rosApi ) ; } /**
     * Disconnect from the routerboard
     */ public disconnect ( ) { return this . rosApi . close ( ) . then ( ( api ) => { this . emit ( "disconnected" , this ) ; return Promise . resolve ( this ) ; } ) . catch ( ( err ) => { return Promise . reject ( err ) ; } ) ; } /**
     * Alias to disconnect
     */ public close ( ) { return this . disconnect ( ) ; } /**
     * Alias to disconnect
     */ public end ( ) { return this . disconnect ( ) ; } /**
     * Return the options provided
     */ public getOptions ( ) { return this . options ; } }