Code Monkey home page Code Monkey logo

js-client's Introduction

happypandax-client for javascript

A javascript client library for communicating with HappyPanda X servers

Note: This is a nodejs module and not meant to run in a browser!

Version>=3.0.0 of this library only supports HPX version >=1.0.0, please use version<3.0.0 of this library for HPX <=0.13

Installing

Install and update with npm or yarn

$ yarn add happypandax-client

Example

Get up and running fast:

import Client from "happypandax-client";

const c = new Client({ name: "my-client" });
c.connect({ host: "localhost", port: 7007 }).then(function (msg) {
  c.handshake({ user: null, password: null })
    .then(function (success) {
      if (success) {
        c.send([{ fname: "get_version" }]).then(function (data) {
          console.log(data);
        });
      } else {
        console.error("Handshake failed")
      }
    })
    .finally(() => c.close());
});

or, using Async/Await syntax:

import Client from "happypandax-client";

let c = new Client({ name: "my-client" });

async function main() {
  const msg = await c.connect({ host: "localhost", port: 7007 });
  const success = await c.handshake({ user: null, password: null });

  if (success) {
    let data = await c.send([{ fname: "get_version" }]);
    console.log(data);
  } else {
    console.error("Handshake failed");
  }

  c.close();
}

main();

API

See Docs

Logging

import { log } from "happypandax-client";

// Enable/disable logging
log.enabled = false;

// Custom logger
log.logger = {
  debug: console.debug,
  info: console.info,
  warning: console.warn,
  error: console.error,
};

Behaviour

Due to a change in NodeJS v17, localhost might now return a IPV6 address, however the client will always prefer the IPv4 address. To restore to NodeJS behaviour, set Client.resolve_IPV4_localhost = false;

js-client's People

Contributors

dependabot[bot] avatar twiddli avatar

Watchers

 avatar  avatar

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.