Skip to content

Commit ab61876

Browse files
fix(browser): check for fetch on window (#501)
1 parent 81e6603 commit ab61876

14 files changed

+244
-110
lines changed

packages/google-cloud-videointelligence/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"prettier": "^2.1.2",
6868
"sinon": "^9.0.2",
6969
"ts-loader": "^8.0.0",
70-
"typescript": "^3.8.3",
71-
"webpack-cli": "^3.3.11"
70+
"typescript": "^3.8.3"
7271
}
7372
}

packages/google-cloud-videointelligence/protos/protos.json

Lines changed: 135 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/google-cloud-videointelligence/src/v1/video_intelligence_service_client.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// ** https://github.com/googleapis/gapic-generator-typescript **
1717
// ** All changes to this file may be overwritten. **
1818

19+
/* global window */
1920
import * as gax from 'google-gax';
2021
import {
2122
Callback,
@@ -27,6 +28,11 @@ import {
2728
import * as path from 'path';
2829

2930
import * as protos from '../../protos/protos';
31+
/**
32+
* Client JSON configuration object, loaded from
33+
* `src/v1/video_intelligence_service_client_config.json`.
34+
* This file defines retry strategy and timeouts for all API methods in this library.
35+
*/
3036
import * as gapicConfig from './video_intelligence_service_client_config.json';
3137
import {operationsProtos} from 'google-gax';
3238
const version = require('../../../package.json').version;
@@ -80,9 +86,9 @@ export class VideoIntelligenceServiceClient {
8086
* your project ID will be detected automatically.
8187
* @param {string} [options.apiEndpoint] - The domain name of the
8288
* API remote host.
83-
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override.
84-
* TODO(@alexander-fenster): link to gax documentation.
85-
* @param {boolean} fallback - Use HTTP fallback mode.
89+
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
90+
* Follows the structure of {@link gapicConfig}.
91+
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
8692
* In fallback mode, a special browser-compatible transport implementation is used
8793
* instead of gRPC transport. In browser context (if the `window` object is defined)
8894
* the fallback mode is enabled automatically; set `options.fallback` to `false`
@@ -96,7 +102,9 @@ export class VideoIntelligenceServiceClient {
96102
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
97103
const port = opts?.port || staticMembers.port;
98104
const clientConfig = opts?.clientConfig ?? {};
99-
const fallback = opts?.fallback ?? typeof window !== 'undefined';
105+
const fallback =
106+
opts?.fallback ??
107+
(typeof window !== 'undefined' && typeof window?.fetch === 'function');
100108
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);
101109

102110
// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
@@ -313,7 +321,7 @@ export class VideoIntelligenceServiceClient {
313321

314322
annotateVideo(
315323
request: protos.google.cloud.videointelligence.v1.IAnnotateVideoRequest,
316-
options?: gax.CallOptions
324+
options?: CallOptions
317325
): Promise<
318326
[
319327
LROperation<
@@ -326,7 +334,7 @@ export class VideoIntelligenceServiceClient {
326334
>;
327335
annotateVideo(
328336
request: protos.google.cloud.videointelligence.v1.IAnnotateVideoRequest,
329-
options: gax.CallOptions,
337+
options: CallOptions,
330338
callback: Callback<
331339
LROperation<
332340
protos.google.cloud.videointelligence.v1.IAnnotateVideoResponse,
@@ -404,7 +412,7 @@ export class VideoIntelligenceServiceClient {
404412
annotateVideo(
405413
request: protos.google.cloud.videointelligence.v1.IAnnotateVideoRequest,
406414
optionsOrCallback?:
407-
| gax.CallOptions
415+
| CallOptions
408416
| Callback<
409417
LROperation<
410418
protos.google.cloud.videointelligence.v1.IAnnotateVideoResponse,
@@ -432,12 +440,12 @@ export class VideoIntelligenceServiceClient {
432440
]
433441
> | void {
434442
request = request || {};
435-
let options: gax.CallOptions;
443+
let options: CallOptions;
436444
if (typeof optionsOrCallback === 'function' && callback === undefined) {
437445
callback = optionsOrCallback;
438446
options = {};
439447
} else {
440-
options = optionsOrCallback as gax.CallOptions;
448+
options = optionsOrCallback as CallOptions;
441449
}
442450
options = options || {};
443451
this.initialize();

packages/google-cloud-videointelligence/src/v1beta2/video_intelligence_service_client.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
// ** https://github.com/googleapis/gapic-generator-typescript **
1717
// ** All changes to this file may be overwritten. **
1818

19+
/* global window */
1920
import * as gax from 'google-gax';
2021
import {
2122
Callback,
@@ -27,6 +28,11 @@ import {
2728
import * as path from 'path';
2829

2930
import * as protos from '../../protos/protos';
31+
/**
32+
* Client JSON configuration object, loaded from
33+
* `src/v1beta2/video_intelligence_service_client_config.json`.
34+
* This file defines retry strategy and timeouts for all API methods in this library.
35+
*/
3036
import * as gapicConfig from './video_intelligence_service_client_config.json';
3137
import {operationsProtos} from 'google-gax';
3238
const version = require('../../../package.json').version;
@@ -80,9 +86,9 @@ export class VideoIntelligenceServiceClient {
8086
* your project ID will be detected automatically.
8187
* @param {string} [options.apiEndpoint] - The domain name of the
8288
* API remote host.
83-
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override.
84-
* TODO(@alexander-fenster): link to gax documentation.
85-
* @param {boolean} fallback - Use HTTP fallback mode.
89+
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
90+
* Follows the structure of {@link gapicConfig}.
91+
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
8692
* In fallback mode, a special browser-compatible transport implementation is used
8793
* instead of gRPC transport. In browser context (if the `window` object is defined)
8894
* the fallback mode is enabled automatically; set `options.fallback` to `false`
@@ -96,7 +102,9 @@ export class VideoIntelligenceServiceClient {
96102
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
97103
const port = opts?.port || staticMembers.port;
98104
const clientConfig = opts?.clientConfig ?? {};
99-
const fallback = opts?.fallback ?? typeof window !== 'undefined';
105+
const fallback =
106+
opts?.fallback ??
107+
(typeof window !== 'undefined' && typeof window?.fetch === 'function');
100108
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);
101109

102110
// If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
@@ -313,7 +321,7 @@ export class VideoIntelligenceServiceClient {
313321

314322
annotateVideo(
315323
request: protos.google.cloud.videointelligence.v1beta2.IAnnotateVideoRequest,
316-
options?: gax.CallOptions
324+
options?: CallOptions
317325
): Promise<
318326
[
319327
LROperation<
@@ -326,7 +334,7 @@ export class VideoIntelligenceServiceClient {
326334
>;
327335
annotateVideo(
328336
request: protos.google.cloud.videointelligence.v1beta2.IAnnotateVideoRequest,
329-
options: gax.CallOptions,
337+
options: CallOptions,
330338
callback: Callback<
331339
LROperation<
332340
protos.google.cloud.videointelligence.v1beta2.IAnnotateVideoResponse,
@@ -401,7 +409,7 @@ export class VideoIntelligenceServiceClient {
401409
annotateVideo(
402410
request: protos.google.cloud.videointelligence.v1beta2.IAnnotateVideoRequest,
403411
optionsOrCallback?:
404-
| gax.CallOptions
412+
| CallOptions
405413
| Callback<
406414
LROperation<
407415
protos.google.cloud.videointelligence.v1beta2.IAnnotateVideoResponse,
@@ -429,12 +437,12 @@ export class VideoIntelligenceServiceClient {
429437
]
430438
> | void {
431439
request = request || {};
432-
let options: gax.CallOptions;
440+
let options: CallOptions;
433441
if (typeof optionsOrCallback === 'function' && callback === undefined) {
434442
callback = optionsOrCallback;
435443
options = {};
436444
} else {
437-
options = optionsOrCallback as gax.CallOptions;
445+
options = optionsOrCallback as CallOptions;
438446
}
439447
options = options || {};
440448
this.initialize();

0 commit comments

Comments
 (0)