• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript grpc-web.grpc类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@improbable-eng/grpc-web.grpc的典型用法代码示例。如果您正苦于以下问题:TypeScript grpc类的具体用法?TypeScript grpc怎么用?TypeScript grpc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了grpc类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: it

          it("should make a bidirectional request that is terminated by the server", (done) => {
            let didGetOnHeaders = false;
            let didGetOnMessage = false;

            let counter = 1;
            let lastMessage = `helloworld:${counter}`;
            const ping = new PingRequest();
            ping.setSendHeaders(withHeaders);
            ping.setSendTrailers(withTrailers);
            ping.setValue(lastMessage);

            const client = grpc.client(TestService.PingPongBidi, {
              debug: DEBUG,
              host: testHostUrl,
              transport: grpc.WebsocketTransport(),
            });
            client.onHeaders((headers: grpc.Metadata) => {
              DEBUG && debug("headers", headers);
              didGetOnHeaders = true;
              if (withHeaders) {
                assert.deepEqual(headers.get("HeaderTestKey1"), ["ServerValue1"]);
                assert.deepEqual(headers.get("HeaderTestKey2"), ["ServerValue2"]);
              }
            });
            client.onMessage((message: PingResponse) => {
              assert.ok(message instanceof PingResponse);
              assert.deepEqual(message.getValue(), lastMessage);

              if (counter === 10) {
                const ping = new PingRequest();
                ping.setFailureType(PingRequest.FailureType.CODE);
                ping.setErrorCodeReturned(grpc.Code.OK);
                client.send(ping);
              } else {
                counter++;
                lastMessage = `helloworld:${counter}`;
                const ping = new PingRequest();
                ping.setValue(lastMessage);
                client.send(ping);
              }
            });
            client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
              DEBUG && debug("status", status, "statusMessage", statusMessage);
              assert.strictEqual(status, grpc.Code.OK, "expected OK (0)");
              assert.strictEqual(statusMessage, "", "expected no message");
              if (withTrailers) {
                assert.deepEqual(trailers.get("TrailerTestKey1"), ["ServerValue1"]);
                assert.deepEqual(trailers.get("TrailerTestKey2"), ["ServerValue2"]);
              }
              assert.ok(didGetOnHeaders, "didGetOnHeaders");

              assert.equal(counter, 10, "counter should have been incremented to 10");
              done();
            });
            client.start();

            // send initial message
            client.send(ping);
          });
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:59,代码来源:client.websocket.spec.ts


示例2: it

        it(`should report status code in Unicode for error with headers + trailers`, (done) => {
          let didGetOnHeaders = false;
          let didGetOnMessage = false;

          const ping = new PingRequest();
          ping.setFailureType(PingRequest.FailureType.CODE_UNICODE);
          ping.setErrorCodeReturned(12);
          ping.setSendHeaders(withHeaders);
          ping.setSendTrailers(withTrailers);

          const client = grpc.client(TestService.PingError, {
            debug: DEBUG,
            transport: transport,
            host: testHostUrl,
          });
          client.onHeaders((headers: grpc.Metadata) => {
            DEBUG && debug("headers", headers);
            didGetOnHeaders = true;
          });
          client.onMessage((message: Empty) => {
            didGetOnMessage = true;
          });
          client.onEnd((status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
            DEBUG && debug("status", status, "statusMessage", statusMessage, "trailers", trailers);
            assert.deepEqual(trailers.get("grpc-status"), ["12"]);
            assert.deepEqual(trailers.get("grpc-message"), [encodeURIComponent("💣")]);
            assert.strictEqual(status, grpc.Code.Unimplemented);
            assert.strictEqual(statusMessage, "💣");
            assert.ok(didGetOnHeaders);
            assert.ok(!didGetOnMessage);
            done();
          });
          client.start();
          client.send(ping);
        });
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:35,代码来源:client.spec.ts


