Skip to content

Commit e41ba12

Browse files
committed
refactor: update websocket agent support changes to be typed
* upgrade core dependency to v1.0.0-rc2 in preparation for a second release candidate
1 parent 0c92dfe commit e41ba12

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

lib/recognize-stream.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License
1515
*/
1616

17+
import { RequestOptions } from 'http';
1718
import { Authenticator, contentType, qs } from 'ibm-cloud-sdk-core';
1819
import omit = require('object.omit');
1920
import pick = require('object.pick');
@@ -75,6 +76,7 @@ class RecognizeStream extends Duplex {
7576
* @param {boolean} [options.readableObjectMode] - Emit `result` objects instead of string Buffers for the `data` events. Does not affect input (which must be binary)
7677
* @param {boolean} [options.objectMode] - Alias for readableObjectMode
7778
* @param {boolean} [options.disableSslVerification] - If true, disable SSL verification for the WebSocket connection (default=false)
79+
* @param {Agent} [options.agent] - custom http(s) agent, useful for using the sdk behind a proxy (Node only)
7880
* @param {string} [options.accessToken] - Bearer token to put in query string
7981
* @param {string} [options.watsonToken] - Valid Watson authentication token (for Cloud Foundry)
8082
* @param {string} [options.model] - The identifier of the model that is to be used for all recognition requests sent over the connection
@@ -189,7 +191,7 @@ class RecognizeStream extends Duplex {
189191
// add custom agent in the request options if given by user
190192
// default request options to null
191193
const { agent } = options;
192-
const requestOptions = agent ? { agent } : null;
194+
const requestOptions: RequestOptions = agent ? { agent } : null;
193195

194196
const socket = (this.socket = new w3cWebSocket(
195197
url,

lib/synthesize-stream.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License
1515
*/
1616

17-
import { OutgoingHttpHeaders } from 'http';
17+
import { Agent, OutgoingHttpHeaders, RequestOptions } from 'http';
1818
import { Authenticator, qs } from 'ibm-cloud-sdk-core';
1919
import pick = require('object.pick');
2020
import { Readable, ReadableOptions } from 'stream';
@@ -32,6 +32,7 @@ interface Options extends ReadableOptions {
3232
url?: string;
3333
headers?: OutgoingHttpHeaders;
3434
disableSslVerification?: boolean;
35+
agent?: Agent;
3536

3637
/* payload options */
3738
text: string;
@@ -84,6 +85,7 @@ class SynthesizeStream extends Readable {
8485
* @param {string} [options.url] - Base url for service (default='wss://stream.watsonplatform.net/speech-to-text/api')
8586
* @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)
8687
* @param {boolean} [options.disableSslVerification] - If true, disable SSL verification for the WebSocket connection (default=false)
88+
* @param {Agent} [options.agent] - custom http(s) agent, useful for using the sdk behind a proxy (Node only)
8789
* @param {string} options.text - The text that us to be synthesized
8890
* @param {string} options.accept - The requested format (MIME type) of the audio
8991
* @param {string[]} [options.timings] - An array that specifies whether the service is to return word timing information for all strings of the input text
@@ -127,7 +129,7 @@ class SynthesizeStream extends Readable {
127129
// add custom agent in the request options if given by user
128130
// default request options to null
129131
const { agent } = options;
130-
const requestOptions = agent ? { agent } : null;
132+
const requestOptions: RequestOptions = agent ? { agent } : null;
131133

132134
const socket = (this.socket = new w3cWebSocket(
133135
url,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"axios": "^0.18.0",
8686
"camelcase": "^5.3.1",
8787
"extend": "~3.0.2",
88-
"ibm-cloud-sdk-core": "^1.0.0-rc1",
88+
"ibm-cloud-sdk-core": "^1.0.0-rc2",
8989
"isstream": "~0.1.2",
9090
"object.pick": "~1.3.0",
9191
"snyk": "^1.192.4",

speech-to-text/v1.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import async = require('async');
22
import extend = require('extend');
3-
import { OutgoingHttpHeaders } from 'http';
3+
import { Agent, OutgoingHttpHeaders } from 'http';
44
import isStream = require('isstream');
55
import { getSdkHeaders } from '../lib/common';
66
import RecognizeStream = require('../lib/recognize-stream');
@@ -138,7 +138,7 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
138138

139139
// if the user configured a custom https client, use it in the websocket method
140140
// let httpsAgent take precedence, default to null
141-
params.agent = this._options.httpsAgent || this._options.httpAgent || null;
141+
params.agent = this.baseOptions.httpsAgent || this.baseOptions.httpAgent || null;
142142

143143
// include analytics headers
144144
const sdkHeaders = getSdkHeaders('speech_to_text', 'v1', 'recognizeUsingWebSocket');
@@ -264,6 +264,7 @@ namespace SpeechToTextV1 {
264264
headers?: OutgoingHttpHeaders;
265265
readableObjectMode?: boolean;
266266
objectMode?: boolean;
267+
agent?: Agent;
267268

268269
/* Query Params*/
269270
accessToken?: string;

text-to-speech/v1.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class TextToSpeechV1 extends GeneratedTextToSpeechV1 {
7979

8080
// if the user configured a custom https client, use it in the websocket method
8181
// let httpsAgent take precedence, default to null
82-
params.agent = this._options.httpsAgent || this._options.httpAgent || null;
82+
params.agent = this.baseOptions.httpsAgent || this.baseOptions.httpAgent || null;
8383

8484
// include analytics headers
8585
const sdkHeaders = getSdkHeaders('text_to_speech', 'v1', 'synthesizeUsingWebSocket');

0 commit comments

Comments
 (0)