diff --git a/lib/recognize-stream.ts b/lib/recognize-stream.ts index 9159edb259..63cd1708a8 100644 --- a/lib/recognize-stream.ts +++ b/lib/recognize-stream.ts @@ -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 */ @@ -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 ( @@ -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 diff --git a/speech-to-text/v1.ts b/speech-to-text/v1.ts index a8ef69c7e8..cc1bbfbfd0 100644 --- a/speech-to-text/v1.ts +++ b/speech-to-text/v1.ts @@ -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); }