How to use @signalk/client - 4 common examples

To help you get started, we’ve selected a few @signalk/client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SignalK / instrumentpanel / lib / ui / instrumentpanel.js View on Github external
var useTLS = window.location.protocol === 'https:'
  var host = window.location.hostname;
  var port = parseInt(window.location.port);
  if (!Number.isInteger(port)) {
    port = (useTLS) ? 443 : 80;
  }
  const signalkServer = getUrlParameter("signalkServer");
  if (typeof signalkServer !== 'undefined') {
    useTLS = signalkServer.startsWith('wss://');
    host = signalkServer.split(':')[1].replace(/\//g, '');
    port = parseInt(signalkServer.split(':')[2]);
    if (!Number.isInteger(port)) {
      port = (useTLS) ? 443 : 80;
    }
  }
  this.SignalkClient = new Client({
    hostname: host,
    port: port,
    useTLS: useTLS,
    reconnect: true,
    autoConnect: false,
    notifications: false,
    maxRetries: 10
  });
  this.loadPreferredUnits();
}
github vokkim / tuktuk-chart-plotter / src / client / provider-signalk.js View on Github external
subscribe: [{path: '*', period: 10000}]
    })
    console.log(`SignalK connected to ${parseAddress(address)}`)
  }
  const onDisconnect = c => {
    c && c.close && c.close()
    rawStream.end()
    connectionStateBus.push('disconnected')
    console.log('SignalK disconnected')
  }
  const onError = e => {
    rawStream.push(new Bacon.Error(e))
    onDisconnect()
  }

  const signalk = new SignalK.Client()
  signalk.connectDelta(parseAddress(address), onMessage, onConnect, onDisconnect, onError, onDisconnect, 'none')
  const selfStream = rawStream.filter(msg => isSelf(msg.context))

  const updates = selfStream.map(msg => {
    return _(msg.updates)
      .map(u =>
        _.map(u.values, v => {
          return {
            timestamp: u.timestamp,
            path: v.path,
            value: v.value
          }
        })
      )
      .flatten()
      .value()
github SignalK / signalk-server-node / packages / streams / mdns-ws.js View on Github external
MdnsWs.prototype.connect = function (discovery) {
  if (this.remoteServers[discovery.host + ':' + discovery.port]) {
    debug(
      'Discovered ' +
        discovery.host +
        ':' +
        discovery.port +
        ' already known, not connecting'
    )
    return
  }
  const signalkClient = new SignalK.Client()
  let url
  if (discovery.discoveryResponse) {
    _object.values(discovery.discoveryResponse.endpoints)[0]['signalk-ws']
  } else {
    const protocol = discovery.protocol || 'ws'
    url =
      protocol +
      '://' +
      discovery.host +
      ':' +
      discovery.port +
      '/signalk/v1/stream?subscribe=all'
  }
  const that = this

  const providerId = `${that.options.providerId}.${discovery.host}:${
github SignalK / signalk-server-node / packages / streams / mdns-ws.js View on Github external
objectMode: true
  })
  this.options = options
  this.selfHost = options.app.config.getExternalHostname() + '.'
  this.selfPort = options.app.config.getExternalPort()
  this.remoteServers = {}
  this.remoteServers[this.selfHost + ':' + this.selfPort] = {}
  if (options.ignoreServers) {
    options.ignoreServers.forEach(s => {
      this.remoteServers[s] = {}
    })
  }
  if (options.host && options.port) {
    this.connect(options)
  } else {
    this.signalkClient = new SignalK.Client()
    this.signalkClient.on('discovery', this.connect.bind(this))
    this.signalkClient.on('discoveryError', info => {
      const providerId = `${options.providerId}.${info.host}:${info.port}`
      options.app.setProviderError(providerId, info.error.message)
    })
    debug('Starting discovery')
    this.signalkClient.startDiscovery()
  }
}

@signalk/client

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)

Apache-2.0
Latest version published 2 years ago

Package Health Score

49 / 100
Full package analysis

Popular @signalk/client functions