@signalk/streams 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/autodetect.js CHANGED
@@ -113,6 +113,9 @@ Splitter.prototype._transform = function (msg, encoding, _done) {
113
113
  default:
114
114
  try {
115
115
  const parsed = JSON.parse(msg.data)
116
+ const timestamp = new Date(Number(msg.timestamp))
117
+ parsed.updates &&
118
+ parsed.updates.forEach((update) => (update.timestamp = timestamp))
116
119
  this.push(parsed)
117
120
  this.demuxEmitData(parsed)
118
121
  } catch (e) {
@@ -137,10 +140,12 @@ function ToTimestamped(deMultiplexer, options) {
137
140
  }
138
141
  require('util').inherits(ToTimestamped, Transform)
139
142
 
143
+ // runs only once, self-assigns the actual transform functions
144
+ // on first call
140
145
  ToTimestamped.prototype._transform = function (msg, encoding, done) {
141
146
  const line = msg.toString()
142
147
  this.multiplexedFormat =
143
- line.length > 16 && line.charAt(13) === ';' && line.charAt(15) === ';'
148
+ line.length > 16 && line.charAt(13) === ';' && line.split(';').length >= 3
144
149
  if (this.multiplexedFormat) {
145
150
  if (this.options.noThrottle) {
146
151
  this.deMultiplexer.toTimestamped.pipe(this.deMultiplexer.splitter)
@@ -176,7 +181,11 @@ ToTimestamped.prototype.handleMixed = function (msg, encoding, done) {
176
181
  ToTimestamped.prototype.handleMultiplexed = function (msg, encoding, done) {
177
182
  const line = msg.toString()
178
183
  const parts = line.split(';')
179
- this.push({ timestamp: parts[0], discriminator: parts[1], data: parts[2] })
184
+ this.push({
185
+ timestamp: parts[0],
186
+ discriminator: parts[1],
187
+ data: parts.slice(2).join(';'),
188
+ })
180
189
  done()
181
190
  }
182
191
 
package/canboatjs.js CHANGED
@@ -29,10 +29,12 @@ function CanboatJs(options) {
29
29
 
30
30
  this.fromPgn.on('warning', (pgn, warning) => {
31
31
  debug(`[warning] ${pgn.pgn} ${warning}`)
32
+ options.app.emit(`canboatjs:warning`, warning)
32
33
  })
33
34
 
34
35
  this.fromPgn.on('error', (pgn, err) => {
35
36
  console.error(pgn.input, err.message)
37
+ options.app.emit(`canboatjs:error`, err)
36
38
  })
37
39
 
38
40
  this.app = options.app
@@ -48,12 +50,16 @@ CanboatJs.prototype._transform = function (chunk, encoding, done) {
48
50
  pgnData.timestamp = new Date(Number(chunk.timestamp)).toISOString()
49
51
  this.push(pgnData)
50
52
  this.app.emit(this.analyzerOutEvent, pgnData)
53
+ } else {
54
+ this.app.emit('canboatjs:unparsed:object', chunk)
51
55
  }
52
56
  } else {
53
57
  const pgnData = this.fromPgn.parse(chunk)
54
58
  if (pgnData) {
55
59
  this.push(pgnData)
56
60
  this.app.emit(this.analyzerOutEvent, pgnData)
61
+ } else {
62
+ this.app.emit('canboatjs:unparsed:data', chunk)
57
63
  }
58
64
  }
59
65
  done()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalk/streams",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Utilities for handling streams of Signal K data",
5
5
  "main": "index.js",
6
6
  "scripts": {