示例3: it

        it("should report status code for error with headers + trailers", (done) => {
          let didGetOnHeaders = false;
          let didGetOnMessage = false;

          const ping = new PingRequest();
          ping.setFailureType(PingRequest.FailureType.CODE);
          ping.setErrorCodeReturned(12);
          ping.setSendHeaders(withHeaders);
          ping.setSendTrailers(withTrailers);

          grpc.invoke(TestService.PingError, {
            debug: DEBUG,
            transport: transport,
            request: ping,
            host: testHostUrl,
            onHeaders: (headers: grpc.Metadata) => {
              DEBUG && debug("headers", headers);
              didGetOnHeaders = true;
            },
            onMessage: (message: Empty) => {
              didGetOnMessage = true;
            },
            onEnd: (status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
              DEBUG && debug("status", status, "statusMessage", statusMessage, "trailers", trailers);
              assert.deepEqual(trailers.get("grpc-status"), ["12"]);
              assert.deepEqual(trailers.get("grpc-message"), ["Intentionally returning error for PingError"]);
              assert.strictEqual(status, grpc.Code.Unimplemented);
              assert.strictEqual(statusMessage, "Intentionally returning error for PingError");
              assert.ok(didGetOnHeaders);
              assert.ok(!didGetOnMessage);
              done();
            }
          });
        });
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:34,代码来源:invoke.spec.ts


示例4: continueStream

            continueStream(testHostUrl, streamIdentifier, (status) => {
              DEBUG && debug("checkAbort.continueStream.status", status);

              const checkStreamClosedRequest = new CheckStreamClosedRequest();
              checkStreamClosedRequest.setStreamIdentifier(streamIdentifier);
              grpc.unary(TestUtilService.CheckStreamClosed, {
                debug: DEBUG,
                request: checkStreamClosedRequest,
                host: testHostUrl,
                onEnd: ({message}) => {
                  const closed = ( message as CheckStreamClosedResponse ).getClosed();
                  DEBUG && debug("closed", closed);
                  if (closed) {
                    done();
                  } else {
                    if (attempt >= maxAbortChecks) {
                      assert.ok(closed, `server did not observe connection closure within ${maxAbortChecks} seconds`);
                      done();
                    } else {
                      setTimeout(() => {
                        checkAbort(attempt + 1);
                      }, 1000);
                    }
                  }
                },
              })
            });
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:27,代码来源:cancellation.spec.ts


示例5: it

      it("should allow the caller to abort an rpc before it completes", () => {
        let transportCancelFuncInvoked = false;

        const cancellationSpyTransport = () => {
          return {
            sendMessage: () => {
            },
            finishSend() {
            },
            start: () => {
            },
            cancel: () => {
              transportCancelFuncInvoked = true;
            },
          }
        };

        const ping = new PingRequest();
        ping.setValue("hello world");

        const reqObj = grpc.invoke(TestService.Ping, {
          debug: DEBUG,
          request: ping,
          host: testHostUrl,
          transport: cancellationSpyTransport,
          onEnd: (status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
          },
        });

        reqObj.close();

        assert.equal(transportCancelFuncInvoked, true, "transport's cancel func must be invoked");
      });
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:33,代码来源:cancellation.spec.ts


示例6: it

        it(`should make a unary request`, (done) => {
          const ping = new PingRequest();
          ping.setValue("hello world");
          ping.setSendHeaders(withHeaders);
          ping.setSendTrailers(withTrailers);

          grpc.unary(TestService.Ping, {
            debug: DEBUG,
            transport: transport,
            request: ping,
            host: testHostUrl,
            onEnd: ({status, statusMessage, headers, message, trailers}) => {
              DEBUG && debug("status", status, "statusMessage", statusMessage, "headers", headers, "res", message, "trailers", trailers);
              assert.strictEqual(status, grpc.Code.OK, "expected OK (0)");
              assert.isNotOk(statusMessage, "expected no message");
              if (withHeaders) {
                assert.deepEqual(headers.get("HeaderTestKey1"), ["ServerValue1"]);
                assert.deepEqual(headers.get("HeaderTestKey2"), ["ServerValue2"]);
              }
              assert.ok(message instanceof PingResponse);
              const asPingResponse: PingResponse = message as PingResponse;
              assert.deepEqual(asPingResponse.getValue(), "hello world");
              assert.deepEqual(asPingResponse.getCounter(), 252);
              if (withTrailers) {
                assert.deepEqual(trailers.get("TrailerTestKey1"), ["ServerValue1"]);
                assert.deepEqual(trailers.get("TrailerTestKey2"), ["ServerValue2"]);
              }
              done();
            }
          });
        });
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:31,代码来源:unary.spec.ts


