Giter Club home page Giter Club logo

jsxapi's People

Contributors

bjornars avatar dependabot[bot] avatar myme avatar torkildr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsxapi's Issues

SSH Keepalive should be set

In the jsxapi library the ssh keep alive by default is turned off. This is the default of the ssh2 library used by jsxapi. While this is not a big problem if your endpoint goes down gracefully, it is if it suddenly loses network connectivity. Basically your ssh session will just hang as might your nodejs application. If the endpoint comes back on a different ip address for what ever reason your ssh session will never recover meaning having to restart your application to recover your connection. The solution how ever is actual very simple. Just add the keepaliveInterval attribute to the connect object and your good to go. This enables ssh keepalives (in milliseconds). Just ensure you use an integer not a string for the timer. This will then generate a event error at disconnect allowing you to recover your ssh session how ever you see fit.

const xapi = jsxapi.connect('ssh://host.example.com', {
username: 'admin',
password: 'password',
keepaliveInterval: 4000
});

Dependency problems attempting to build docs

Ubuntu 22.04
node 16.14.2
jsxapi 5.1.1

Attempting to npm install from node_modules/jsxapi:

npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: @types/[email protected]
npm ERR! node_modules/@types/jest
npm ERR!   dev @types/jest@"^26.0.24" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peerOptional @types/jest@"^27.0.0" from [email protected]
npm ERR! node_modules/ts-jest
npm ERR!   dev ts-jest@"^27.0.7" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: @types/[email protected]
npm ERR! node_modules/@types/jest
npm ERR!   peerOptional @types/jest@"^27.0.0" from [email protected]
npm ERR!   node_modules/ts-jest
npm ERR!     dev ts-jest@"^27.0.7" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 
npm ERR! See /home/dstaudt/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/dstaudt/.npm/_logs/2022-08-03T19_45_11_981Z-debug-0.log

Using npm install --force seems to work ok as a workaround.

Mentioned log file attached.

2022-08-03T19_45_11_981Z-debug-0.log

"xapi.on('ready', ...)" should emit with the `XAPI` instance

This should be possible:

const jsxapi = require('jsxapi');
const xapi = new Promise((resolve, reject) => {
  jsxapi
    .connect('somehost', { /* ... */ })
    .on('error', reject)
    .on('ready', resolve);
});

Right now you'd have to catch a reference to the xapi instance inside the Promise creator function and pass a lambda to the "ready" handler: .on('ready', () => { resolve(xapi); });

jsxapi needs better error handling for websockets

  • Errors don't contain useful error codes (e.g. I want to see error 1015 for TLS errors)
  • When disconnecting due to navigation, it logs an error to the console.
  • When a connection error occurs, I get two calls to my error handler.

Uncaught ReferenceError: Buffer is not defined

Trying to use this as an ES6 import like this:

import * as XAPI from 'jsxapi';

And when I go to use it:

    let jsxapi = XAPI;
    this.deviceConnection = jsxapi.connect(`wss://${this.deviceIP}`, {
      username: this.deviceAdminUsername,
      password: this.deviceAdminPassword
    })
    .on('error', console.error)
    .on('ready', async (xapi:any)=>{
      console.log("WE'VE CONNECTED!")
      xapi.close();
    })

I get the following error:

Uncaught ReferenceError: Buffer is not defined
    at generateAuthSubProto (ws.js:1:493)
    at websocketConnect (ws.js:1:922)
    at initBackend (browser.js:1:1069)
    at Object.eval [as connect] (connect.js:1:1861)
    at Index.connectToDevice (index.js:47:1)
    at EmberCuiButton.clickHandler (ember-cui-button.js:185:1)

Any suggestions?

Connection terminated remotely

Hey Guys, i'm having a trouble while i'm doing an UI update.

i have a panel that i'm updating with new products list, but when its larger than 3 products this error shows up 'Connection terminated remotely'

do you guys have an idea how can i handle that ? i'm new working with cisco devices.

i'm not on vpn, im doing that local

i have this code as example

const jsxapi = require('jsxapi');
jsxapi
    .connect('ssh://roomkitip', {
        username: 'user',
        password: 'password'
    }).on('error', async (error) => {
        console.log(error)
    }).on('ready', async (xapi) => {

        let products= [{
            codigo: 'agua',
            nome: 'Water',
        }, {
            codigo: 'cafe',
            nome: 'Coffee',
        }, {
            codigo: 'cha',
            nome: 'Tea',
        }, {
            codigo: 'suco',
            nome: 'Juice',
        }, {
            codigo: 'coca',
            nome: 'Coke',
        },];

        xapi.command('UserInterface Extensions Panel Save', { PanelId: 'concierge' },
            `<Extensions>
                <Version>1.1</Version>
                <Name>Concierge</Name>
                <Panel>
                    <Icon>Concierge</Icon>
                    <Color>#FF3D67</Color>
                    <Name>Concierge</Name>
                    <Type>Statusbar</Type>
                    <Page>
                        <Name>Concierge</Name>
                        ${ produtos.map(el => {
                return `<Row>
                                    <Name>${el.nome}</Name>
                                    <Widget>
                                    <WidgetId>${el.codigo}</WidgetId>
                                    <Type>Spinner</Type>
                                    <Options>style=plusminus</Options>
                                    </Widget>
                                </Row>`}).join('')}
                    </Page>
                </Panel>
            </Extensions>`).then(res => {
                    console.log('result => ', res)
                }).catch(err => {
                    console.log('erro => ', err)

                });
    });

Feedback registration should return a promise

Registering a feedback expression must return a promise which is resolved when the registration (read: command) is successful. There are scenarios where it's important to know if the feedback expression is registered before continuing issuing commands. This requires a breaking API change, as the current API returns a cancellation handler function.

