Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

signalk-client-angular

panaaj119Apache-202.0.3TypeScript support: included

Signal K client library for Angular.

angular, signal k, signalk-client, signalk-client-angular

readme

Signal K client for the Angular Framework

Note: This library was generated with Angular CLI version 12.0.0.

SignalKClient is an Angular library to facilitate communication with a Signal K server.

It provides the following classes to interact with Signal K HTTP and STREAM APIs as well as exposing STREAM Events:

  • api class for interacting with Signal K HTTP API

  • stream class for interacting with Signal K STREAM API

  • apps class to enable interaction with applications installed on the Signal K server


NOTE: To connect to a Signal K stream using a web worker use the signalk-worker-angular library in conjunction with this library.

npm i signalk-worker-angular

Breaking Changes:

From the release of version 1.7.0 the following methods now return an Observable.

  • connect()
  • connectStream()
  • connectPlayback()

To continue using Promises update your code to use the following methods:

  • connectAsPromise()
  • connectStreamAsPromise()
  • connectPlaybackAsPromise()

See below for some Examples below to see how to use this library..

Detailed documentation for using this library can be found on GitHub.

Installation

npm install signalk-client-angular

Usage

app.module.ts

  • Include SignalKClientModule in your project.
 import { SignalKClientModule } from 'signalk-client-angular';

app.component.ts

  • Inject SignalKClient into your application.
import { SignalKClient } from 'signalk-client-angular';

// **** Inject the SignalKClient ****

constructor( public sk: SignalKClient ) {
    ...
}

Basic Usage

The simplest way to get started is to connect to a Signal K server and open a websocket to its data stream.

To do this:

  1. Use connectStream(...) to connect to the server and open the data stream.

  2. Subscribe to the stream events to process the received data

Example:

// **** Subscribe to Signal K Stream events ***

this.sk.stream.onConnect.subscribe( e=> {
    ...handle connection event
});
this.sk.stream.onError.subscribe( e=> {
    ...handle error event
});
this.sk.stream.onClose.subscribe( e=> {
    ...handle connection closed event
});
this.sk.stream.onMessage.subscribe( e=> {
    ...handle message received event
});    

// **** CONNECT to Server and open STREAM ****
this.sk.connectStream('192.168.99.100', 80, false, 'self');

Once connected you can then interact with both the STREAM and HTTP APIs in the following ways:

  • Use the stream object to interact with the websocket connection.
    // **** send data to STREAM API ****
    this.sk.stream.send({..data..});    
  • Use the api object to interact Signal K HTTP API path. /signalk/v1/api/

Example:

// **** make HTTP API request ****
this.sk.api.get('vessels/self/navigation/position').subscribe(
    response=> { ... },
    error=> { ... }
);

Connect and open Stream on Demand

If you want to just use the HTTP API or defer the connection to the STREAM API based on user interaction use the connect(..) method.

  1. Use connect(...) to connect to the server and perform endpoint discovery.

  2. When you are ready to connect to the STREAM API use openStream() ( or stream.open() ) with a null or undefined url parameter. This will cnnect to the discovered stream endpoint.

Example:

// **** Subscribe to Signal K Stream events ***

this.sk.stream.onConnect.subscribe( e=> {
    ...handle connection event
});
this.sk.stream.onError.subscribe( e=> {
    ...handle error event
});
this.sk.stream.onClose.subscribe( e=> {
    ...handle connection closed event
});
this.sk.stream.onMessage.subscribe( e=> {
    ...handle message received event
});    

// **** CONNECT to Signal K Server ****
this.sk.connect('192.168.99.100', 80, false, 'self');

... 

this.sk.openStream( null, 'self');

OR

this.sk.stream.open( null, 'self');

Use with non-HTTP enabled Signal K server

By default the connect methods will cause an HTTP request to be sent to the server /signalk path to discover the server's advertised endpoints.

To interact with the server without using endpoint discovery use the openStream(<hostname>, <port>) method specifying the host ip address and port.

Note: No HTTP endpoint discovery is performed when using openXX() methods and specifying a host.

Example:

// **** Subscribe to Signal K Stream events ***

