Yuwei Huang | 5a84f953 | 2019-02-20 18:29:01 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/at_exit.h" |
Yuwei Huang | 575c32ee | 2019-02-27 04:41:56 | [diff] [blame] | 6 | #include "base/bind.h" |
Yuwei Huang | 5a84f953 | 2019-02-20 18:29:01 | [diff] [blame] | 7 | #include "base/command_line.h" |
Yuwei Huang | 5a84f953 | 2019-02-20 18:29:01 | [diff] [blame] | 8 | #include "base/logging.h" |
Yuwei Huang | 575c32ee | 2019-02-27 04:41:56 | [diff] [blame] | 9 | #include "base/macros.h" |
| 10 | #include "base/message_loop/message_loop.h" |
| 11 | #include "base/run_loop.h" |
Yuwei Huang | 5a84f953 | 2019-02-20 18:29:01 | [diff] [blame] | 12 | #include "remoting/signaling/ftl_client.h" |
| 13 | |
Yuwei Huang | 575c32ee | 2019-02-27 04:41:56 | [diff] [blame] | 14 | namespace remoting { |
Yuwei Huang | 5a84f953 | 2019-02-20 18:29:01 | [diff] [blame] | 15 | |
Yuwei Huang | 575c32ee | 2019-02-27 04:41:56 | [diff] [blame] | 16 | class FtlSignalingPlayground { |
| 17 | public: |
| 18 | FtlSignalingPlayground(); |
| 19 | ~FtlSignalingPlayground(); |
Yuwei Huang | 5a84f953 | 2019-02-20 18:29:01 | [diff] [blame] | 20 | |
Yuwei Huang | 575c32ee | 2019-02-27 04:41:56 | [diff] [blame] | 21 | void GetIceServer(base::OnceClosure on_done); |
Yuwei Huang | 5a84f953 | 2019-02-20 18:29:01 | [diff] [blame] | 22 | |
Yuwei Huang | 575c32ee | 2019-02-27 04:41:56 | [diff] [blame] | 23 | private: |
| 24 | static void OnGetIceServerResponse(base::OnceClosure on_done, |
| 25 | grpc::Status status, |
| 26 | const ftl::GetICEServerResponse& response); |
| 27 | |
| 28 | FtlClient client_; |
| 29 | DISALLOW_COPY_AND_ASSIGN(FtlSignalingPlayground); |
| 30 | }; |
| 31 | |
| 32 | FtlSignalingPlayground::FtlSignalingPlayground() = default; |
| 33 | |
| 34 | FtlSignalingPlayground::~FtlSignalingPlayground() = default; |
| 35 | |
| 36 | void FtlSignalingPlayground::GetIceServer(base::OnceClosure on_done) { |
| 37 | client_.GetIceServer(base::BindOnce( |
| 38 | &FtlSignalingPlayground::OnGetIceServerResponse, std::move(on_done))); |
| 39 | VLOG(0) << "Running GetIceServer..."; |
| 40 | } |
| 41 | |
| 42 | // static |
| 43 | void FtlSignalingPlayground::OnGetIceServerResponse( |
| 44 | base::OnceClosure on_done, |
| 45 | grpc::Status status, |
| 46 | const ftl::GetICEServerResponse& response) { |
| 47 | if (status.ok()) { |
| 48 | VLOG(0) << "Ice transport policy: " |
| 49 | << response.ice_config().ice_transport_policy(); |
| 50 | for (const ftl::ICEServerList& server : |
| 51 | response.ice_config().ice_servers()) { |
| 52 | VLOG(0) << "ICE server:"; |
| 53 | VLOG(0) << " hostname=" << server.hostname(); |
| 54 | VLOG(0) << " username=" << server.username(); |
| 55 | VLOG(0) << " credential=" << server.credential(); |
| 56 | VLOG(0) << " max_rate_kbps=" << server.max_rate_kbps(); |
| 57 | for (const std::string& url : server.urls()) { |
| 58 | VLOG(0) << " url=" << url; |
| 59 | } |
| 60 | } |
| 61 | } else { |
Yuwei Huang | 5a84f953 | 2019-02-20 18:29:01 | [diff] [blame] | 62 | LOG(ERROR) << "RPC failed. Code=" << status.error_code() << ", " |
| 63 | << "Message=" << status.error_message(); |
| 64 | if (status.error_code() == grpc::StatusCode::UNAVAILABLE) { |
| 65 | VLOG(0) |
| 66 | << "Set the GRPC_DEFAULT_SSL_ROOTS_FILE_PATH environment variable " |
| 67 | << "to third_party/grpc/src/etc/roots.pem if gRPC cannot locate the " |
| 68 | << "root certificates."; |
| 69 | } |
Yuwei Huang | 5a84f953 | 2019-02-20 18:29:01 | [diff] [blame] | 70 | } |
Yuwei Huang | 575c32ee | 2019-02-27 04:41:56 | [diff] [blame] | 71 | std::move(on_done).Run(); |
| 72 | } |
Yuwei Huang | 5a84f953 | 2019-02-20 18:29:01 | [diff] [blame] | 73 | |
Yuwei Huang | 575c32ee | 2019-02-27 04:41:56 | [diff] [blame] | 74 | } // namespace remoting |
| 75 | |
| 76 | int main(int argc, char const* argv[]) { |
| 77 | base::AtExitManager exitManager; |
| 78 | base::CommandLine::Init(argc, argv); |
| 79 | |
| 80 | base::MessageLoopForIO message_loop; |
| 81 | |
| 82 | remoting::FtlSignalingPlayground playground; |
| 83 | base::RunLoop run_loop; |
| 84 | playground.GetIceServer(run_loop.QuitClosure()); |
| 85 | run_loop.Run(); |
| 86 | |
Yuwei Huang | 5a84f953 | 2019-02-20 18:29:01 | [diff] [blame] | 87 | return 0; |
| 88 | } |