npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ks-client

v3.1.4

Published

nodejs client for Kaltiot Smart IoT SDK

Downloads

8

Readme

ks-client

API

All the functions that accept a callback also return promises. So you can use the library in the usual callback style or promise style, whichever you prefer.

Requires C gateway version >= 1.0.18 or JS gateway version >= 2.0.0.

Example

var KSClient = require("ks-client");
var constants = KSClient.constants;
var client = new KSClient;

var path = "/tmp/ks_gw_socket";

// this is equivalent to...
client.connect(path, function(err) {
  if (err) {
    // handle error
    return;
  }

  // handle success
});

// ...this
client.connect(path).then(function () {
  // handle success
}).catch(function (err) {
  // handle error
});

new KSClient

Creates a new client object.

The client is an EventEmitter and it emits the following events.

Event: ipc-disconnected

Fired when the IPC gets disconnected. You will need to call #connect again after this.

Event: state

Fired when the state of the gateway changes.

Field | Type | Description ------|------|------------ state | int | Represents the state of the client. One of the network state constants from constants.md. error | int | Possible error code. One of the error constants from constants.md.

Event: notification

Fired when a notification is received.

Field | Type | Description ------|------|------------ address | string | Alphanumeric string. payloadType | string | Type of payload. One of: "BINARY", "INT", "STRING", "PING", "PONG". payload | int, Buffer or string | 32 bit integer when payloadType is "INT", Buffer when "BINARY", string otherwise.

Event: rid

Fired when your application receives its RID.

Field | Type | Description ------|------|------------ address | string | Alphanumeric string. rid | string | The RID received. secret | string | The secret of that RID.

Event: gateway-rid

Fired when the gateway receives its RIDs.

Field | Type | Description ------|------|------------ rid | string | The gateway RID.

#connect(path, [callback])

Connect to a socket in the given address or path. For example, /tmp/ks_gw_socket or localhost:12345.

#disconnect([callback])

Disconnects an established connection, if any.

#register(address, version, customerId, channels, [callback])

Registers with the daemon. App will start receiving notifications and other events.

NOTE: If you need to update the channels, you have to first unregister nd then register again, with the different channels.

Argument | Type | Description ---------|------|------------ address | string | Alphanumeric string. version | string | Alphanumeric string. customerId | string | Your customer ID. Alphanumeric. channels | Array | Array of strings describing the channels you wish to subscribe to.

#unregister(address, version, customerId, [callback])

Unregisters from the daemon.

Argument | Type | Description ---------|------|------------ address | string | Alphanumeric string. version | string | Alphanumeric string. customerId | string | Your customer ID. Alphanumeric.

#publish(payloadType, payload, [tag], [callback])

Publishes a message to the server.

Argument | Type | Description ---------|------|------------ payloadType | string | Type of payload. One of: "BINARY", "INT", "STRING", "PING", "PONG". payload | int, Buffer or string | 32 bit integer when payloadType is "INT", Buffer when "BINARY", string otherwise. tag | string | SRIKY WHAT WAS THIS AGAIN?

#requestState([callback])

Request the state from the daemon. This will cause the state event to be emitted. The callback is run when the request has been written.

#requestRid([callback])

Request your rid from the daemon. This will cause the rid event to be emitted. The callback is run when the request has been written.

#requestAppId([callback])

Request the application ID from the daemon. Callback will be called with the application ID.

#setNetworkAvailable(opts, [callback])

Set the availability of the network. opts is an object of the following format:

{
  state: constants.NETWORK_STATE_MOBILE_2G, // one of the network state constants
  mcc: "555", // optional, use with mobile networks
  mnc: "66", // optional, use with mobile networks
}

mcc and mnc are used for optimization of the connection. If they change, you should update the state.

#setEngineEnabled(enabled, [callback])

Enable or disable the gateway.

Argument | Type | Description ---------|------|------------ enabled | boolean |

#setOrganizationSecret(secret, [callback])

Set the organization secret. This will only have an effect if it is called on an empty database before any applications have been registered.

Argument | Type | Description ---------|------|------------ secret | string |

Example use

A complete example that works similarly to the C SDK's sample_publish can be found in src/lib/example.js.