this.sk.stream.onConnect.subscribe( e=> {
    ...handle connection event
});
this.sk.stream.onError.subscribe( e=> {
    ...handle error event
});
this.sk.stream.onClose.subscribe( e=> {
    ...handle connection closed event
});
this.sk.stream.onMessage.subscribe( e=> {
    ...handle message received event
});    

// **** CONNECT to Signal K Server ****
this.sk.openStream('192.168.99.100', 80, false, 'self');

changelog

CHANGELOG: signalk-client-angular

v2.0.0

  • Added proxied attribute. When set to true ignores the endpoint protocol, host & port returned in the hello message and uses the values passed to the connection. Useful when Signal K server accessed via a proxy.

  • Added api.observeResponse attribute which when set to true results in the entire HTTP response being available for api.post(), api.put() and api.delete() rather than just the response.body. (Default is false).

Breaking Changes:

  • Changed uuid() function to return a string containing the UUID value and not a UUID object.

  • Added signalkUuid() function to return a Signal K v1 UUID string.

  • Removed patch for working around the issue when using PUT to update resources. Note: This library now requires a version of Signal K server that implements the Resources API.

  • Removed support for legacy Signal K server path /webapps.

v1.8.0

  • Updated to support Angular Ivy.

  • Added API raiseAlarm() and clearAlarm() methods.

  • Updated STREAM raiseAlarm() and clearAlarm() methods to use PUT.

v1.7.0

  • Add support for storing client data on the server via the applicationData path.

  • Add isLoggedin() method to query if a user is authenticated on the server.

Breaking Changes:

The following methods now return an Observable rather than a Promise.

  • connect()
  • connectStream()
  • connectPlayback()

To continue using Promises update your code to use the following methods:

  • connectAsPromise()
  • connectStreamAsPromise()
  • connectPlaybackAsPromise()

v1.6.0

  • Removed worker object. Use signalk-worker-angular to interact with Signal K stream via a web worker.

  • Update apps to work with signalk-node-server (v1.24.0 or higher) support for the app API.

v1.5.4

  • Add apps object to provide inital support for proposed API for installed applications on SignalK server.

v1.5.3

  • Add support for using stream object in Angular Web Worker.

Note: The worker object will be deprecated in future releases.

v1.5.2

  • Fix url parameter processing issue.

v1.5.1

  • Added stream.sendRequest() method.

  • Added stream.login() method.

  • Signal K Resources: The following methods have been added/updated to align with proposed resources section of the specification.

    • Added api.post() method for use with resource creation.

    • Added api.delete() method for removing resources.

    • updated api.put() to ensure the resource uuid is part of the path.

    • Added api.put(path, value) overload definition.

v1.5.0

This version represents a significant refactoring of SignalKClient to better align it with recent enhancements to the Signal K specification. It contains MANY BREAKING CHANGES so please review the README before upgrading!

It introduces the new classes to interact with Signal K API's:

api: class for interacting with Signal K HTTP API endpoint path

stream: class for interacting with Signal K STREAM API endpoint path

It also provides a worker class as a wrapper for WebWorker scripts to enable moving Signal K data processing off the main thread.

v1.4.1

  • updated to align with updated security specification.

v1.4.0

  • add support for History Playback api via playback(), connectPlayback() and snapshot() methods
  • added isConnected property

v1.3.5

  • bug fixes: corrects issue where secure connection to web socket endpoint was using ws:// rather than wss://

v1.3.4

  • bug fixes

v1.3.3

  • bug fixes

v1.3.2

  • added overloaded apiPut() method apiPut(context, path, value)

v1.3.0

  • added put() and post() to enable these actions to urls outside the /signalk/v1/api/ scope.

v1.2.0

  • added Alarm functionality raiseAlarm(), clearAlarm().

  • added ability to see if Signal K server has security enabled via theauthRequired attribute.

  • get list of supported api versions by server via the apiVersions attribute.

v1.1.0

  • added connectionTimeout attribute.

  • added sendUpdate() function to enable updates to be sent to Delta Stream.

  • added support for Authentication via authtoken attribute and login() function.

v1.0.1

  • connectDelta() function added to allow connection to servers that do not reply with an HTTP discovery response detailing service endpoints.

BREAKING CHANGES:

  • version attribute is now a number not a string.

v1.0.0

Initial Release