Skip to content

Commit

Permalink
SoraSignalingConfig に forwarding_filters を追加
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Oct 28, 2024
1 parent 12a337a commit 34a19c9
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 16 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
- @melpon
- [ADD] SoraSignalingConfig::DataChennel に header を追加
- @melpon
- [ADD] SoraSignalingConfig::ForwardingFilter に name と priority を追加
- @melpon
- [ADD] SoraSignalingConfig に forwarding_filters を追加
- @melpon
- [FIX] HTTP Proxy 利用時の Websocket 初期化で insecure_ メンバ変数が初期化されていなかったのを修正
- @melpon
- [FIX] SoraSignalingConfig の client_cert と client_key に渡す必要がある値を、ファイルパスからファイルの内容に修正
Expand Down
5 changes: 4 additions & 1 deletion include/sora/sora_signaling.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ struct SoraSignalingConfig {
std::vector<DataChannel> data_channels;

struct ForwardingFilter {
std::optional<std::string> name;
std::optional<int> priority;
boost::optional<std::string> action;
struct Rule {
std::string field;
Expand All @@ -134,7 +136,8 @@ struct SoraSignalingConfig {
boost::optional<std::string> version;
boost::optional<boost::json::value> metadata;
};
boost::optional<ForwardingFilter> forwarding_filter;
std::optional<ForwardingFilter> forwarding_filter;
std::optional<std::vector<ForwardingFilter>> forwarding_filters;

std::optional<std::string> client_cert;
std::optional<std::string> client_key;
Expand Down
23 changes: 20 additions & 3 deletions src/sora_signaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,14 @@ void SoraSignaling::DoSendConnect(bool redirect) {
m["data_channels"] = ar;
}

if (config_.forwarding_filter) {
auto forwarding_filter_to_json = [](const SoraSignalingConfig::ForwardingFilter& f) -> boost::json::value {
boost::json::object obj;
auto& f = *config_.forwarding_filter;
if (f.name) {
obj["name"] = *f.name;
}
if (f.priority) {
obj["priority"] = *f.priority;
}
if (f.action) {
obj["action"] = *f.action;
}
Expand All @@ -417,7 +422,19 @@ void SoraSignaling::DoSendConnect(bool redirect) {
if (f.metadata) {
obj["metadata"] = *f.metadata;
}
m["forwarding_filter"] = obj;
return obj;
};

if (config_.forwarding_filter) {
m["forwarding_filter"] = forwarding_filter_to_json(*config_.forwarding_filter);
}

if (config_.forwarding_filters) {
boost::json::array ar;
for (const auto& f : *config_.forwarding_filters) {
ar.push_back(forwarding_filter_to_json(f));
}
m["forwarding_filters"] = ar;
}

std::string text = boost::json::serialize(m);
Expand Down
35 changes: 35 additions & 0 deletions test/.testparam.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,41 @@
// ],
"data_channels": null,

// "forwarding_filters": [{
// "name": "client-id-carol-block",
// "priority": 0,
// "action": "allow",
// "rules": [
// [
// {
// "field": "client_id",
// "operator": "is_in",
// "values": [
// "carol",
// ]
// }
// ]
// ]
// }, {
// "name": "default",
// "priority": 32767,
// "action": "block",
// "rules": [
// [
// {
// "field": "kind",
// "operator": "is_in",
// "values": [
// "audio",
// "video",
// ]
// }
// ]
// ]
// },
// ],
"forwarding_filters": null,

// 0 - verbose
// 1 - info
// 2 - warning
Expand Down
63 changes: 51 additions & 12 deletions test/hello.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ void HelloSora::Run() {
if (!config_.data_channels.empty()) {
config.data_channels = config_.data_channels;
}
if (!config_.forwarding_filters.empty()) {
config.forwarding_filters = config_.forwarding_filters;
}
conn_ = sora::SoraSignaling::Create(config);

boost::asio::executor_work_guard<boost::asio::io_context::executor_type>
Expand Down Expand Up @@ -196,27 +199,63 @@ int main(int argc, char* argv[]) {
sora::SoraSignalingConfig::DataChannel data_channel;
data_channel.label = dc.as_object().at("label").as_string();
data_channel.direction = dc.as_object().at("direction").as_string();
if (get(dc, "ordered", x)) {
data_channel.ordered = x.as_bool();
boost::json::value y;
if (get(dc, "ordered", y)) {
data_channel.ordered = y.as_bool();
}
if (get(dc, "max_packet_life_time", x)) {
data_channel.max_packet_life_time = x.to_number<int32_t>();
if (get(dc, "max_packet_life_time", y)) {
data_channel.max_packet_life_time = y.to_number<int32_t>();
}
if (get(dc, "max_retransmits", x)) {
data_channel.max_retransmits = x.to_number<int32_t>();
if (get(dc, "max_retransmits", y)) {
data_channel.max_retransmits = y.to_number<int32_t>();
}
if (get(dc, "protocol", x)) {
data_channel.protocol = x.as_string().c_str();
if (get(dc, "protocol", y)) {
data_channel.protocol = y.as_string().c_str();
}
if (get(dc, "compress", x)) {
data_channel.compress = x.as_bool();
if (get(dc, "compress", y)) {
data_channel.compress = y.as_bool();
}
if (get(dc, "header", x)) {
data_channel.header.emplace(x.as_array().begin(), x.as_array().end());
if (get(dc, "header", y)) {
data_channel.header.emplace(y.as_array().begin(), y.as_array().end());
}
config.data_channels.push_back(data_channel);
}
}
if (get(v, "forwarding_filters", x)) {
for (auto&& ff : x.as_array()) {
sora::SoraSignalingConfig::ForwardingFilter forwarding_filter;
boost::json::value y;
if (get(ff, "name", y)) {
forwarding_filter.name.emplace(y.as_string());
}
if (get(ff, "priority", y)) {
forwarding_filter.priority.emplace(y.to_number<int>());
}
if (get(ff, "action", y)) {
forwarding_filter.action.emplace(y.as_string());
}
for (auto&& rs : ff.as_object().at("rules").as_array()) {
std::vector<sora::SoraSignalingConfig::ForwardingFilter::Rule> rules;
for (auto&& r : rs.as_array()) {
sora::SoraSignalingConfig::ForwardingFilter::Rule rule;
rule.field = r.as_object().at("field").as_string();
rule.op = r.as_object().at("operator").as_string();
for (auto&& v : r.as_object().at("values").as_array()) {
rule.values.push_back(v.as_string().c_str());
}
rules.push_back(rule);
}
forwarding_filter.rules.push_back(rules);
}
if (get(ff, "version", y)) {
forwarding_filter.version.emplace(y.as_string());
}
if (get(ff, "metadata", y)) {
forwarding_filter.metadata = y;
}
config.forwarding_filters.push_back(forwarding_filter);
}
}
if (get(v, "log_level", x)) {
rtc::LogMessage::LogToDebug((rtc::LoggingSeverity)x.to_number<int>());
}
Expand Down
1 change: 1 addition & 0 deletions test/hello.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct HelloSoraConfig {
std::optional<bool> ignore_disconnect_websocket;
std::string client_id;
std::vector<sora::SoraSignalingConfig::DataChannel> data_channels;
std::vector<sora::SoraSignalingConfig::ForwardingFilter> forwarding_filters;
};

class HelloSora : public std::enable_shared_from_this<HelloSora>,
Expand Down

0 comments on commit 34a19c9

Please sign in to comment.