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

@bluenav/signalk-client

v2.1.8

Published

A Javascript SDK for Signal K clients. Provides various abstract interfaces for discovering (via optional mDNS) the Signal K server and communication via WebSocket & REST. Aims to implement all major APIs in the most recent Signal K version(s)

Downloads

4

Readme

Signal K JS Client

Build Status

A Javascript SDK for Signal K clients. Provides various abstract interfaces for discovering the Signal K server and communication via WebSocket & REST. Aims to implement all major APIs in the most recent Signal K version(s).

INSTALLATION

[sudo] npm install --save @signalk/client

BASIC USAGE

import Client, { Discovery } from '@signalk/client'
import Bonjour from 'bonjour'

let client = null

// Default options for instantiating a client:
const defaults = {
  hostname: 'localhost',
  port: 3000,
  useTLS: true,
  useAuthentication: false,
  notifications: true,
  autoConnect: false,
  reconnect: true,
  maxRetries: Infinity,
  maxTimeBetweenRetries: 2500,
  username: null,
  password: null,
  deltaStreamBehaviour: 'none',
}

// Instantiate client
client = new Client({
  hostname: 'demo.signalk.org',
  port: 80,
  useTLS: false,
  reconnect: true,
  autoConnect: false,
})

// Instantiate client with authentication
client = new Client({
  hostname: 'demo.signalk.org',
  port: 80,
  useTLS: false,
  rejectUnauthorized: false, // Optional, set to false only if the server has a self-signed certificate
  useAuthentication: true,
  reconnect: true,
  autoConnect: false,
  username: '[email protected]',
  password: 'signalk',
})

// Discover client using mDNS
// Params: bonjour lib, search time
const bonjour = Bonjour()
const discovery = new Discovery(bonjour, 60000)

// Timeout fires when search time is up and no servers were found
discovery.on('timeout', () => console.log('No SK servers found'))

// Found fires when a SK server was found
discovery.on('found', (server) => {
  if (server.isMain() && server.isMaster()) {
    client = server.createClient({
      useTLS: false,
      useAuthentication: true,
      reconnect: true,
      autoConnect: true,
      notifications: false,
      username: '[email protected]',
      password: 'signalk',
    })
  }
})

// Delta Stream over WS usage
// 1. Stream behaviour selection
client = new Client({
  hostname: 'demo.signalk.org',
  port: 80,
  useTLS: false,
  reconnect: true,
  autoConnect: false,
  notifications: false,
  // Either "self", "all", "none", or null (see below)
  // - null: no behaviour is set for the delta stream, default behaviour is used. Use this option when connecting to older devices that don't support the subscription modifiers per query request. See https://signalk.org/specification/1.4.0/doc/subscription_protocol.html.
  // - "self" provides a stream of all local data of own vessel
  // - "all" provides a stream of all data for all vessels
  // - "none" provides no data over the stream
  deltaStreamBehaviour: 'self',
})

// 2. Subscribe to specific Signal K paths
client = new Client({
  hostname: 'demo.signalk.org',
  port: 80,
  useTLS: false,
  reconnect: true,
  autoConnect: false,
  notifications: false,
  subscriptions: [
    {
      context: 'vessels.*',
      subscribe: [
        {
          path: 'navigation.position',
          policy: 'instant',
        },
      ],
    },
  ],
})

// 3. Listen to the "delta" event to get the stream data
client.on('delta', (delta) => {
  // do something with delta
})

// 4. Modify your subscription parameters. Can be a single object or an array.
client.subscribe([
  {
    context: 'vessels.*',
    subscribe: [
      {
        path: 'navigation.position',
        policy: 'instant',
      },
    ],
  },
])

// 5. Unsubscribe from all data paths.
client.unsubscribe()

// REST API usage
// 1. Fetch an entire group
client
  .API() // create REST API client
  .then((api) => api.navigation())
  .then((navigationGroupResult) => {
    // Do something with navigation group data
  })

// 2. Fetch a specific path
client
  .API() // create REST API client
  .then((api) => api.get('/vessels/self/navigation/position')) // Path can be specified using dotnotation and slashes
  .then((positionResult) => {
    // Do something with position data
  })

// 3. Fetch meta for a specific path
client
  .API() // create REST API client
  .then((api) => api.getMeta('vessels.self.navigation.position'))
  .then((positionMetaResult) => {
    // Do something with position meta data
  })

// 4. Fetch the entire tree for the local vessel
client
  .API() // create REST API client
  .then((api) => api.self())
  .then((selfResult) => {
    // Do something with boat data
  })

// ... check out the tests for more REST API examples

Other Signal K Clients:

Angular: Signal K client for the Angular framework signalk-client-angular

NOTES

  • Node SK server responds with "Request updated" for access request responses. This is incorrect per spec
  • Node SK server paths for access requests repsponses are not correct to spec (i.e. no /signalk/v1 prefix)