Skip to content

Commit

Permalink
fix(icp): disabling ssl verification now works for websocket connection
Browse files Browse the repository at this point in the history
  • Loading branch information
dpopp07 committed Sep 27, 2018
1 parent 624de81 commit f8466c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/recognize-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class RecognizeStream extends Duplex {
* @param {string} [options.base_model_version] - The version of the specified base model that is to be used with recognition request or, for the **Create a session** method, with the new session.
* Multiple versions of a base model can exist when a model is updated for internal improvements. The parameter is intended primarily for use with custom models that have been upgraded for a new base model.
* The default value depends on whether the parameter is used with or without a custom model. For more information, see [Base model version](https://console.bluemix.net/docs/services/speech-to-text/input.html#version).
* @param {Boolean} [options.rejectUnauthorized] - If true, disable SSL verification for the WebSocket connection
*
* @constructor
*/
Expand All @@ -133,8 +134,15 @@ class RecognizeStream extends Duplex {
this.listening = false;
this.initialized = false;
this.finished = false;

// is using iam, another authentication step is needed
this.authenticated = options.token_manager ? false : true;

// build the last argument for the websocket constructor (clientConfig name comes from `websocket` docs)
// `tlsOptions` gets passed to Node's `http` library, which allows us to pass a rejectUnauthorized option
// for disabling SSL verification (for ICP)
const clientConfig = this.rejectUnauthorized ? { tlsOptions: { rejectUnauthorized: false }} : null;

this.on('newListener', event => {
if (!options.silent) {
if (
Expand Down Expand Up @@ -225,11 +233,7 @@ class RecognizeStream extends Duplex {
null,
options.headers,
null,
{
tlsOptions: {
rejectUnauthorized: false,
}
},
clientConfig
));

// when the input stops, let the service know that we're done
Expand Down
3 changes: 3 additions & 0 deletions speech-to-text/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
params.headers
);

// allow user to disable ssl verification when using websockets
params.rejectUnauthorized = this._options.rejectUnauthorized;

return new RecognizeStream(params);
}

Expand Down

0 comments on commit f8466c8

Please sign in to comment.