Skip to content

Commit 40d3c2d

Browse files
authored
Merge pull request #2 from watson-developer-cloud/master
Merge latest update
2 parents e7dc230 + 32f72bf commit 40d3c2d

File tree

6 files changed

+125
-42
lines changed

6 files changed

+125
-42
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ Node-RED Watson Nodes for IBM Cloud
77

88
<a href="https://cla-assistant.io/watson-developer-cloud/node-red-node-watson"><img src="https://cla-assistant.io/readme/badge/watson-developer-cloud/node-red-node-watson" alt="CLA assistant" /></a>
99

10+
11+
### New in version 0.6.6
12+
- Added Mute option for STT Node warning status when running in Streaming mode
13+
- Discard option for STT Node Streaming listening events.
14+
- Added Auto-Connect mode for STT Node - Will keep connection to service alive,
15+
else connection is restored on demand.
16+
- Fix to Discovery Query Builder Node to return schema options.
17+
1018
### New in version 0.6.5
1119
- Endpoint can now be specified in Natural Language Classifier Node
1220

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-red-node-watson",
3-
"version": "0.6.5",
3+
"version": "0.6.6",
44
"description": "A collection of Node-RED nodes for IBM Watson services",
55
"dependencies": {
66
"async": "^1.5.2",
@@ -15,7 +15,7 @@
1515
"word-count": "^0.2.2",
1616
"is-docx": "^0.0.3",
1717
"stream-to-array" : "^2.3.0",
18-
"ws" : "^4.0.0"
18+
"ws" : "^4.1.0"
1919
},
2020
"repository": {
2121
"type": "git",

services/discovery/v1-query-builder.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
// can be obtained from the service.
184184
disQB.hideAll = function() {
185185
$('#credentials-not-found').show();
186-
cv1wm.hideSelectedFields(fields);
186+
//disQB.hideSelectedFields(fields);
187187
$('#something-went-wrong').hide();
188188
$('#node-input-environment').parent().hide();
189189
$('#node-input-collection').parent().hide();
@@ -609,7 +609,7 @@
609609

610610

611611
// This is the on edit prepare function, which will be invoked everytime the dialog is shown.
612-
function oneditprepare() {
612+
function disQBoneditprepare() {
613613
disQB.hideAll();
614614
disQB.restoreHidden();
615615

@@ -620,6 +620,7 @@
620620
$('.credentials').toggle(!service);
621621
// for some reason the getJSON resets the vars so need to restoreHidden again
622622
// so again.
623+
disQB.have_credentials = true;
623624
disQB.restoreHidden();
624625
if (!service) {
625626
// no bound service, so check local settings to see if they are valid
@@ -637,7 +638,7 @@
637638
$('#credentials-check').hide();
638639
})
639640
}
640-
// credentials can be set during the oneditprepare process, so check again.
641+
// credentials can be set during the disQBoneditprepare process, so check again.
641642
if (disQB.have_credentials || disQB.using_local_credentials)
642643
{
643644
$('#credentials-check').hide();
@@ -654,7 +655,7 @@
654655
}
655656

656657
// Save the values in the dyanmic lists to the hidden fields.
657-
function oneditsave(){
658+
function disQoneditsave(){
658659
disQB.environment_selected = $('#node-input-environment').val();
659660
$('#node-input-environmenthidden').val(disQB.environment_selected);
660661

@@ -736,8 +737,8 @@
736737
labelStyle: function() {
737738
return this.name ? "node_label_italic" : "";
738739
},
739-
oneditprepare: oneditprepare,
740-
oneditsave: oneditsave
740+
oneditprepare: disQBoneditprepare,
741+
oneditsave: disQoneditsave
741742
});
742743
})();
743744
</script>

services/discovery/v1-query-builder.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,16 @@ module.exports = function(RED) {
4343
username: sUsername ? sUsername : req.query.un,
4444
password: sPassword ? sPassword : req.query.pwd,
4545
url: req.query.endpoint ? req.query.endpoint : sEndpoint,
46-
version_date: '2017-09-01',
46+
version_date: '2017-11-07',
4747
headers: {
4848
'User-Agent': pkg.name + '-' + pkg.version
4949
}
5050
});
5151

