當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript grpc.WebsocketTransport方法代碼示例

本文整理匯總了TypeScript中@improbable-eng/grpc-web.grpc.WebsocketTransport方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript grpc.WebsocketTransport方法的具體用法?TypeScript grpc.WebsocketTransport怎麽用?TypeScript grpc.WebsocketTransport使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@improbable-eng/grpc-web.grpc的用法示例。


在下文中一共展示了grpc.WebsocketTransport方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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


注:本文中的@improbable-eng/grpc-web.grpc.WebsocketTransport方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。