One possibility to retain backwards compatibility is to attach a promise to the returned function:

  on(path, listener) {
    log.info(`new feedback listener on: ${path}`);
    const eventPath = normalizePath(path)
      .join('/')
      .toLowerCase();

    this.eventEmitter.on(eventPath, listener);

    const registration = this.xapi.execute('xFeedback/Subscribe', {
      Query: normalizePath(path),
    });

    const off = () => {
      registration.then(({ Id }) => {
        this.xapi.execute('xFeedback/Unsubscribe', { Id });
      });

      this.eventEmitter.removeListener(eventPath, listener);
    };

    off.registration = registration;
    // ^-- Add registration Promise to returned function
    return off;
}

Create browser bundle in dist/

Create a browser-friendly bundle which is part of the release package, suitable for CDNs like unpkg. The browser bundle supports only the WebSocket protocol. Include both a regular and a minified version.

Is there a way to turn off ssl validation on web socket?

I know WebSocket in general supports it, but does jsxapi provide a means to do it.

From what I can tell looking at the code, it doesn't appear to let us disable cert check?

Though, the most straightforward way to add that option is not obvious to me.

XAPI instances aren't sealed by default when passing additional options to constructor

When creating an XAPI instance without passing additional options the constructor defaults to sealing the object (making the instance less mutable by not allowing new properties and changes to existing properties). However, when passing unrelated options in a second argument to the XAPI constructor the seal option isn't properly defaulted to true, and so instances aren't sealed.

Sealing should be opt-out, always.

Reconnect support

It would be nice to have reconnect ability built into the library somewhere.

This would remove the need to have

xapi
    .on('close', () => {})
    .on('error', (error) => {});

with reconnect logic in client code.

Today, to have reconnect ability, you will have to have event listeners on close and error, which will create a new xapi object, and re-register all feedbacks.

UncaughtException Client Socket

In cases where an endpoint is offline but the script is still running it generates a client socket uncaught exception. This is using SSH to long term monitor events from an endpoint. Error is below.

2018-09-04T17:28:19.330Z error: Error [ERR_UNHANDLED_ERROR]: Unhandled error. (client-socket)
at XAPI.emit (events.js:171:17)
at TSHBackend. (/Users/christno/WebstormProjects/walmartApp/node_modules/jsxapi/lib/xapi/index.js:126:13)
at TSHBackend.emit (events.js:182:13)
at DuplexPassThrough. (/Users/christno/WebstormProjects/walmartApp/node_modules/jsxapi/lib/backend/tsh.js:106:20)
at DuplexPassThrough.emit (events.js:182:13)
at Client. (/Users/christno/WebstormProjects/walmartApp/node_modules/jsxapi/lib/transport/ssh.js:106:15)
at Client.emit (events.js:182:13)
at Socket. (/Users/christno/WebstormProjects/walmartApp/node_modules/ssh2/lib/client.js:299:10)
at Socket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)

Add a way to get valuespaces

For introspection purposes and also because different devices may have slightly different values possible for the same command, being able to get the valuespaces would be really awesome.

Add configuration/staus binding/subscription method

xconfiguration and xstatus trigger feedback on changes, but they are also non-transient and can be fetched at any time. A very nice convenience method would be to allow binding a callback to configs and statuses which is invoked with the initial value, as well as being called back on changes.

Possible names are .bind() or .subscribe(). "Subscribe" might be a better fit, as "bind" implies more of an end-to-end data binding between elements.

Requirements:

  • Feedback APIs must be changed to return a Promise which resolves on successful registration.
  • Add a "Subscribable" interface which is mixed into Config and Status.
  • Subscribable has a .subscribe() method which first registers feedback, then fetches the value.
  • To avoid races, the feedback registration promise must be resolved before the callback is invoked with the current value, from then on, the callback is invoked on all feedback.
  • Feedback which arrives before the fetched value is returned, should be queued to avoid data races.

Change error handling to make it harder to end up with uncaught errors

Today, it is possible to end up with a case where, because of delayed execution, the error emitter is assigned after some of the error-emitting code has started to execute.

Example of delayed emitter assignment

const xapi = jsxapi.connect('ssh://localhost:99');
Promise.resolve(() => {
  xapi.on('error', (err) => {
    console.error(`xapi error: ${err}`);
  });
});

Though this example is a bit contrived, it is easy to picture a more organic scenario where the code is "synchronous" ish, but is triggered in an asynchronous manner, thus not being executed before any other async logic.

We should investigate the possibility of moving the error emitter assignment so that it is possible to do before doing the initial commit.

An example, though not the final design, of such a solution, might be something like:

import Jsxapi from 'jsxapi';

const jsxapi = new Jsxapi();

jsxapi.on('error', err => console.log(err));
jsxapi.connect('ssh://localhost:99')

rpc.createSetResponse() does not handle invalid paths

Doesn't look like there is any test for createSetResponse (while there are some for createCommandResponse or createGetResponse).

While working no a feature in vega I noticed that xapi.config.set('BLAH Audio Output ConnectorSetup', 'Manual) resolves while it should have rejected.

Fix array dispatching

For arrays, both the entire array and individual nodes within the array are dispatched. This leads to listeners being fired multiple times and is confusing.

xapi.config.on('Audio Input Microphone', console.log);

yields:

{ id: '1', Mode: 'Off' } { Configuration: { Audio: { Input: [Object] } } }
[ { id: '1', Mode: 'Off' } ] { Configuration: { Audio: { Input: [Object] } } }

Upgrade dependencies

Dependencies have been rotting away. Need to update them to remove security vulnerabilities and to keep the repo maintanable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.