52-
console.log('Getting Discovery Environments');
5352
discovery.getEnvironments({}, function(err, response) {
5453
if (err) {
55-
console.log(err);
5654
res.json(err);
5755
} else {
58-
console.log('Returning Envrionments');
5956
res.json(response.environments ? response.environments : response);
6057
}
6158
});
@@ -67,7 +64,7 @@ module.exports = function(RED) {
6764
username: sUsername ? sUsername : req.query.un,
6865
password: sPassword ? sPassword : req.query.pwd,
6966
url: req.query.endpoint ? req.query.endpoint : sEndpoint,
70-
version_date: '2017-09-01',
67+
version_date: '2017-11-07',
7168
headers: {
7269
'User-Agent': pkg.name + '-' + pkg.version
7370
}
@@ -92,7 +89,7 @@ module.exports = function(RED) {
9289
username: sUsername ? sUsername : req.query.un,
9390
password: sPassword ? sPassword : req.query.pwd,
9491
url: req.query.endpoint ? req.query.endpoint : sEndpoint,
95-
version_date: '2017-09-01',
92+
version_date: '2017-11-07',
9693
headers: {
9794
'User-Agent': pkg.name + '-' + pkg.version
9895
}
@@ -101,7 +98,9 @@ module.exports = function(RED) {
10198
discovery.query({
10299
environment_id: req.query.environment_id,
103100
collection_id: req.query.collection_id,
104-
query: 'text:a,text:ibm',
101+
//query: 'text:a,text:ibm',
102+
// Need a Query that will return some data!
103+
query: 'text:"Trump",text:"IBM",text:"Watson"',
105104
count: 1
106105
},
107106
function(err, response) {

services/speech_to_text/v1.html

Lines changed: 77 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@
8888
<label for="node-input-streaming-mode" style="width: 70%;"> Streaming Mode</label>
8989
</div>
9090

91+
<div class="form-row">
92+
<label>&nbsp;</label>
93+
<input type="checkbox" id="node-input-streaming-mute" style="display: inline-block; width: auto; vertical-align: top;">
94+
<label for="node-input-streaming-mute" style="width: 70%;"> Mute in Streaming Mode</label>
95+
</div>
96+
97+
<div class="form-row">
98+
<label>&nbsp;</label>
99+
<input type="checkbox" id="node-input-discard-listening" style="display: inline-block; width: auto; vertical-align: top;">
100+
<label for="node-input-discard-listening" style="width: 70%;"> Discard Listening events from STT</label>
101+
</div>
102+
103+
<div class="form-row">
104+
<label>&nbsp;</label>
105+
<input type="checkbox" id="node-input-auto-connect" style="display: inline-block; width: auto; vertical-align: top;">
106+
<label for="node-input-auto-connect" style="width: 70%;"> Attempt auto connect on connection close</label>
107+
</div>
108+
91109
<div class="form-row">
92110
<label>&nbsp;</label>
93111
<input type="checkbox" id="node-input-speakerlabels"style="display: inline-block; width: auto; vertical-align: top;"></input>
@@ -148,6 +166,8 @@
148166
is as per the WebSocket input for Speech To Text, with an action of either
149167
<code>start</code> or <code>stop</code> or an audio blob. No token is needed
150168
as the node takes care of that step.</p>
169+
<p>>The Mute option allows for the supression of session timeout messages.</p>
170+
<p>>The Discard Listening option allows for listening events from STT to be discarded.</p>
151171
<p>For more information about the Speech To Text service, read the <a href="https://www.ibm.com/watson/services/speech-to-text/">documentation</a>.</p>
152172
</script>
153173

@@ -186,41 +206,61 @@
186206
return self.indexOf(value) === index;
187207
}
188208

209+
stt.showSelectedFields = function(fields) {
210+
for (i = 0; i < fields.length; i++) {
211+
$(fields[i]).parent().show();
212+
}
213+
}
214+
215+
stt.hideSelectedFields = function(fields) {
216+
for (i = 0; i < fields.length; i++) {
217+
$(fields[i]).parent().hide();
218+
}
219+
}
220+
221+
189222
// Function to be used at the start, as don't want to expose any fields, unless the models are
190223
// available. The models can only be fetched if the credentials are available.
191224
stt.hideEverything = function () {
192225
if (!stt.models) {
226+
var fields = [];
193227
$('#credentials-not-found').show();
194-
$('label#node-label-message').parent().hide();
195-
$('input#node-input-alternatives').parent().hide();
196-
$('input#node-input-speakerlabels').parent().hide();
197-
$('input#node-input-smartformatting').parent().hide();
198-
$('select#node-input-lang').parent().hide();
199-
$('select#node-input-band').parent().hide();
200-
$('select#node-input-langcustom').parent().hide();
228+
229+
fields.push('#node-label-message'
230+
+ ', #node-input-alternatives'
231+
+ ', #node-input-speakerlabels'
232+
+ ', #node-input-smartformatting'
233+
+ ', #node-input-lang'
234+
+ ', #node-input-band'
235+
+ ', #node-input-langcustom');
236+
stt.hideSelectedFields(fields);
201237
}
202238
}
203239

204240
// Check if there is a model then can show the fields.
205241
// available. The models can only be fetched if the credentials are available.
206242
stt.VisibilityCheck = function () {
243+
var showFields = [];
244+
var hideFields = [];
207245
if (stt.models) {
208-
$('label#node-label-message').parent().hide();
209-
$('input#node-input-alternatives').parent().show();
210-
$('input#node-input-speakerlabels').parent().show();
211-
$('input#node-input-smartformatting').parent().show();
212-
$('select#node-input-lang').parent().show();
213-
//$('select#node-input-langcustom').parent().show();
214-
$('select#node-input-band').parent().show();
246+
showFields.push('#node-input-alternatives'
247+
+ ', #node-input-speakerlabels'
248+
+ ', #node-input-smartformatting'
249+
+ ', #node-input-lang'
250+
+ ', #node-input-band');
251+
252+
hideFields.push('#node-label-message');
215253
} else {
216-
$('label#node-label-message').parent().hide();
217-
$('input#node-input-alternatives').parent().hide();
218-
$('input#node-input-speakerlabels').parent().hide();
219-
$('input#node-input-smartformatting').parent().hide();
220-
$('select#node-input-lang').parent().hide();
221-
$('select#node-input-langcustom').parent().hide();
222-
$('select#node-input-band').parent().hide();
254+
hideFields.push('#node-label-message'
255+
+ ', #node-input-alternatives'
256+
+ ', #node-input-speakerlabels'
257+
+ ', #node-input-smartformatting'
258+
+ ', #node-input-langcustom'
259+
+ ', #node-input-lang'
260+
+ ', #node-input-band');
223261
}
262+
stt.hideSelectedFields(hideFields);
263+
stt.showSelectedFields(showFields);
224264
}
225265

226266

@@ -365,6 +405,20 @@
365405
}
366406
});
367407

408+
$('#node-input-streaming-mode').change(function () {
409+
var fields = [];
410+
fields.push('#node-input-streaming-mute'
411+
+ ', #node-input-discard-listening'
412+
+ ', #node-input-auto-connect');
413+
414+
var checked = $('#node-input-streaming-mode').prop('checked')
415+
if (checked) {
416+
stt.showSelectedFields(fields);
417+
} else {
418+
stt.hideSelectedFields(fields);
419+
}
420+
});
421+
368422
$('#node-input-flushcache').click(function () {
369423
stt.flushCache();
370424
});
@@ -542,6 +596,8 @@
542596
password: {value: ''},
543597
'payload-response' :{value: false},
544598
'streaming-mode' :{value: false},
599+
'streaming-mute' :{value: true},
600+
'discard-listening' :{value: false},
545601
'default-endpoint' :{value: true},
546602
'service-endpoint' :{value: 'https://stream.watsonplatform.net/speech-to-text/api'}
547603
},

