@signalk/streams 5.1.0 → 5.1.1

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/serialport.js +24 -34
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signalk/streams",
3
- "version": "5.1.0",
3
+ "version": "5.1.1",
4
4
  "description": "Utilities for handling streams of Signal K data",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/serialport.js CHANGED
@@ -148,44 +148,34 @@ SerialStream.prototype.start = function () {
148
148
  )
149
149
 
150
150
  let pendingWrites = 0
151
- const stdOutEvents = isArray(this.options.toStdout)
152
- ? this.options.toStdout
153
- : [this.options.toStdout]
154
- const standardOutEventName = `serial-${this.options.subOptions.providerId}-toStdout`
155
- stdOutEvents.push(standardOutEventName)
156
-
157
- stdOutEvents.forEach((event) => {
158
- const onDrain = () => {
159
- pendingWrites--
160
- }
161
-
162
- that.options.app.on(event, (d) => {
163
- if (pendingWrites > that.maxPendingWrites) {
164
- that.debug('Buffer overflow, not writing:' + d)
165
- return
151
+ const stdOutEvent = this.options.toStdout
152
+ if (stdOutEvent) {
153
+ ;(isArray(stdOutEvent) ? stdOutEvent : [stdOutEvent]).forEach((event) => {
154
+ const onDrain = () => {
155
+ pendingWrites--
166
156
  }
167
- that.debug('Writing:' + d)
168
- if (isBuffer(d)) {
169
- that.serial.write(d)
170
- } else {
171
- that.serial.write(d + '\r\n')
172
- }
173
- setImmediate(() => {
174
- that.options.app.emit('connectionwrite', {
175
- providerId: that.options.providerId
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
+ })
176
173
  })
174
+ pendingWrites++
175
+ that.serial.drain(onDrain)
177
176
  })
178
- pendingWrites++
179
- that.serial.drain(onDrain)
180
177
  })
181
- })
182
-
183
- this.options.app.emitPropertyValue('serialport', {
184
- id: this.options.providerId,
185
- eventNames: {
186
- toStdout: standardOutEventName
187
- }
188
- })
178
+ }
189
179
  }
190
180
 
191
181
  SerialStream.prototype.end = function () {