• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2020 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #include <map>
17 #include <string>
18 
19 #include <android-base/logging.h>
20 #include <gflags/gflags.h>
21 
22 #include "host/frontend/webrtc_operator/client_handler.h"
23 #include "host/frontend/webrtc_operator/device_handler.h"
24 #include "host/frontend/webrtc_operator/device_list_handler.h"
25 #include "host/libs/websocket/websocket_handler.h"
26 #include "host/libs/websocket/websocket_server.h"
27 
28 #include "host/libs/config/logging.h"
29 
30 DEFINE_int32(http_server_port, 8443, "The port for the http server.");
31 DEFINE_bool(use_secure_http, true, "Whether to use HTTPS or HTTP.");
32 DEFINE_string(assets_dir, "webrtc",
33               "Directory with location of webpage assets.");
34 DEFINE_string(certs_dir, "webrtc/certs", "Directory to certificates.");
35 DEFINE_string(stun_server, "stun.l.google.com:19302",
36               "host:port of STUN server to use for public address resolution");
37 
38 namespace {
39 
40 constexpr auto kRegisterDeviceUriPath = "/register_device";
41 constexpr auto kConnectClientUriPath = "/connect_client";
42 constexpr auto kListDevicesUriPath = "/list_devices";
43 
44 }  // namespace
45 
main(int argc,char ** argv)46 int main(int argc, char** argv) {
47   cuttlefish::DefaultSubprocessLogging(argv);
48   ::gflags::ParseCommandLineFlags(&argc, &argv, true);
49 
50   cuttlefish::DeviceRegistry device_registry;
51   cuttlefish::ServerConfig server_config({FLAGS_stun_server});
52 
53   cuttlefish::WebSocketServer wss(
54         "webrtc-operator", FLAGS_certs_dir, FLAGS_assets_dir, FLAGS_http_server_port);
55 
56   auto device_handler_factory_p =
57       std::unique_ptr<cuttlefish::WebSocketHandlerFactory>(
58           new cuttlefish::DeviceHandlerFactory(&device_registry, server_config));
59   wss.RegisterHandlerFactory(kRegisterDeviceUriPath, std::move(device_handler_factory_p));
60   auto client_handler_factory_p =
61       std::unique_ptr<cuttlefish::WebSocketHandlerFactory>(
62           new cuttlefish::ClientHandlerFactory(&device_registry, server_config));
63   wss.RegisterHandlerFactory(kConnectClientUriPath, std::move(client_handler_factory_p));
64   auto device_list_handler_factory_p =
65       std::unique_ptr<cuttlefish::WebSocketHandlerFactory>(
66           new cuttlefish::DeviceListHandlerFactory(device_registry));
67   wss.RegisterHandlerFactory(kListDevicesUriPath, std::move(device_list_handler_factory_p));
68 
69   wss.Serve();
70   return 0;
71 }
72