Action Engine
Loading...
Searching...
No Matches
server.h
Go to the documentation of this file.
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ACTIONENGINE_NET_WEBRTC_SERVER_H_
16#define ACTIONENGINE_NET_WEBRTC_SERVER_H_
17
18#include <cstdint>
19#include <memory>
20#include <optional>
21#include <string>
22#include <string_view>
23
24#include <absl/base/nullability.h>
25#include <absl/base/thread_annotations.h>
26#include <absl/container/flat_hash_map.h>
27#include <absl/status/status.h>
28
31#include "actionengine/net/webrtc/wire_stream.h"
32#include "actionengine/service/service.h"
33
47
48namespace act::net {
49
74 public:
105 explicit WebRtcServer(act::Service* absl_nonnull service,
106 std::string_view address = "0.0.0.0",
107 uint16_t port = 20000,
108 std::string_view signalling_address = "localhost",
109 uint16_t signalling_port = 80,
110 std::string_view signalling_identity = "server",
111 std::optional<RtcConfig> rtc_config = std::nullopt);
112
114
127 void Run();
128
140 absl::Status Cancel();
141
151 absl::Status Join();
152
153 private:
154 using DataChannelConnectionMap =
155 absl::flat_hash_map<std::string, WebRtcDataChannelConnection>;
156 void RunLoop() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
157
158 absl::Status CancelInternal() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
159 absl::Status JoinInternal() ABSL_EXCLUSIVE_LOCKS_REQUIRED(mu_);
160
161 std::shared_ptr<SignallingClient> InitSignallingClient(
162 std::string_view signalling_address, uint16_t signalling_port,
163 DataChannelConnectionMap* absl_nonnull connections);
164
165 act::Service* absl_nonnull const service_;
166
167 const std::string address_;
168 const uint16_t port_;
169 const std::string signalling_address_;
170 const uint16_t signalling_port_;
171 const std::string signalling_identity_;
172 const std::optional<RtcConfig> rtc_config_;
173
175 ready_data_connections_;
176 act::Mutex mu_;
177 std::unique_ptr<thread::Fiber> main_loop_;
178};
179
180} // namespace act::net
181
182#endif // ACTIONENGINE_NET_WEBRTC_SERVER_H_
Concurrency utilities for ActionEngine.
Definition service.h:131
void Run()
Definition server.cc:68
absl::Status Join()
Definition server.cc:81
WebRtcServer(act::Service *absl_nonnull service, std::string_view address="0.0.0.0", uint16_t port=20000, std::string_view signalling_address="localhost", uint16_t signalling_port=80, std::string_view signalling_identity="server", std::optional< RtcConfig > rtc_config=std::nullopt)
Definition server.cc:47
absl::Status Cancel()
Definition server.cc:76
A Channel is a bounded FIFO queue that allows multiple readers and writers to communicate with each o...
Definition channel.h:278