1 /*
2  * Copyright (C) 2022 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 
17 #pragma once
18 
19 #include <functional>
20 #include <memory>
21 
22 #include <api/data_channel_interface.h>
23 
24 #include "host/frontend/webrtc/libdevice/connection_observer.h"
25 
26 namespace cuttlefish {
27 namespace webrtc_streaming {
28 
29 constexpr auto kControlChannelLabel = "device-control";
30 
31 class DataChannelHandler;
32 
33 // Groups all data channel handlers.
34 // Each handler is an implementation of the DataChannelHandler abstract class
35 // providing custom message handlers and calling the appropriate methods on the
36 // connection observer.
37 class DataChannelHandlers {
38  public:
39   DataChannelHandlers(std::shared_ptr<ConnectionObserver> observer);
40   ~DataChannelHandlers();
41 
42   void OnDataChannelOpen(
43       rtc::scoped_refptr<webrtc::DataChannelInterface> channel);
44 
45  private:
46   std::unique_ptr<DataChannelHandler> input_;
47   std::unique_ptr<DataChannelHandler> control_;
48   std::unique_ptr<DataChannelHandler> adb_;
49   std::unique_ptr<DataChannelHandler> bluetooth_;
50   std::unique_ptr<DataChannelHandler> camera_;
51   std::unique_ptr<DataChannelHandler> sensors_;
52   std::unique_ptr<DataChannelHandler> lights_;
53   std::unique_ptr<DataChannelHandler> location_;
54   std::unique_ptr<DataChannelHandler> kml_location_;
55   std::unique_ptr<DataChannelHandler> gpx_location_;
56   std::vector<std::unique_ptr<DataChannelHandler>> unknown_channels_;
57 
58   std::shared_ptr<ConnectionObserver> observer_;
59 };
60 
61 }  // namespace webrtc_streaming
62 }  // namespace cuttlefish
63