Signal K JS SDK
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).
INSTALLATION
This is not yet published on Github. If you'd like to use an early version, use the following command to install the SDK in your project:
[sudo] npm install --save @signalk/client
BASIC USAGE
import Client, { Discovery } from '@signalk/signalk-js-sdk'
import mdns from 'mdns'
let client = null
client = new Client({
hostname: 'demo.signalk.org',
port: 80,
useTLS: true,
reconnect: true,
autoConnect: false
})
client = new Client({
hostname: 'hq.decipher.digital',
port: 3000,
useTLS: true,
useAuthentication: true,
reconnect: true,
autoConnect: false,
username: 'sdk@decipher.industries',
password: 'signalk'
})
const discovery = new Discovery(mdns, 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,
username: 'sdk@decipher.industries',
password: 'signalk'
})
}
})
const subscription = {
context: 'vessels.self',
subscribe: [{ path: 'navigation.position' }]
}
client
.connect()
.then(() => client.subscribe(subscription))
.catch(err => done(err))
client.on('delta', delta => {
})
client
.connect()
.then(() => client.subscribe())
.catch(err => done(err))
client.on('delta', delta => {
})
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
PRE-1.0 RELEASE CHECKLIST
FUTURE RELEASES
NOTES
- mDNS advert should advertise if server supports TLS
PUT requests via REST
have been implemented, but don't have a valid test yet. Need to figure out how to test this- 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)
Security is implemented, but the token type is currently hardcoded to JWT
if no token.type
is returned by a SK server. IMHO that default should be Bearer
. See issue https://github.com/SignalK/signalk-server-node/issues/715 & PR https://github.com/SignalK/specification/pull/535