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 #pragma once 17 18 #include <memory> 19 #include <string> 20 21 #include <json/json.h> 22 23 #include "host/frontend/webrtc_operator/device_registry.h" 24 #include "host/frontend/webrtc_operator/server_config.h" 25 #include "host/libs/websocket/websocket_handler.h" 26 27 namespace cuttlefish { 28 29 class SignalHandler : public WebSocketHandler { 30 public: 31 void OnReceive(const uint8_t* msg, size_t len, bool binary) override; 32 void OnReceive(const uint8_t* msg, size_t len, bool binary, 33 bool is_final) override; 34 void OnConnected() override; 35 protected: 36 SignalHandler(struct lws* wsi, DeviceRegistry* registry, 37 const ServerConfig& server_config); 38 39 virtual void handleMessage(const std::string& message_type, 40 const Json::Value& message) = 0; 41 void SendServerConfig(); 42 43 void LogAndReplyError(const std::string& message); 44 void Reply(const Json::Value& json); 45 46 DeviceRegistry* registry_; 47 const ServerConfig& server_config_; 48 std::vector<uint8_t> receive_buffer_; 49 }; 50 } // namespace cuttlefish 51