1 /* 2 * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 #ifndef RTC_TOOLS_DATA_CHANNEL_BENCHMARK_GRPC_SIGNALING_H_ 11 #define RTC_TOOLS_DATA_CHANNEL_BENCHMARK_GRPC_SIGNALING_H_ 12 13 #include <memory> 14 #include <string> 15 16 #include "api/jsep.h" 17 #include "rtc_tools/data_channel_benchmark/signaling_interface.h" 18 19 namespace webrtc { 20 21 // This class defines a server enabling clients to perform a PeerConnection 22 // negotiation directly over gRPC. 23 // When a client connects, a callback is run to handle the request. 24 class GrpcSignalingServerInterface { 25 public: 26 virtual ~GrpcSignalingServerInterface() = default; 27 28 // Start listening for connections. 29 virtual void Start() = 0; 30 31 // Wait for the gRPC server to terminate. 32 virtual void Wait() = 0; 33 34 // Stop the gRPC server instance. 35 virtual void Stop() = 0; 36 37 // The port the server is listening on. 38 virtual int SelectedPort() = 0; 39 40 // Create a gRPC server listening on |port| that will run |callback| on each 41 // request. If |oneshot| is true, it will terminate after serving one request. 42 static std::unique_ptr<GrpcSignalingServerInterface> Create( 43 std::function<void(webrtc::SignalingInterface*)> callback, 44 int port, 45 bool oneshot); 46 }; 47 48 // This class defines a client that can connect to a server and perform a 49 // PeerConnection negotiation directly over gRPC. 50 class GrpcSignalingClientInterface { 51 public: 52 virtual ~GrpcSignalingClientInterface() = default; 53 54 // Connect the client to the gRPC server. 55 virtual bool Start() = 0; 56 virtual webrtc::SignalingInterface* signaling_client() = 0; 57 58 // Create a client to connnect to a server at |server_address|. 59 static std::unique_ptr<GrpcSignalingClientInterface> Create( 60 const std::string& server_address); 61 }; 62 63 } // namespace webrtc 64 #endif // RTC_TOOLS_DATA_CHANNEL_BENCHMARK_GRPC_SIGNALING_H_ 65