Skip to content

Commit

Permalink
fix(browser): check for fetch on window (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored Nov 23, 2020
1 parent 81e6603 commit ab61876
Show file tree
Hide file tree
Showing 14 changed files with 244 additions and 110 deletions.
3 changes: 1 addition & 2 deletions packages/google-cloud-videointelligence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"prettier": "^2.1.2",
"sinon": "^9.0.2",
"ts-loader": "^8.0.0",
"typescript": "^3.8.3",
"webpack-cli": "^3.3.11"
"typescript": "^3.8.3"
}
}
144 changes: 135 additions & 9 deletions packages/google-cloud-videointelligence/protos/protos.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

/* global window */
import * as gax from 'google-gax';
import {
Callback,
Expand All @@ -27,6 +28,11 @@ import {
import * as path from 'path';

import * as protos from '../../protos/protos';
/**
* Client JSON configuration object, loaded from
* `src/v1/video_intelligence_service_client_config.json`.
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './video_intelligence_service_client_config.json';
import {operationsProtos} from 'google-gax';
const version = require('../../../package.json').version;
Expand Down Expand Up @@ -80,9 +86,9 @@ export class VideoIntelligenceServiceClient {
* your project ID will be detected automatically.
* @param {string} [options.apiEndpoint] - The domain name of the
* API remote host.
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override.
* TODO(@alexander-fenster): link to gax documentation.
* @param {boolean} fallback - Use HTTP fallback mode.
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
* Follows the structure of {@link gapicConfig}.
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
* In fallback mode, a special browser-compatible transport implementation is used
* instead of gRPC transport. In browser context (if the `window` object is defined)
* the fallback mode is enabled automatically; set `options.fallback` to `false`
Expand All @@ -96,7 +102,9 @@ export class VideoIntelligenceServiceClient {
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
const port = opts?.port || staticMembers.port;
const clientConfig = opts?.clientConfig ?? {};
const fallback = opts?.fallback ?? typeof window !== 'undefined';
const fallback =
opts?.fallback ??
(typeof window !== 'undefined' && typeof window?.fetch === 'function');
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);

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

annotateVideo(
request: protos.google.cloud.videointelligence.v1.IAnnotateVideoRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
LROperation<
Expand All @@ -326,7 +334,7 @@ export class VideoIntelligenceServiceClient {
>;
annotateVideo(
request: protos.google.cloud.videointelligence.v1.IAnnotateVideoRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
LROperation<
protos.google.cloud.videointelligence.v1.IAnnotateVideoResponse,
Expand Down Expand Up @@ -404,7 +412,7 @@ export class VideoIntelligenceServiceClient {
annotateVideo(
request: protos.google.cloud.videointelligence.v1.IAnnotateVideoRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
LROperation<
protos.google.cloud.videointelligence.v1.IAnnotateVideoResponse,
Expand Down Expand Up @@ -432,12 +440,12 @@ export class VideoIntelligenceServiceClient {
]
> | void {
request = request || {};
let options: gax.CallOptions;
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
} else {
options = optionsOrCallback as gax.CallOptions;
options = optionsOrCallback as CallOptions;
}
options = options || {};
this.initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **

/* global window */
import * as gax from 'google-gax';
import {
Callback,
Expand All @@ -27,6 +28,11 @@ import {
import * as path from 'path';

import * as protos from '../../protos/protos';
/**
* Client JSON configuration object, loaded from
* `src/v1beta2/video_intelligence_service_client_config.json`.
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './video_intelligence_service_client_config.json';
import {operationsProtos} from 'google-gax';
const version = require('../../../package.json').version;
Expand Down Expand Up @@ -80,9 +86,9 @@ export class VideoIntelligenceServiceClient {
* your project ID will be detected automatically.
* @param {string} [options.apiEndpoint] - The domain name of the
* API remote host.
* @param {gax.ClientConfig} [options.clientConfig] - client configuration override.
* TODO(@alexander-fenster): link to gax documentation.
* @param {boolean} fallback - Use HTTP fallback mode.
* @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
* Follows the structure of {@link gapicConfig}.
* @param {boolean} [options.fallback] - Use HTTP fallback mode.
* In fallback mode, a special browser-compatible transport implementation is used
* instead of gRPC transport. In browser context (if the `window` object is defined)
* the fallback mode is enabled automatically; set `options.fallback` to `false`
Expand All @@ -96,7 +102,9 @@ export class VideoIntelligenceServiceClient {
opts?.servicePath || opts?.apiEndpoint || staticMembers.servicePath;
const port = opts?.port || staticMembers.port;
const clientConfig = opts?.clientConfig ?? {};
const fallback = opts?.fallback ?? typeof window !== 'undefined';
const fallback =
opts?.fallback ??
(typeof window !== 'undefined' && typeof window?.fetch === 'function');
opts = Object.assign({servicePath, port, clientConfig, fallback}, opts);

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

annotateVideo(
request: protos.google.cloud.videointelligence.v1beta2.IAnnotateVideoRequest,
options?: gax.CallOptions
options?: CallOptions
): Promise<
[
LROperation<
Expand All @@ -326,7 +334,7 @@ export class VideoIntelligenceServiceClient {
>;
annotateVideo(
request: protos.google.cloud.videointelligence.v1beta2.IAnnotateVideoRequest,
options: gax.CallOptions,
options: CallOptions,
callback: Callback<
LROperation<
protos.google.cloud.videointelligence.v1beta2.IAnnotateVideoResponse,
Expand Down Expand Up @@ -401,7 +409,7 @@ export class VideoIntelligenceServiceClient {
annotateVideo(
request: protos.google.cloud.videointelligence.v1beta2.IAnnotateVideoRequest,
optionsOrCallback?:
| gax.CallOptions
| CallOptions
| Callback<
LROperation<
protos.google.cloud.videointelligence.v1beta2.IAnnotateVideoResponse,
Expand Down Expand Up @@ -429,12 +437,12 @@ export class VideoIntelligenceServiceClient {
]
> | void {
request = request || {};
let options: gax.CallOptions;
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
} else {
options = optionsOrCallback as gax.CallOptions;
options = optionsOrCallback as CallOptions;
}
options = options || {};
this.initialize();
Expand Down
Loading

0 comments on commit ab61876

Please sign in to comment.