Noteworthy Programming Masterpiece
Miss any of our Open RFC calls?Watch the recordings here! »

This package has been deprecated

Author message:

Please use @signalk/client

@signalk/signalk-client

0.1.0 • Public • Published

Signal K JavaScript Client Library

Installation

$ npm install signalk-client

Mdns is an optional dependency for doing automatic discovery. It is not relevant in browser environment, but Browserify will fail if you don't ignore or exclude it explicitly as in --exclude mdns. For Webpack you can declare it as an external.

Usage

var SignalKClient = require('@signalk/signalk-client').Client;
var signalk = new SignalKClient;
var connection;

var thisCallback = function(msg) {
  $.each(listenerList, function(i, obj) {
    obj.onmessage(msg, connection);
  });
};

function connectDelta(host, thisCallback, onConnect, onDisconnect) {
  debug("Connecting to " + host);

  // try mdns
  connection = signalk.discoverAndConnect();
  if(connection) {
    return;
  }

  console.log("Could not use mdns, falling back to " + host);

  connection = signalk.connectDelta(host, thisCallback,
    function(skConnection) {
      skConnection.subscribeAll();
      onConnect();
    },

    function(skConnection) {
      skConnection.close();
      debug('Disconnected');
    },

    function(error) {
      console.log(error)
    },

    'self'
  );
}

Install

npm i @signalk/signalk-client

DownloadsWeekly Downloads

1

Version

0.1.0

License

Apache-2.0

Last publish

Collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar