Skip to content

Commit 8fc5bac

Browse files
committed
emit parsed json (if any) with message events
1 parent b278e2f commit 8fc5bac

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

speech-to-text/recognize-stream.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,6 @@ RecognizeStream.prototype.initialize = function() {
266266
}
267267

268268
socket.onmessage = function(frame) {
269-
/**
270-
* Emit any messages received over the wire, mainly used for debugging.
271-
*
272-
* @event RecognizeStream#message
273-
* @param {Object} message - frame object with a data attribute that's either a string or a Buffer/TypedArray
274-
*/
275-
self.emit('message', frame);
276269

277270
if (typeof frame.data !== 'string') {
278271
return emitError('Unexpected binary data received from server', frame);
@@ -285,6 +278,15 @@ RecognizeStream.prototype.initialize = function() {
285278
return emitError('Invalid JSON received from service:', frame, jsonEx);
286279
}
287280

281+
/**
282+
* Emit any messages received over the wire, mainly used for debugging.
283+
*
284+
* @event RecognizeStream#message
285+
* @param {Object} message - frame object with a data attribute that's either a string or a Buffer/TypedArray
286+
* @param {Object} [data] - parsed JSON object (if possible);
287+
*/
288+
self.emit('message', frame, data);
289+
288290
if (data.error) {
289291
emitError(data.error, frame);
290292
} else if (data.state === 'listening') {

0 commit comments

Comments
 (0)