diff --git a/javascript/net/grpc/web/generictransportinterface.js b/javascript/net/grpc/web/generictransportinterface.js index d73aae2c..790c45d9 100644 --- a/javascript/net/grpc/web/generictransportinterface.js +++ b/javascript/net/grpc/web/generictransportinterface.js @@ -16,13 +16,10 @@ * */ /** - * @fileoverview gRPC web client Readable Stream + * @fileoverview gRPC-Web generic transport interface * - * This class is being returned after a gRPC streaming call has been - * started. This class provides functionality for user to operates on - * the stream, e.g. set onData callback, etc. - * - * This wraps the underlying goog.net.streams.NodeReadableStream + * This class provides an abstraction for the underlying transport + * implementation underneath the ClientReadableStream layer. * * @author stanleycheung@google.com (Stanley Cheung) */ diff --git a/javascript/net/grpc/web/interceptor.js b/javascript/net/grpc/web/interceptor.js index 46d6a00c..44e044d7 100644 --- a/javascript/net/grpc/web/interceptor.js +++ b/javascript/net/grpc/web/interceptor.js @@ -1,5 +1,13 @@ /** - * @fileoverview grpc-web Interceptor. + * @fileoverview grpc-web client interceptors. + * + * The type of interceptors is determined by the response type of the RPC call. + * gRPC-Web has two generated clients for one service: + * FooServiceClient and FooServicePromiseClient. The response type of + * FooServiceClient is ClientReadableStream for BOTH unary calls and server + * streaming calls, so StreamInterceptor is expected to be used for intercepting + * FooServiceClient calls. The response type of PromiseClient is Promise, so use + * UnaryInterceptor for PromiseClients. */ goog.module('grpc.web.Interceptor'); @@ -11,6 +19,18 @@ const Request = goog.require('grpc.web.Request'); const UnaryResponse = goog.require('grpc.web.UnaryResponse'); /** + * Interceptor for RPC calls with response type `UnaryResponse`. + * An example implementation of UnaryInterceptor + *
+ * TestUnaryInterceptor.prototype.intercept = function(request, invoker) {
+ *   const newRequest = ...
+ *   return invoker(newRequest).then((response) => {
+ *     // Do something with response.getMetadata
+       // Do something with response.getResponseMessage
+ *     return response;
+ *   });
+ * };
+ * 
* @interface */ const UnaryInterceptor = function() {}; @@ -28,6 +48,14 @@ UnaryInterceptor.prototype.intercept = function(request, invoker) {}; /** + * Interceptor for RPC calls with response type `ClientReadableStream`. + * + * Two steps to create a stream interceptor: + * <1>Create a new subclass of ClientReadableStream that wraps around the + * original stream and overrides its methods. <2>Create a new subclass of + * StreamInterceptor. While implementing the + * StreamInterceptor.prototype.intercept method, return the wrapped + * ClientReadableStream. * @interface */ const StreamInterceptor = function() {};