示例7:

 assert.throw(() => {
   const client = grpc.client(TestService.Ping, {
     debug: DEBUG,
     transport: transport,
     host: testHostUrl,
   });
   client.send(ping);
 }, "Client not started - .start() must be called before .send()");
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:8,代码来源:client.spec.ts


示例8: runWithSupportedTransports

export function runWithSupportedTransports(cb: (transport: grpc.TransportFactory | undefined) => void) {
  const transports: {[key: string]: grpc.TransportFactory | undefined} = {
    "httpTransport": undefined
  };

  if (process.env.BROWSER === "nodejs") {
    grpc.setDefaultTransport(NodeHttpTransport());
  }

  if (!process.env.DISABLE_WEBSOCKET_TESTS) {
    transports["websocketTransport"] = grpc.WebsocketTransport();
  }

  for (let transportName in transports) {
    describe(transportName, () => {
      cb(transports[transportName]);
    })
  }
}
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:19,代码来源:testRpcCombinations.ts


示例9: debug

 assert.throw(() => {
   grpc.unary(TestService.PingStream as any as grpc.UnaryMethodDefinition<PingRequest, PingResponse>, {
     debug: DEBUG,
     transport: transport,
     request: ping,
     host: testHostUrl,
     onEnd: ({status, statusMessage, headers, message, trailers}) => {
       DEBUG && debug("status", status, "statusMessage", statusMessage, "headers", headers, "res", message, "trailers", trailers);
     }
   })
 }, ".unary cannot be used with client-streaming methods. Use .client instead.");
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:11,代码来源:unary.spec.ts


示例10: debug

 assert.throw(() => {
   grpc.invoke(TestService.PingStream, {
     debug: DEBUG,
     transport: transport,
     request: ping,
     host: testHostUrl,
     onHeaders: (headers: grpc.Metadata) => {
       DEBUG && debug("headers", headers);
     },
     onMessage: (message: PingResponse) => {
       DEBUG && debug("message", message);
     },
     onEnd: (status: grpc.Code, statusMessage: string, trailers: grpc.Metadata) => {
       DEBUG && debug("status", status, "statusMessage", statusMessage);
     }
   })
 }, ".invoke cannot be used with client-streaming methods. Use .client instead.");
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:17,代码来源:invoke.spec.ts


示例11: getBook

function getBook() {
  const getBookRequest = new GetBookRequest();
  getBookRequest.setIsbn(60929871);
  grpc.unary(BookService.GetBook, {
    request: getBookRequest,
    host: host,
    onEnd: res => {
      const { status, statusMessage, headers, message, trailers } = res;
      console.log("getBook.onEnd.status", status, statusMessage);
      console.log("getBook.onEnd.headers", headers);
      if (status === grpc.Code.OK && message) {
        console.log("getBook.onEnd.message", message.toObject());
      }
      console.log("getBook.onEnd.trailers", trailers);
      queryBooks();
    }
  });
}
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:18,代码来源:index.ts


示例12: queryBooks

function queryBooks() {
  const queryBooksRequest = new QueryBooksRequest();
  queryBooksRequest.setAuthorPrefix("Geor");
  const client = grpc.client(BookService.QueryBooks, {
    host: host,
  });
  client.onHeaders((headers: grpc.Metadata) => {
    console.log("queryBooks.onHeaders", headers);
  });
  client.onMessage((message: Book) => {
    console.log("queryBooks.onMessage", message.toObject());
  });
  client.onEnd((code: grpc.Code, msg: string, trailers: grpc.Metadata) => {
    console.log("queryBooks.onEnd", code, msg, trailers);
  });
  client.start();
  client.send(queryBooksRequest);
}
开发者ID:mwitkow,项目名称:grpc-browser-compat,代码行数:18,代码来源:index.ts



注:本文中的@improbable-eng/grpc-web.grpc类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript vis.fromFlux函数代码示例发布时间:2022-05-28
下一篇:
TypeScript util.Dispatch类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap