Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
fix(browser): check for fetch on window
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshi-automation authored Nov 23, 2020
1 parent f58a09e commit c0245c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
18 changes: 13 additions & 5 deletions src/v1beta1/speech_translation_service_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
// ** 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, CallOptions, Descriptors, ClientOptions} from 'google-gax';
import * as path from 'path';

import * as protos from '../../protos/protos';
/**
* Client JSON configuration object, loaded from
* `src/v1beta1/speech_translation_service_client_config.json`.
* This file defines retry strategy and timeouts for all API methods in this library.
*/
import * as gapicConfig from './speech_translation_service_client_config.json';

const version = require('../../../package.json').version;
Expand Down Expand Up @@ -73,9 +79,9 @@ export class SpeechTranslationServiceClient {
* 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 @@ -89,7 +95,9 @@ export class SpeechTranslationServiceClient {
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 @@ -301,7 +309,7 @@ export class SpeechTranslationServiceClient {
* stream.write(request);
* stream.end();
*/
streamingTranslateSpeech(options?: gax.CallOptions): gax.CancellableStream {
streamingTranslateSpeech(options?: CallOptions): gax.CancellableStream {
this.initialize();
return this.innerApiCalls.streamingTranslateSpeech(options);
}
Expand Down
14 changes: 10 additions & 4 deletions synth.metadata
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
{
"git": {
"name": ".",
"remote": "git@github.com:googleapis/nodejs-media-translation.git",
"sha": "f132c7b2725509ef3d4d497733ba85f851b52789"
"remote": "https://github.com/googleapis/nodejs-media-translation.git",
"sha": "f58a09e23452b1407079078809d079b2c31775f4"
}
},
{
"git": {
"name": "googleapis",
"remote": "https://github.com/googleapis/googleapis.git",
"sha": "2f019bf70bfe06f1e2af1b04011b0a2405190e43",
"internalRef": "343202295"
}
},
{
Expand Down Expand Up @@ -78,14 +86,12 @@
"LICENSE",
"README.md",
"api-extractor.json",
"package-lock.json.3635725974",
"protos/google/cloud/mediatranslation/v1beta1/media_translation.proto",
"protos/protos.d.ts",
"protos/protos.js",
"protos/protos.json",
"renovate.json",
"samples/README.md",
"samples/package-lock.json.3114264012",
"src/index.ts",
"src/v1beta1/index.ts",
"src/v1beta1/speech_translation_service_client.ts",
Expand Down

0 comments on commit c0245c5

Please sign in to comment.