Skip to content

Commit 1901aae

Browse files
authored
fix: stop ignoring serviceUrl for Websocket methods (#1060)
`recognizeUsingWebsocket` (STT) and `synthesizeUsingWebsocket` (TTS) were not using the `serviceUrl` parameter defined by the core
1 parent 21a5a7f commit 1901aae

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
lines changed

lib/recognize-stream.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class RecognizeStream extends Duplex {
6969
*
7070
* @param {Options} options
7171
* @param {Authenticator} options.authenticator - Authenticator to add Authorization header
72-
* @param {string} [options.url] - Base url for service (default='wss://stream.watsonplatform.net/speech-to-text/api')
72+
* @param {string} [options.serviceUrl] - Base url for service (default='wss://stream.watsonplatform.net/speech-to-text/api')
7373
* @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)
7474
* @param {boolean} [options.readableObjectMode] - Emit `result` objects instead of string Buffers for the `data` events. Does not affect input (which must be binary)
7575
* @param {boolean} [options.objectMode] - Alias for readableObjectMode
@@ -152,7 +152,7 @@ class RecognizeStream extends Duplex {
152152

153153
// synthesize the url
154154
const url =
155-
(options.url || 'wss://stream.watsonplatform.net/speech-to-text/api'
155+
(options.serviceUrl || 'wss://stream.watsonplatform.net/speech-to-text/api'
156156
).replace(/^http/, 'ws') +
157157
'/v1/recognize?' +
158158
queryString;
@@ -468,7 +468,7 @@ namespace RecognizeStream {
468468
// to the user.
469469
authenticator: Authenticator;
470470
disableSslVerification?: boolean;
471-
url?: string;
471+
serviceUrl?: string;
472472
}
473473
}
474474

lib/synthesize-stream.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class SynthesizeStream extends Readable {
5151
*
5252
* @param {Options} options
5353
* @param {Authenticator} options.authenticator - Authenticator to add Authorization header
54-
* @param {string} [options.url] - Base url for service (default='wss://stream.watsonplatform.net/speech-to-text/api')
54+
* @param {string} [options.serviceUrl] - Base url for service (default='wss://stream.watsonplatform.net/speech-to-text/api')
5555
* @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)
5656
* @param {boolean} [options.disableSslVerification] - If true, disable SSL verification for the WebSocket connection (default=false)
5757
* @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 {
9090

9191
// synthesize the url
9292
const url =
93-
(options.url || 'wss://stream.watsonplatform.net/text-to-speech/api')
93+
(options.serviceUrl || 'wss://stream.watsonplatform.net/text-to-speech/api')
9494
.replace(/^http/, 'ws') +
9595
'/v1/synthesize?' +
9696
queryString;
@@ -233,7 +233,7 @@ namespace SynthesizeStream {
233233
export interface Options extends ReadableOptions, SynthesizeWebSocketParams {
234234
/* base options */
235235
authenticator: Authenticator;
236-
url?: string;
236+
serviceUrl?: string;
237237
disableSslVerification?: boolean;
238238
agent?: Agent;
239239
}

speech-to-text/v1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
131131
{
132132
// pass the Authenticator to the RecognizeStream object
133133
authenticator: this.getAuthenticator(),
134-
url: this.baseOptions.url,
134+
serviceUrl: this.baseOptions.serviceUrl,
135135
// if the user configured a custom https client, use it in the websocket method
136136
// let httpsAgent take precedence, default to null
137137
agent: this.baseOptions.httpsAgent || this.baseOptions.httpAgent || null,

test/unit/speech-helpers.test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ const websocket = require('websocket');
66
const SpeechToTextV1 = require('../../dist/speech-to-text/v1');
77
const TextToSpeechV1 = require('../../dist/text-to-speech/v1');
88

9-
const url = 'http://ibm.com:80';
9+
const serviceUrl = 'http://ibm.com:80';
1010
const version = 'v1';
1111
const authenticator = new BasicAuthenticator({
1212
username: 'batman',
1313
password: 'bruce-wayne',
1414
});
1515

1616
const sttService = {
17-
url,
17+
serviceUrl,
1818
version,
1919
authenticator,
2020
};
2121

2222
const ttsService = {
23-
url,
23+
url: serviceUrl,
2424
version,
2525
authenticator,
2626
};
@@ -38,7 +38,7 @@ describe('speech to text helpers', () => {
3838

3939
it('should pass the correct parameters into RecognizeStream', () => {
4040
const stream = speechToText.recognizeUsingWebSocket();
41-
expect(stream.options.url).toBe(sttService.url);
41+
expect(stream.options.serviceUrl).toBe(serviceUrl);
4242
expect(stream.options.headers['User-Agent']).toBeTruthy();
4343
expect(stream.options.headers['X-IBMCloud-SDK-Analytics']).toBe(
4444
'service_name=speech_to_text;service_version=v1;operation_id=recognizeUsingWebSocket;async=true'
@@ -87,7 +87,7 @@ describe('text to speech helpers', () => {
8787

8888
it('should pass the correct parameters into RecognizeStream', () => {
8989
const stream = textToSpeech.synthesizeUsingWebSocket();
90-
expect(stream.options.url).toBe(ttsService.url);
90+
expect(stream.options.serviceUrl).toBe(serviceUrl);
9191
expect(stream.options.headers.authorization).toBeUndefined();
9292
expect(stream.options.headers['User-Agent']).toBeTruthy();
9393
expect(stream.options.headers['X-IBMCloud-SDK-Analytics']).toBe(

text-to-speech/v1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ class TextToSpeechV1 extends GeneratedTextToSpeechV1 {
113113
{
114114
// pass the Authenticator to the SynthesizeStream object
115115
authenticator: this.getAuthenticator(),
116-
url: this.baseOptions.url,
116+
serviceUrl: this.baseOptions.serviceUrl,
117117
// if the user configured a custom https client, use it in the websocket method
118118
// let httpsAgent take precedence, default to null
119119
agent: this.baseOptions.httpsAgent || this.baseOptions.httpAgent || null,

0 commit comments

Comments
 (0)