Skip to content

Commit a26383f

Browse files
committed
Remove debug console.log
1 parent f43c3a3 commit a26383f

File tree

1 file changed

+48
-38
lines changed
  • services/speech_to_text

1 file changed

+48
-38
lines changed

services/speech_to_text/v1.js

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -355,29 +355,12 @@ module.exports = function (RED) {
355355
return p;
356356
}
357357

358-
// If we are going to connect to STT through websockets then its going to
359-
// disconnect or timeout, so need to handle that occurrence.
360-
function connectIfNeeded() {
361-
console.log('re-establishing the connect');
362-
websocket = null;
363-
socketCreationInProcess = false;
364-
365-
366-
// The token may have expired so test for it.
367-
getToken(determineService())
368-
.then(() => {
369-
return processSTTSocketStart(false);
370-
})
371-
.then(() => {
372-
//return Promise.resolve();
373-
return;
374-
})
375-
.catch((err) => {
376-
//return Promise.resolve();
377-
return;
378-
});
379-
}
380358

359+
// This function generates a load of listeners, that if resolving or
360+
// rejecting promises causes problems, as nothing is waiting on those
361+
// promises. I had wanted to pause and socket activity until the 'open'
362+
// event, which was ok initially, but on subsequent socket close / Error
363+
// reopens caused problems.
381364
function processSTTSocketStart(initialConnect) {
382365
var p = new Promise(function resolver(resolve, reject) {
383366
var model = config.lang + '_' + config.band;
@@ -404,44 +387,71 @@ module.exports = function (RED) {
404387

405388
ws.on('message', (data) => {
406389
// First message will be 'state': 'listening'
407-
console.log('-----------------------');
408-
console.log('Data Received from Input');
409-
console.log(data);
390+
// console.log('-----------------------');
391+
// console.log('Data Received from Input');
392+
// console.log(data);
410393
var d = JSON.parse(data);
411394
var newMsg = {payload : JSON.parse(data)};
412-
node.send(newMsg);
413-
if (d && d.state && 'listening' === d.state){
414-
socketListening = true;
415-
resolve();
395+
if (d) {
396+
if (d.error) {
397+
// Force Expiry of Token, as that is the only Error
398+
// response from the service that we have seen.
399+
token = null;
400+
getToken(determineService())
401+
.then(() => {
402+
return;
403+
});
404+
} else if (d && d.state && 'listening' === d.state) {
405+
socketListening = true;
406+
//resolve();
407+
} else {
408+
node.send(newMsg);
409+
}
416410
}
417411
});
418412

419413
ws.on('close', () => {
420-
//if (websocket) {
421-
// websocket.close();
422-
//}
423414
websocket = null;
424415
socketListening = false;
425-
console.log('STT Socket disconnected');
416+
// console.log('STT Socket disconnected');
426417
setTimeout(connectIfNeeded, 1000);
427418
});
428419

429420
ws.on('error', (err) => {
430421
socketListening = false;
431-
console.log('Error Detected');
422+
// console.log('Error Detected');
432423
if (initialConnect) {
433-
reject(err);
424+
//reject(err);
434425
}
435426
});
436427

437-
} else {
438-
resolve();
439428
}
440-
429+
resolve();
441430
});
442431
return p;
443432
}
444433

434+
// If we are going to connect to STT through websockets then its going to
435+
// disconnect or timeout, so need to handle that occurrence.
436+
function connectIfNeeded() {
437+
// console.log('re-establishing the connect');
438+
websocket = null;
439+
socketCreationInProcess = false;
440+
441+
// The token may have expired so test for it.
442+
getToken(determineService())
443+
.then(() => {
444+
return processSTTSocketStart(false);
445+
})
446+
.then(() => {
447+
//return Promise.resolve();
448+
return;
449+
})
450+
.catch((err) => {
451+
//return Promise.resolve();
452+
return;
453+
});
454+
}
445455

446456
// While we are waiting for a connection, stack the data input
447457
// so it can be processed, when the connection becomes available.

0 commit comments

Comments
 (0)