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

@hms-networks/kolibri-js-client

v2.0.4

Published

Kolibri Consumer API client for building kolibri based applications

Downloads

144

Readme

npm version

Kolibri-JS-Client

The Kolibri-JS-Client is an easy to use Kolibri Consumer API client. It allows to interact with a Kolibri Broker with a simple request / response model with additional event driven data functionalities. The client is written in TypeScript and can also be used with JavaScript.

Supported Kolibri Versions

Currently supported Kolibri Consumer Protocol Versions:

  • v3.2

Features

The Kolibri-JS-Client abstracts most of the Kolibri Protocol internals from the application and provides some additional / convenient features.

  • Promise-based Request/Response API for the Kolibri Consumer Protocol over WebSockets.
  • Event Listener support for receiving events and live data from the Kolibri Broker.
  • Client side data merging for the kolibri.subscribe and kolibri.write live data.
  • Client side Kolibri QoS Level and transaction handling
  • Auto reconnect on connection loss
  • NodeJS and Browser support
  • Support for TLS
  • Support for Kolibri-RPC
  • Support for HTTP/HTTPS Proxy
  • Fully typed

Install

NPM

npm install @hms-networks/kolibri-js-client

Yarn

yarn add @hms-networks/kolibri-js-client

Node and Browser Support

The client currently supports Browser Single Page applications and NodeJS environments.

HTML Apps can import the minimized bundle from the location build/bundles/kolibri-js-client.umd.min.js

<script src="./build/bundles/kolibri-js-client.umd.min.js"></script>

Getting Started

To be able to call kolibri RPCs the client has to be created with some configuration first. With the client object created you can then call Kolibri Consumer RPCs to the configured Kolibri Broker.

import { ClientConfig, KolibriClientFactory } from '@hms-networks/kolibri-js-client';

// create config
const config: ClientConfig = {
     host: 'ws://localhost:8080',
     project: 'testv21',
     path: '/'
};
const client = KolibriClientFactory.create(config);

await client.connect();
// RPC calls...
await client.disconnect();

Proxy Settings

Setting a proxy is only supported on Node environment. Proxy settings are ignored on the Browser.

import { ClientConfig, KolibriClientFactory } from '@hms-networks/kolibri-js-client';

const config: ClientConfig = {
     host: 'ws://localhost:8080',
     project: 'testv21',
     path: '/',
     proxy: {
         host: 'localhost',
         port: 8089
     }
};

const client = KolibriClientFactory.create(config);

TLS Connection

Custom TLS Configuration is only available on Node environment. On Browsers the config is ignored.

Tls connection with default options can be established by just providing host url with the wss:// protocol. If you want to configure the connection you can provide the optional tls config parameter to the ClientFactory.create method. For more details about the TlsConfig see https://nodejs.org/api/https.html#https_https_request_options_callback

import { ClientConfig, KolibriClientFactory } from '@hms-networks/kolibri-js-client';

const config: ClientConfig = {
     host: 'ws://localhost:8080',
     project: 'testv21',
     path: '/',
     tls: {
        rejectUnauthorized: false
    }
};

const client = KolibriClientFactory.create(config);

Samples Projects

The /sample directory contains examples how to setup and use some common scenarios.

Sending RPCs

The client uses the request / response model to communicate with the Kolibri Broker. To send a kolibri RPC request call the desired function with the correct params object.

const params: LoginParams = {
      user: 'Username',
      password: 'Password',
      interval: 60,
      timeout: 5
};
const result = await client.login(params);

Event Listeners

Some kolibri RPCs trigger the Kolibri Broker to send data to the client. For that purpose the client is able to register event listeners to handle incoming data from the broker.

client.addOnWriteListener((nodes: any[]) => {
 console.log(nodes);
});

const params: SubscribeParams = [
     { path: '/device01/temperatures/room1' }
];
const result = await client.subscribe(params);

After the registration of the addOnWriteListener and the client.subscribe RPC the Kolibri Broker will send data to the client. The client will then call the registered function with the data as the parameter. See Kolibri Consumer API Specification for more details.

Error Handling

All the errors returned from the Kolibri Broker are instances of subclasses to the KolibriRequestError class containing the reason and additional data (if available).

const params: LoginParams = {
      user: 'Invalid Username',
      password: 'Password',
      interval: 60,
      timeout: 5
};
try{
    const result = await client.login(params);
}
catch(e){
    if(e instanceof AccessDeniedError){
        console.log(e.message);
    }
}