Skip to content

Commit

Permalink
fix: stop ignoring serviceUrl for Websocket methods (watson-developer…
Browse files Browse the repository at this point in the history
…-cloud#1060)

`recognizeUsingWebsocket` (STT) and `synthesizeUsingWebsocket` (TTS) were not using the `serviceUrl` parameter defined by the core
  • Loading branch information
dpopp07 authored Sep 29, 2020
1 parent 21a5a7f commit 1901aae
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/recognize-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -468,7 +468,7 @@ namespace RecognizeStream {
// to the user.
authenticator: Authenticator;
disableSslVerification?: boolean;
url?: string;
serviceUrl?: string;
}
}

Expand Down
6 changes: 3 additions & 3 deletions lib/synthesize-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -233,7 +233,7 @@ namespace SynthesizeStream {
export interface Options extends ReadableOptions, SynthesizeWebSocketParams {
/* base options */
authenticator: Authenticator;
url?: string;
serviceUrl?: string;
disableSslVerification?: boolean;
agent?: Agent;
}
Expand Down
2 changes: 1 addition & 1 deletion speech-to-text/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions test/unit/speech-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ 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',
password: 'bruce-wayne',
});

const sttService = {
url,
serviceUrl,
version,
authenticator,
};

const ttsService = {
url,
url: serviceUrl,
version,
authenticator,
};
Expand All @@ -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'
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion text-to-speech/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1901aae

Please sign in to comment.