services/speech_to_text/v1.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module.exports = function (RED) {
2828
payloadutils = require('../../utilities/payload-utils'),
2929
sttV1 = require('watson-developer-cloud/speech-to-text/v1'),
3030
authV1 = require('watson-developer-cloud/authorization/v1'),
31+
muteMode = true, discardMode = false, autoConnect = true,
3132
username = '', password = '', sUsername = '', sPassword = '',
3233
endpoint = '',
3334
sEndpoint = 'https://stream.watsonplatform.net/speech-to-text/api',
@@ -133,6 +134,10 @@ module.exports = function (RED) {
133134
function configCheck() {
134135
var message = '';
135136

137+
muteMode = config['streaming-mute'];
138+
discardMode = config['discard-listening'];
139+
autoConnect = config['auto-connect'];
140+
136141
if (!config.lang) {
137142
message = 'Missing audio language configuration, unable to process speech.';
138143
} else if (!config.band) {
@@ -397,7 +402,10 @@ module.exports = function (RED) {
397402
// Force Expiry of Token, as that is the only Error
398403
// response from the service that we have seen.
399404
// report the error for verbose testing
400-
payloadutils.reportError(node,newMsg,d.error);
405+
if (!muteMode) {
406+
payloadutils.reportError(node,newMsg,d.error);
407+
}
408+
401409
token = null;
402410
getToken(determineService())
403411
.then(() => {
@@ -406,7 +414,9 @@ module.exports = function (RED) {
406414
} else if (d && d.state && 'listening' === d.state) {
407415
socketListening = true;
408416
// Added for verbose testing
409-
node.send(newMsg);
417+
if (!discardMode) {
418+
node.send(newMsg);
419+
}
410420
//resolve();
411421
} else {
412422
node.send(newMsg);
@@ -418,12 +428,20 @@ module.exports = function (RED) {
418428
websocket = null;
419429
socketListening = false;
420430
// console.log('STT Socket disconnected');
421-
setTimeout(connectIfNeeded, 1000);
431+
if (!muteMode) {
432+
var newMsg = {payload : 'STT Connection Close Event'};
433+
payloadutils.reportError(node,newMsg,'STT Socket Connection closed');
434+
}
435+
if (autoConnect) {
436+
setTimeout(connectIfNeeded, 1000);
437+
}
422438
});
423439

424440
ws.on('error', (err) => {
425441
socketListening = false;
426-
payloadutils.reportError(node,newMsg,err);
442+
if (!muteMode) {
443+
payloadutils.reportError(node,newMsg,err);
444+
}
427445
// console.log('Error Detected');
428446
if (initialConnect) {
429447
//reject(err);
@@ -472,8 +490,9 @@ module.exports = function (RED) {
472490
//websocket.send(a.data);
473491
websocket.send(a.data, (error) => {
474492
if (error) {
475-
payloadutils.reportError(node,{},error);
476-
} else {
493+
if (!muteMode) {
494+
payloadutils.reportError(node,{},error);
495+
}
477496
}
478497
});
479498
}

0 commit comments

Comments
 (0)