From 1901aae2f07e58c97ed26ed31906407581fb51c1 Mon Sep 17 00:00:00 2001 From: Dustin Popp Date: Tue, 29 Sep 2020 11:30:16 -0500 Subject: [PATCH] fix: stop ignoring serviceUrl for Websocket methods (#1060) `recognizeUsingWebsocket` (STT) and `synthesizeUsingWebsocket` (TTS) were not using the `serviceUrl` parameter defined by the core --- lib/recognize-stream.ts | 6 +++--- lib/synthesize-stream.ts | 6 +++--- speech-to-text/v1.ts | 2 +- test/unit/speech-helpers.test.js | 10 +++++----- text-to-speech/v1.ts | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/recognize-stream.ts b/lib/recognize-stream.ts index feab7dd562..2f173a9bda 100644 --- a/lib/recognize-stream.ts +++ b/lib/recognize-stream.ts @@ -69,7 +69,7 @@ class RecognizeStream extends Duplex { * * @param {Options} options * @param {Authenticator} options.authenticator - Authenticator to add Authorization header - * @param {string} [options.url] - Base url for service (default='wss://stream.watsonplatform.net/speech-to-text/api') + * @param {string} [options.serviceUrl] - Base url for service (default='wss://stream.watsonplatform.net/speech-to-text/api') * @param {OutgoingHttpHeaders} [options.headers] - Only works in Node.js, not in browsers. Allows for custom headers to be set, including an Authorization header (preventing the need for auth tokens) * @param {boolean} [options.readableObjectMode] - Emit `result` objects instead of string Buffers for the `data` events. Does not affect input (which must be binary) * @param {boolean} [options.objectMode] - Alias for readableObjectMode @@ -152,7 +152,7 @@ class RecognizeStream extends Duplex { // synthesize the url const url = - (options.url || 'wss://stream.watsonplatform.net/speech-to-text/api' + (options.serviceUrl || 'wss://stream.watsonplatform.net/speech-to-text/api' ).replace(/^http/, 'ws') + '/v1/recognize?' + queryString; @@ -468,7 +468,7 @@ namespace RecognizeStream { // to the user. authenticator: Authenticator; disableSslVerification?: boolean; - url?: string; + serviceUrl?: string; } } diff --git a/lib/synthesize-stream.ts b/lib/synthesize-stream.ts index 7ae95952e7..28bfa5a351 100644 --- a/lib/synthesize-stream.ts +++ b/lib/synthesize-stream.ts @@ -51,7 +51,7 @@ class SynthesizeStream extends Readable { * * @param {Options} options * @param {Authenticator} options.authenticator - Authenticator to add Authorization header - * @param {string} [options.url] - Base url for service (default='wss://stream.watsonplatform.net/speech-to-text/api') + * @param {string} [options.serviceUrl] - Base url for service (default='wss://stream.watsonplatform.net/speech-to-text/api') * @param {OutgoingHttpHeaders} [options.headers] - Only works in Node.js, not in browsers. Allows for custom headers to be set, including an Authorization header (preventing the need for auth tokens) * @param {boolean} [options.disableSslVerification] - If true, disable SSL verification for the WebSocket connection (default=false) * @param {Agent} [options.agent] - custom http(s) agent, useful for using the sdk behind a proxy (Node only) @@ -90,7 +90,7 @@ class SynthesizeStream extends Readable { // synthesize the url const url = - (options.url || 'wss://stream.watsonplatform.net/text-to-speech/api') + (options.serviceUrl || 'wss://stream.watsonplatform.net/text-to-speech/api') .replace(/^http/, 'ws') + '/v1/synthesize?' + queryString; @@ -233,7 +233,7 @@ namespace SynthesizeStream { export interface Options extends ReadableOptions, SynthesizeWebSocketParams { /* base options */ authenticator: Authenticator; - url?: string; + serviceUrl?: string; disableSslVerification?: boolean; agent?: Agent; } diff --git a/speech-to-text/v1.ts b/speech-to-text/v1.ts index 3395f0ee8d..f4c4b74d38 100644 --- a/speech-to-text/v1.ts +++ b/speech-to-text/v1.ts @@ -131,7 +131,7 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 { { // pass the Authenticator to the RecognizeStream object authenticator: this.getAuthenticator(), - url: this.baseOptions.url, + serviceUrl: this.baseOptions.serviceUrl, // if the user configured a custom https client, use it in the websocket method // let httpsAgent take precedence, default to null agent: this.baseOptions.httpsAgent || this.baseOptions.httpAgent || null, diff --git a/test/unit/speech-helpers.test.js b/test/unit/speech-helpers.test.js index 3fcdfc2a39..360f92e641 100644 --- a/test/unit/speech-helpers.test.js +++ b/test/unit/speech-helpers.test.js @@ -6,7 +6,7 @@ const websocket = require('websocket'); const SpeechToTextV1 = require('../../dist/speech-to-text/v1'); const TextToSpeechV1 = require('../../dist/text-to-speech/v1'); -const url = 'http://ibm.com:80'; +const serviceUrl = 'http://ibm.com:80'; const version = 'v1'; const authenticator = new BasicAuthenticator({ username: 'batman', @@ -14,13 +14,13 @@ const authenticator = new BasicAuthenticator({ }); const sttService = { - url, + serviceUrl, version, authenticator, }; const ttsService = { - url, + url: serviceUrl, version, authenticator, }; @@ -38,7 +38,7 @@ describe('speech to text helpers', () => { it('should pass the correct parameters into RecognizeStream', () => { const stream = speechToText.recognizeUsingWebSocket(); - expect(stream.options.url).toBe(sttService.url); + expect(stream.options.serviceUrl).toBe(serviceUrl); expect(stream.options.headers['User-Agent']).toBeTruthy(); expect(stream.options.headers['X-IBMCloud-SDK-Analytics']).toBe( 'service_name=speech_to_text;service_version=v1;operation_id=recognizeUsingWebSocket;async=true' @@ -87,7 +87,7 @@ describe('text to speech helpers', () => { it('should pass the correct parameters into RecognizeStream', () => { const stream = textToSpeech.synthesizeUsingWebSocket(); - expect(stream.options.url).toBe(ttsService.url); + expect(stream.options.serviceUrl).toBe(serviceUrl); expect(stream.options.headers.authorization).toBeUndefined(); expect(stream.options.headers['User-Agent']).toBeTruthy(); expect(stream.options.headers['X-IBMCloud-SDK-Analytics']).toBe( diff --git a/text-to-speech/v1.ts b/text-to-speech/v1.ts index 7839bb064e..f48d87cff3 100644 --- a/text-to-speech/v1.ts +++ b/text-to-speech/v1.ts @@ -113,7 +113,7 @@ class TextToSpeechV1 extends GeneratedTextToSpeechV1 { { // pass the Authenticator to the SynthesizeStream object authenticator: this.getAuthenticator(), - url: this.baseOptions.url, + serviceUrl: this.baseOptions.serviceUrl, // if the user configured a custom https client, use it in the websocket method // let httpsAgent take precedence, default to null agent: this.baseOptions.httpsAgent || this.baseOptions.httpAgent || null,