@signalk/streams 5.1.1 → 5.1.4

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
@@ -114,8 +114,11 @@ Splitter.prototype._transform = function (msg, encoding, _done) {
114
114
  try {
115
115
  const parsed = JSON.parse(msg.data)
116
116
  const timestamp = new Date(Number(msg.timestamp))
117
- parsed.updates &&
118
- parsed.updates.forEach((update) => (update.timestamp = timestamp))
117
+ if (parsed.updates) {
118
+ parsed.updates.forEach((update) => {
119
+ update.timestamp = timestamp
120
+ })
121
+ }
119
122
  this.push(parsed)
120
123
  this.demuxEmitData(parsed)
121
124
  } catch (e) {
package/n2k-signalk.js CHANGED
@@ -71,7 +71,7 @@ function ToSignalK(options) {
71
71
  })
72
72
 
73
73
  this.n2kMapper.on('n2kSourceMetadataTimeout', (pgn, src) => {
74
- if (pgn == 60928) {
74
+ if (Number(pgn) === 60928) {
75
75
  console.warn(`n2k-signalk: unable to detect can name for src ${src}`)
76
76
  this.sourceMeta[src].unknowCanName = true
77
77
  }
@@ -101,8 +101,10 @@ ToSignalK.prototype.isFiltered = function (source) {
101
101
  return (
102
102
  (!filter.source ||
103
103
  filter.source.length === 0 ||
104
- filter.source == sFilter) &&
105
- (!filter.pgn || filter.pgn.length === 0 || filter.pgn == source.pgn)
104
+ filter.source === sFilter) &&
105
+ (!filter.pgn ||
106
+ filter.pgn.length === 0 ||
107
+ String(filter.pgn) === String(source.pgn))
106
108
  )
107
109
  })
108
110
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalk/streams",
3
- "version": "5.1.1",
3
+ "version": "5.1.4",
4
4
  "description": "Utilities for handling streams of Signal K data",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/serialport.js CHANGED
@@ -82,13 +82,52 @@ function SerialStream(options) {
82
82
 
83
83
  const createDebug = options.createDebug || require('debug')
84
84
  this.debug = createDebug('signalk:streams:serialport')
85
+
86
+ let pendingWrites = 0
87
+ const stdOutEvents = isArray(this.options.toStdout)
88
+ ? this.options.toStdout
89
+ : [this.options.toStdout]
90
+ const standardOutEventName = `serial-${this.options.providerId}-toStdout`
91
+ stdOutEvents.push(standardOutEventName)
92
+
93
+ const that = this
94
+ stdOutEvents.forEach((event) => {
95
+ const onDrain = () => {
96
+ pendingWrites--
97
+ }
98
+
99
+ that.options.app.on(event, (d) => {
100
+ if (pendingWrites > that.maxPendingWrites) {
101
+ that.debug('Buffer overflow, not writing:' + d)
102
+ return
103
+ }
104
+ that.debug('Writing:' + d)
105
+ if (isBuffer(d)) {
106
+ that.serial.write(d)
107
+ } else {
108
+ that.serial.write(d + '\r\n')
109
+ }
110
+ setImmediate(() => {
111
+ that.options.app.emit('connectionwrite', {
112
+ providerId: that.options.providerId
113
+ })
114
+ })
115
+ pendingWrites++
116
+ that.serial.drain(onDrain)
117
+ })
118
+ })
119
+
120
+ this.options.app.emitPropertyValue('serialport', {
121
+ id: this.options.providerId,
122
+ eventNames: {
123
+ toStdout: standardOutEventName
124
+ }
125
+ })
85
126
  }
86
127
 
87
128
  require('util').inherits(SerialStream, Transform)
88
129
 
89
130
  SerialStream.prototype.start = function () {
90
- const that = this
91
-
92
131
  if (this.serial !== null) {
93
132
  this.serial.unpipe(this)
94
133
  this.serial.removeAllListeners()
@@ -146,36 +185,6 @@ SerialStream.prototype.start = function () {
146
185
  this.scheduleReconnect()
147
186
  }.bind(this)
148
187
  )
149
-
150
- let pendingWrites = 0
151
- const stdOutEvent = this.options.toStdout
152
- if (stdOutEvent) {
153
- ;(isArray(stdOutEvent) ? stdOutEvent : [stdOutEvent]).forEach((event) => {
154
- const onDrain = () => {
155
- pendingWrites--
156
- }
157
-
158
- that.options.app.on(event, (d) => {
159
- if (pendingWrites > that.maxPendingWrites) {
160
- that.debug('Buffer overflow, not writing:' + d)
161
- return
162
- }
163
- that.debug('Writing:' + d)
164
- if (isBuffer(d)) {
165
- that.serial.write(d)
166
- } else {
167
- that.serial.write(d + '\r\n')
168
- }
169
- setImmediate(() => {
170
- that.options.app.emit('connectionwrite', {
171
- providerId: that.options.providerId
172
- })
173
- })
174
- pendingWrites++
175
- that.serial.drain(onDrain)
176
- })
177
- })
178
- }
179
188
  }
180
189
 
181
190
  SerialStream.prototype.end = function () {
package/simple.js CHANGED
@@ -97,6 +97,7 @@ function Simple(options) {
97
97
  const dataReceivedEventName = `${options.subOptions.providerId}-received`
98
98
 
99
99
  const spy = new Transform({
100
+ objectMode: true,
100
101
  transform(chunk, encoding, callback) {
101
102
  options.app.emit(dataReceivedEventName, chunk)
102
103
  callback(null, chunk)
@@ -119,7 +120,9 @@ function Simple(options) {
119
120
  transform(delta, encoding, callback) {
120
121
  if (delta.updates) {
121
122
  const now = new Date().toISOString()
122
- delta.updates.forEach((update) => (update.timestamp = now))
123
+ delta.updates.forEach((update) => {
124
+ update.timestamp = now
125
+ })
123
126
  }
124
127
  callback(null, delta)
125
128
  }