diff --git a/lib/recognize-stream.ts b/lib/recognize-stream.ts index 20da337969..cef50eeea7 100644 --- a/lib/recognize-stream.ts +++ b/lib/recognize-stream.ts @@ -126,6 +126,7 @@ class RecognizeStream extends Duplex { * 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://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-input#version). * @param {Boolean} [options.rejectUnauthorized] - If true, disable SSL verification for the WebSocket connection + * @param {String} [options.agent] - custom http(s) agent, useful for using the sdk behind a proxy (Node only) * @param {String} [options.grammar_name] - The name of a grammar that is to be used with the recognition request. If you specify a grammar, you must also use the `language_customization_id` parameter to specify the name of the custom language model for which the grammar is defined. The service recognizes only strings that are recognized by the specified grammar; it does not recognize other custom words from the model's words resource. See [Grammars](https://cloud.ibm.com/docs/services/speech-to-text/output.html) * @param {Boolean} [options.redaction] - If `true`, the service redacts, or masks, numeric data from final transcripts. The feature redacts any number that has three or more consecutive digits by replacing each digit with an `X` character. It is intended to redact sensitive numeric data, such as credit card numbers. By default, the service performs no redaction. When you enable redaction, the service automatically enables smart formatting, regardless of whether you explicitly disable that feature. To ensure maximum security, the service also disables keyword spotting (ignores the `keywords` and `keywords_threshold` parameters) and returns only a single final transcript (forces the `max_alternatives` parameter to be `1`). **Note:** Applies to US English, Japanese, and Korean transcription only. See [Numeric redaction](https://cloud.ibm.com/docs/services/speech-to-text/output.html#redaction) * @@ -241,12 +242,18 @@ class RecognizeStream extends Duplex { // for the last argument, `tlsOptions` gets passed to Node's `http` library, // which allows us to pass a rejectUnauthorized option // for disabling SSL verification (for ICP) + + // add custom agent in the request options if given by user + // default request options to null + const { agent } = options; + const requestOptions = agent ? { agent } : null; + const socket = (this.socket = new w3cWebSocket( url, null, null, options.headers, - null, + requestOptions, { tlsOptions: { rejectUnauthorized: options.rejectUnauthorized }} )); diff --git a/lib/synthesize-stream.ts b/lib/synthesize-stream.ts index f111c2c10f..c732dfa4db 100644 --- a/lib/synthesize-stream.ts +++ b/lib/synthesize-stream.ts @@ -82,6 +82,7 @@ class SynthesizeStream extends Readable { * @param {String} [options.x-watson-metadata] - Associates a customer ID with data that is passed over the connection. * @param {IamTokenManagerV1} [options.token_manager] - Token manager for authenticating with IAM * @param {Boolean} [options.rejectUnauthorized] - If true, disable SSL verification for the WebSocket connection + * @param {String} [options.agent] - custom http(s) agent, useful for using the sdk behind a proxy (Node only) * * @constructor */ @@ -103,12 +104,17 @@ class SynthesizeStream extends Readable { '/v1/synthesize?' + queryString; + // add custom agent in the request options if given by user + // default request options to null + const { agent } = options; + const requestOptions = agent ? { agent } : null; + const socket = (this.socket = new w3cWebSocket( url, null, null, options.headers, - null, + requestOptions, { tlsOptions: { rejectUnauthorized: options.rejectUnauthorized }} )); diff --git a/scripts/typedoc/generate_typedoc.sh b/scripts/typedoc/generate_typedoc.sh old mode 100644 new mode 100755 diff --git a/speech-to-text/v1.ts b/speech-to-text/v1.ts index d02b25d3b5..da6b6b2556 100644 --- a/speech-to-text/v1.ts +++ b/speech-to-text/v1.ts @@ -158,6 +158,10 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 { params.token_manager = this.tokenManager; } + // if the user configured a custom https client, use it in the websocket method + // let httpsAgent take precedence, default to null + params.agent = this._options.httpsAgent || this._options.httpAgent || null; + // include analytics headers const sdkHeaders = getSdkHeaders('speech_to_text', 'v1', 'recognizeUsingWebSocket'); diff --git a/test/unit/speech-helpers.test.js b/test/unit/speech-helpers.test.js index a8cf56e90e..db1c95e03a 100644 --- a/test/unit/speech-helpers.test.js +++ b/test/unit/speech-helpers.test.js @@ -9,6 +9,8 @@ const service = { url: 'http://ibm.com:80', version: 'v1', silent: true, // hide deprecation warnings for recognizeLive and friends + httpsAgent: 'fake https agent', + httpAgent: 'fake http agent', }; const rc_service = { @@ -16,6 +18,7 @@ const rc_service = { url: 'http://ibm.com:80', version: 'v1', silent: true, // hide deprecation warnings for recognizeLive and friends + httpAgent: 'fake http agent', }; const speech_to_text = new SpeechToTextV1(service); @@ -36,6 +39,7 @@ describe('speech_to_text', () => { 'service_name=speech_to_text;service_version=v1;operation_id=recognizeUsingWebSocket;async=true' ); expect(stream.options.token_manager).toBeUndefined(); + expect(stream.options.agent).toBe(service.httpsAgent); }); it('should create a token manager in RecognizeStream if using IAM', () => { @@ -43,6 +47,7 @@ describe('speech_to_text', () => { expect(stream.options.url).toBe(service.url); expect(stream.options.headers.authorization).toBeUndefined(); expect(stream.options.token_manager).toBeDefined(); + expect(stream.options.agent).toBe(rc_service.httpAgent); }); it('should override stored header with new token on refresh', done => { diff --git a/text-to-speech/v1.ts b/text-to-speech/v1.ts index 0a73c67b47..a1600977b8 100644 --- a/text-to-speech/v1.ts +++ b/text-to-speech/v1.ts @@ -86,6 +86,10 @@ class TextToSpeechV1 extends GeneratedTextToSpeechV1 { params.token_manager = this.tokenManager; } + // if the user configured a custom https client, use it in the websocket method + // let httpsAgent take precedence, default to null + params.agent = this._options.httpsAgent || this._options.httpAgent || null; + // include analytics headers const sdkHeaders = getSdkHeaders('text_to_speech', 'v1', 'synthesizeUsingWebSocket');