-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrpc.js
49 lines (45 loc) · 1.21 KB
/
grpc.js
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
/**
* Created by orian on 19.06.15.
*/
goog.provide('orian.grpc.Client');
goog.require('goog.net.XhrIo');
/**
* A gRPC service client.
* @param {String} baseUrl base url, e.g. /api
* @param {String} service name.
* @constructor
* @final
*/
orian.grpc.Client = function (baseUrl, service) {
/**
*
* @type {String}
* @private
*/
this.baseUrl_ = baseUrl;
/**
*
* @type {String}
* @private
*/
this.service_ = service;
};
orian.grpc.Client.prototype.apiCall_ = function(method, arg, success, failure, requestConstructor, responseConstructor) {
var url = this.baseUrl_ + '/' + this.service_ + '/' + method;
if (requestConstructor && arg instanceof requestConstructor) {
console.log("Proto not supported yet.");
console.error("Proto not supported yet.");
} else {
var data = JSON.stringify(arg);
var callback = function(e) {
if (e.target.isSuccess()) {
if (success) {
success(e.target.getResponseJson());
}
} else if (failure) {
failure(e);
}
};
goog.net.XhrIo.send(url, callback, 'POST', data, null, 30);
}
};