Skip to content

Commit 89a1dd0

Browse files
authored
Merge pull request #18 from kushan-chinthaka/fb_issue17
Two fixes: propagate errors from recognizeStream to whatever stream is returned to the user, and only send data on open websockets Fixes #17 Fixes #10
2 parents 01e74d5 + 9d3efef commit 89a1dd0

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

speech-to-text/recognize-microphone.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ module.exports = function recognizeMicrophone(options) {
141141

142142
}).catch(recognizeStream.emit.bind(recognizeStream, 'error'));
143143

144+
/**
145+
* Propagate error to new FormatStream
146+
*
147+
* @param {String} error message
148+
*/
149+
function handleError(error) {
150+
stream.emit('error', error);
151+
}
152+
153+
// Capture error from original RecognizeStream
154+
recognizeStream.on('error', handleError);
144155

145156
return stream;
146157
};

speech-to-text/recognize-stream.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ RecognizeStream.prototype.finish = function finish() {
404404
this.finished = true;
405405
var self = this;
406406
var closingMessage = {action: 'stop'};
407-
if (self.socket && self.socket.readyState !== self.socket.CLOSED && self.socket.readyState !== self.socket.CLOSING) {
407+
if (self.socket && self.socket.readyState === self.socket.OPEN) {
408408
self.sendJSON(closingMessage);
409409
} else {
410410
this.once('connect', function() {

0 commit comments

Comments
 (0)