Signal K JS Client
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
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',
wsKeepaliveInterval: 0
}
client = new Client({
hostname: 'demo.signalk.org',
port: 80,
useTLS: false,
reconnect: true,
autoConnect: false,
})
client = new Client({
hostname: 'demo.signalk.org',
port: 80,
useTLS: false,
rejectUnauthorized: false,
useAuthentication: true,
reconnect: true,
autoConnect: false,
username: 'demo@signalk.org',
password: 'signalk',
})
const bonjour = Bonjour()
const discovery = new Discovery(bonjour, 60000)
discovery.on('timeout', () => console.log('No SK servers found'))
discovery.on('found', (server) => {
if (server.isMain() && server.isMaster()) {
client = server.createClient({
useTLS: false,
useAuthentication: true,
reconnect: true,
autoConnect: true,
notifications: false,
username: 'sdk@decipher.industries',
password: 'signalk',
})
}
})
client = new Client({
hostname: 'demo.signalk.org',
port: 80,
useTLS: false,
reconnect: true,
autoConnect: false,
notifications: false,
deltaStreamBehaviour: 'self',
sendMeta: 'all',
wsKeepaliveInterval: 10
})
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',
},
],
},
],
})
client.on('delta', (delta) => {
})
client.subscribe([
{
context: 'vessels.*',
subscribe: [
{
path: 'navigation.position',
policy: 'instant',
},
],
},
])
client.unsubscribe()
client
.API()
.then((api) => api.navigation())
.then((navigationGroupResult) => {
})
client
.API()
.then((api) => api.get('/vessels/self/navigation/position'))
.then((positionResult) => {
})
client
.API()
.then((api) => api.getMeta('vessels.self.navigation.position'))
.then((positionMetaResult) => {
})
client
.API()
.then((api) => api.self())
.then((selfResult) => {
})
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)