blob: f1be2d9f973a805c46ffbebcefadf44c451588a7 [file] [log] [blame]
Yuwei Huang5a84f9532019-02-20 18:29:011// 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 Huang575c32ee2019-02-27 04:41:566#include "base/bind.h"
Yuwei Huang5a84f9532019-02-20 18:29:017#include "base/command_line.h"
Yuwei Huang5a84f9532019-02-20 18:29:018#include "base/logging.h"
Yuwei Huang575c32ee2019-02-27 04:41:569#include "base/macros.h"
10#include "base/message_loop/message_loop.h"
11#include "base/run_loop.h"
Yuwei Huang5a84f9532019-02-20 18:29:0112#include "remoting/signaling/ftl_client.h"
13
Yuwei Huang575c32ee2019-02-27 04:41:5614namespace remoting {
Yuwei Huang5a84f9532019-02-20 18:29:0115
Yuwei Huang575c32ee2019-02-27 04:41:5616class FtlSignalingPlayground {
17 public:
18 FtlSignalingPlayground();
19 ~FtlSignalingPlayground();
Yuwei Huang5a84f9532019-02-20 18:29:0120
Yuwei Huang575c32ee2019-02-27 04:41:5621 void GetIceServer(base::OnceClosure on_done);
Yuwei Huang5a84f9532019-02-20 18:29:0122
Yuwei Huang575c32ee2019-02-27 04:41:5623 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
32FtlSignalingPlayground::FtlSignalingPlayground() = default;
33
34FtlSignalingPlayground::~FtlSignalingPlayground() = default;
35
36void 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
43void 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 Huang5a84f9532019-02-20 18:29:0162 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 Huang5a84f9532019-02-20 18:29:0170 }
Yuwei Huang575c32ee2019-02-27 04:41:5671 std::move(on_done).Run();
72}
Yuwei Huang5a84f9532019-02-20 18:29:0173
Yuwei Huang575c32ee2019-02-27 04:41:5674} // namespace remoting
75
76int 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 Huang5a84f9532019-02-20 18:29:0187 return 0;
88}