Skip to content

Commit

Permalink
forwarding_filters に対応する
Browse files Browse the repository at this point in the history
forwarding_filter を使わないでコピペして書いた。
  • Loading branch information
voluntas committed Oct 28, 2024
1 parent fec7e9a commit 7843559
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
61 changes: 61 additions & 0 deletions src/sora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ std::shared_ptr<SoraConnection> Sora::CreateConnection(
std::optional<std::string> spotlight_focus_rid,
std::optional<std::string> spotlight_unfocus_rid,
const nb::handle& forwarding_filter,
const nb::handle& forwarding_filters,
const nb::handle& data_channels,
std::optional<bool> data_channel_signaling,
std::optional<bool> ignore_disconnect_websocket,
Expand Down Expand Up @@ -131,6 +132,7 @@ std::shared_ptr<SoraConnection> Sora::CreateConnection(
config.spotlight_unfocus_rid = *spotlight_unfocus_rid;
}
config.forwarding_filter = ConvertForwardingFilter(forwarding_filter);
config.forwarding_filters = ConvertForwardingFilters(forwarding_filters);
config.data_channels = ConvertDataChannels(data_channels);
if (data_channel_signaling) {
config.data_channel_signaling.emplace(*data_channel_signaling);
Expand Down Expand Up @@ -263,6 +265,59 @@ boost::json::value Sora::ConvertJsonValue(nb::handle value,
throw nb::type_error(error_message);
}

std::optional<std::vector<sora::SoraSignalingConfig::ForwardingFilter>>
Sora::ConvertForwardingFilters(const nb::handle value) {
auto forwarding_filters_value =
ConvertJsonValue(value, "Invalid JSON value in forwarding_filters");
if (forwarding_filters_value.is_null()) {
return std::nullopt;
}

std::vector<sora::SoraSignalingConfig::ForwardingFilter> forwarding_filters;

for (auto forwarding_filter_value : forwarding_filters_value.as_array()) {
sora::SoraSignalingConfig::ForwardingFilter filter;
try {
auto object = forwarding_filter_value.as_object();
if (!object["action"].is_null()) {
filter.action = std::string(object["action"].as_string());
}
for (auto or_rule : object["rules"].as_array()) {
std::vector<sora::SoraSignalingConfig::ForwardingFilter::Rule> rules;
for (auto and_rule_value : or_rule.as_array()) {
auto and_rule = and_rule_value.as_object();
sora::SoraSignalingConfig::ForwardingFilter::Rule rule;
rule.field = and_rule["field"].as_string();
rule.op = and_rule["operator"].as_string();
for (auto value : and_rule["values"].as_array()) {
rule.values.push_back(value.as_string().c_str());
}
rules.push_back(rule);
}
filter.rules.push_back(rules);
}
if (!object["version"].is_null()) {
filter.version = std::string(object["version"].as_string());
}
if (!object["metadata"].is_null()) {
filter.metadata = object["metadata"];
}
if (!object["name"].is_null()) {
filter.name = std::string(object["name"].as_string());
}
if (!object["priority"].is_null()) {
filter.priority = boost::json::value_to<int>(object["priority"]);
}
} catch (std::exception&) {
throw nb::type_error("Invalid forwarding_filter");
}
forwarding_filters.push_back(filter);
}

return forwarding_filters;
}


std::optional<sora::SoraSignalingConfig::ForwardingFilter>
Sora::ConvertForwardingFilter(const nb::handle value) {
auto forwarding_filter_value =
Expand Down Expand Up @@ -298,6 +353,12 @@ Sora::ConvertForwardingFilter(const nb::handle value) {
if (!object["metadata"].is_null()) {
filter.metadata = object["metadata"];
}
if (!object["name"].is_null()) {
filter.name = std::string(object["name"].as_string());
}
if (!object["priority"].is_null()) {
filter.priority = boost::json::value_to<int>(object["priority"]);
}
} catch (std::exception&) {
throw nb::type_error("Invalid forwarding_filter");
}
Expand Down
4 changes: 4 additions & 0 deletions src/sora.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class Sora : public DisposePublisher {
std::optional<std::string> spotlight_focus_rid,
std::optional<std::string> spotlight_unfocus_rid,
const nb::handle& forwarding_filter,
const nb::handle& forwarding_filters,
const nb::handle& data_channels,
std::optional<bool> data_channel_signaling,
std::optional<bool> ignore_disconnect_websocket,
Expand Down Expand Up @@ -175,6 +176,9 @@ class Sora : public DisposePublisher {
const nb::handle value);
std::vector<std::string> ConvertSignalingUrls(const nb::handle value);

std::optional<std::vector<sora::SoraSignalingConfig::ForwardingFilter>>
ConvertForwardingFilters(const nb::handle value);

std::optional<sora::SoraSignalingConfig::ForwardingFilter>
ConvertForwardingFilter(const nb::handle value);

Expand Down
4 changes: 3 additions & 1 deletion src/sora_sdk_ext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,8 @@ NB_MODULE(sora_sdk_ext, m) {
"spotlight"_a = nb::none(), "spotlight_number"_a = nb::none(),
"simulcast_rid"_a = nb::none(), "spotlight_focus_rid"_a = nb::none(),
"spotlight_unfocus_rid"_a = nb::none(),
"forwarding_filter"_a = nb::none(), "data_channels"_a = nb::none(),
"forwarding_filter"_a = nb::none(), "forwarding_filters"_a = nb::none(),
"data_channels"_a = nb::none(),
"data_channel_signaling"_a = nb::none(),
"ignore_disconnect_websocket"_a = nb::none(),
"data_channel_signaling_timeout"_a = nb::none(),
Expand Down Expand Up @@ -544,6 +545,7 @@ NB_MODULE(sora_sdk_ext, m) {
"spotlight_focus_rid: Optional[str] = None, "
"spotlight_unfocus_rid: Optional[str] = None, "
"forwarding_filter: Optional[dict] = None, "
"forwarding_filters: Optional[list[dict]] = None, "
"data_channels: Optional[list[dict]] = None, "
"data_channel_signaling: Optional[bool] = None, "
"ignore_disconnect_websocket: Optional[bool] = None, "
Expand Down

0 comments on commit 7843559

Please # to comment.