forked from googleapis/google-cloud-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo_intelligence_service_client.js
More file actions
290 lines (267 loc) · 11 KB
/
Copy pathvideo_intelligence_service_client.js
File metadata and controls
290 lines (267 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*
* Copyright 2017, Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* EDITING INSTRUCTIONS
* This file was generated from the file
* https://github.com/googleapis/googleapis/blob/master/google/cloud/videointelligence/v1beta2/video_intelligence.proto,
* and updates to that file get reflected here through a refresh process.
* For the short term, the refresh process will only be runnable by Google
* engineers.
*
* The only allowed edits are to method and file documentation. A 3-way
* merge preserves those additions if the generated source changes.
*/
/* TODO: introduce line-wrapping so that it never exceeds the limit. */
/* jscs: disable maximumLineLength */
'use strict';
var configData = require('./video_intelligence_service_client_config');
var extend = require('extend');
var gax = require('google-gax');
var googleProtoFiles = require('google-proto-files');
var path = require('path');
var protobuf = require('protobufjs');
var SERVICE_ADDRESS = 'videointelligence.googleapis.com';
var DEFAULT_SERVICE_PORT = 443;
var CODE_GEN_NAME_VERSION = 'gapic/0.0.5';
/**
* The scopes needed to make gRPC calls to all of the methods defined in
* this service.
*/
var ALL_SCOPES = [
'https://www.googleapis.com/auth/cloud-platform'
];
/**
* Service that implements Google Cloud Video Intelligence API.
*
*
* @class
*/
function VideoIntelligenceServiceClient(gaxGrpc, loadedProtos, opts) {
opts = extend({
servicePath: SERVICE_ADDRESS,
port: DEFAULT_SERVICE_PORT,
clientConfig: {}
}, opts);
var googleApiClient = [
'gl-node/' + process.versions.node
];
if (opts.libName && opts.libVersion) {
googleApiClient.push(opts.libName + '/' + opts.libVersion);
}
googleApiClient.push(
CODE_GEN_NAME_VERSION,
'gax/' + gax.version,
'grpc/' + gaxGrpc.grpcVersion
);
this.operationsClient = new gax.lro({
auth: gaxGrpc.auth,
grpc: gaxGrpc.grpc
}).operationsClient(opts);
var protoFilesRoot = new gax.grpc.GoogleProtoFilesRoot();
protoFilesRoot = protobuf.loadSync(
path.join(__dirname, '..', '..', 'protos', 'google/cloud/videointelligence/v1beta2/video_intelligence.proto'),
protoFilesRoot);
var annotateVideoResponse = protoFilesRoot.lookup('google.cloud.videointelligence.v1beta2.AnnotateVideoResponse');
var annotateVideoMetadata = protoFilesRoot.lookup('google.cloud.videointelligence.v1beta2.AnnotateVideoProgress');
this.longrunningDescriptors = {
annotateVideo: new gax.LongrunningDescriptor(
this.operationsClient,
annotateVideoResponse.decode.bind(annotateVideoResponse),
annotateVideoMetadata.decode.bind(annotateVideoMetadata))
};
var defaults = gaxGrpc.constructSettings(
'google.cloud.videointelligence.v1beta2.VideoIntelligenceService',
configData,
opts.clientConfig,
{'x-goog-api-client': googleApiClient.join(' ')});
var self = this;
this.auth = gaxGrpc.auth;
var videoIntelligenceServiceStub = gaxGrpc.createStub(
loadedProtos.google.cloud.videointelligence.v1beta2.VideoIntelligenceService,
opts);
var videoIntelligenceServiceStubMethods = [
'annotateVideo'
];
videoIntelligenceServiceStubMethods.forEach(function(methodName) {
self['_' + methodName] = gax.createApiCall(
videoIntelligenceServiceStub.then(function(videoIntelligenceServiceStub) {
return function() {
var args = Array.prototype.slice.call(arguments, 0);
return videoIntelligenceServiceStub[methodName].apply(videoIntelligenceServiceStub, args);
};
}),
defaults[methodName],
self.longrunningDescriptors[methodName]);
});
}
/**
* Get the project ID used by this class.
* @param {function(Error, string)} callback - the callback to be called with
* the current project Id.
*/
VideoIntelligenceServiceClient.prototype.getProjectId = function(callback) {
return this.auth.getProjectId(callback);
};
// Service calls
/**
* Performs asynchronous video annotation. Progress and results can be
* retrieved through the `google.longrunning.Operations` interface.
* `Operation.metadata` contains `AnnotateVideoProgress` (progress).
* `Operation.response` contains `AnnotateVideoResponse` (results).
*
* @param {Object} request
* The request object that will be sent.
* @param {string=} request.inputUri
* Input video location. Currently, only
* [Google Cloud Storage](https://cloud.google.com/storage/) URIs are
* supported, which must be specified in the following format:
* `gs://bucket-id/object-id` (other URI formats return
* {@link google.rpc.Code.INVALID_ARGUMENT}). For more information, see
* [Request URIs](https://cloud.google.com/storage/docs/reference-uris).
* A video URI may include wildcards in `object-id`, and thus identify
* multiple videos. Supported wildcards: '*' to match 0 or more characters;
* '?' to match 1 character. If unset, the input video should be embedded
* in the request as `input_content`. If set, `input_content` should be unset.
* @param {string=} request.inputContent
* The video data bytes. Encoding: base64. If unset, the input video(s)
* should be specified via `input_uri`. If set, `input_uri` should be unset.
* @param {number[]=} request.features
* Requested video annotation features.
*
* The number should be among the values of [Feature]{@link Feature}
* @param {Object=} request.videoContext
* Additional video context and/or feature-specific parameters.
*
* This object should have the same structure as [VideoContext]{@link VideoContext}
* @param {string=} request.outputUri
* Optional location where the output (in JSON format) should be stored.
* Currently, only [Google Cloud Storage](https://cloud.google.com/storage/)
* URIs are supported, which must be specified in the following format:
* `gs://bucket-id/object-id` (other URI formats return
* {@link google.rpc.Code.INVALID_ARGUMENT}). For more information, see
* [Request URIs](https://cloud.google.com/storage/docs/reference-uris).
* @param {string=} request.locationId
* Optional cloud region where annotation should take place. Supported cloud
* regions: `us-east1`, `us-west1`, `europe-west1`, `asia-east1`. If no region
* is specified, a region will be determined based on video file location.
* @param {Object=} options
* Optional parameters. You can override the default settings for this call, e.g, timeout,
* retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details.
* @param {function(?Error, ?Object)=} callback
* The function which will be called with the result of the API call.
*
* The second parameter to the callback is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
* @return {Promise} - The promise which resolves to an array.
* The first element of the array is a [gax.Operation]{@link https://googleapis.github.io/gax-nodejs/Operation} object.
* The promise has a method named "cancel" which cancels the ongoing API call.
*
* @example
*
* var videoIntelligence = require('@google-cloud/video-intelligence');
*
* var client = videoIntelligence.v1beta2({
* // optional auth parameters.
* });
*
*
*
* // Handle the operation using the promise pattern.
* client.annotateVideo({}).then(function(responses) {
* var operation = responses[0];
* var initialApiResponse = responses[1];
*
* // Operation#promise starts polling for the completion of the LRO.
* return operation.promise();
* }).then(function(responses) {
* // The final result of the operation.
* var result = responses[0];
*
* // The metadata value of the completed operation.
* var metadata = responses[1];
*
* // The response of the api call returning the complete operation.
* var finalApiResponse = responses[2];
* })
* .catch(function(err) {
* console.error(err);
* });
*
*
*
* // Handle the operation using the event emitter pattern.
* client.annotateVideo({}).then(function(responses) {
* var operation = responses[0];
* var initialApiResponse = responses[1];
*
* // Adding a listener for the "complete" event starts polling for the
* // completion of the operation.
* operation.on('complete', function(result, metadata, finalApiResponse) {
* // doSomethingWith(result);
* });
*
* // Adding a listener for the "progress" event causes the callback to be
* // called on any change in metadata when the operation is polled.
* operation.on('progress', function(metadata, apiResponse) {
* // doSomethingWith(metadata)
* })
*
* // Adding a listener for the "error" event handles any errors found during polling.
* operation.on('error', function(err) {
* // throw(err);
* })
* })
* .catch(function(err) {
* console.error(err);
* });
*/
VideoIntelligenceServiceClient.prototype.annotateVideo = function(request, options, callback) {
if (options instanceof Function && callback === undefined) {
callback = options;
options = {};
}
if (options === undefined) {
options = {};
}
return this._annotateVideo(request, options, callback);
};
function VideoIntelligenceServiceClientBuilder(gaxGrpc) {
if (!(this instanceof VideoIntelligenceServiceClientBuilder)) {
return new VideoIntelligenceServiceClientBuilder(gaxGrpc);
}
var videoIntelligenceServiceStubProtos = gaxGrpc.loadProto(
path.join(__dirname, '..', '..', 'protos'), 'google/cloud/videointelligence/v1beta2/video_intelligence.proto');
extend(this, videoIntelligenceServiceStubProtos.google.cloud.videointelligence.v1beta2);
/**
* Build a new instance of {@link VideoIntelligenceServiceClient}.
*
* @param {Object=} opts - The optional parameters.
* @param {String=} opts.servicePath
* The domain name of the API remote host.
* @param {number=} opts.port
* The port on which to connect to the remote host.
* @param {grpc.ClientCredentials=} opts.sslCreds
* A ClientCredentials for use with an SSL-enabled channel.
* @param {Object=} opts.clientConfig
* The customized config to build the call settings. See
* {@link gax.constructSettings} for the format.
*/
this.videoIntelligenceServiceClient = function(opts) {
return new VideoIntelligenceServiceClient(gaxGrpc, videoIntelligenceServiceStubProtos, opts);
};
extend(this.videoIntelligenceServiceClient, VideoIntelligenceServiceClient);
}
module.exports = VideoIntelligenceServiceClientBuilder;
module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS;
module.exports.ALL_SCOPES = ALL_SCOPES;