From 7843559f2568a499ab63ebb8c7abcba4ba53d13a Mon Sep 17 00:00:00 2001 From: voluntas Date: Mon, 28 Oct 2024 23:29:12 +0900 Subject: [PATCH] =?UTF-8?q?forwarding=5Ffilters=20=E3=81=AB=E5=AF=BE?= =?UTF-8?q?=E5=BF=9C=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit forwarding_filter を使わないでコピペして書いた。 --- src/sora.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++ src/sora.h | 4 +++ src/sora_sdk_ext.cpp | 4 ++- 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/sora.cpp b/src/sora.cpp index 5854648..c708d83 100644 --- a/src/sora.cpp +++ b/src/sora.cpp @@ -43,6 +43,7 @@ std::shared_ptr Sora::CreateConnection( std::optional spotlight_focus_rid, std::optional spotlight_unfocus_rid, const nb::handle& forwarding_filter, + const nb::handle& forwarding_filters, const nb::handle& data_channels, std::optional data_channel_signaling, std::optional ignore_disconnect_websocket, @@ -131,6 +132,7 @@ std::shared_ptr 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); @@ -263,6 +265,59 @@ boost::json::value Sora::ConvertJsonValue(nb::handle value, throw nb::type_error(error_message); } +std::optional> +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 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 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(object["priority"]); + } + } catch (std::exception&) { + throw nb::type_error("Invalid forwarding_filter"); + } + forwarding_filters.push_back(filter); + } + + return forwarding_filters; +} + + std::optional Sora::ConvertForwardingFilter(const nb::handle value) { auto forwarding_filter_value = @@ -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(object["priority"]); + } } catch (std::exception&) { throw nb::type_error("Invalid forwarding_filter"); } diff --git a/src/sora.h b/src/sora.h index 6c48057..3ec8bcb 100644 --- a/src/sora.h +++ b/src/sora.h @@ -118,6 +118,7 @@ class Sora : public DisposePublisher { std::optional spotlight_focus_rid, std::optional spotlight_unfocus_rid, const nb::handle& forwarding_filter, + const nb::handle& forwarding_filters, const nb::handle& data_channels, std::optional data_channel_signaling, std::optional ignore_disconnect_websocket, @@ -175,6 +176,9 @@ class Sora : public DisposePublisher { const nb::handle value); std::vector ConvertSignalingUrls(const nb::handle value); + std::optional> + ConvertForwardingFilters(const nb::handle value); + std::optional ConvertForwardingFilter(const nb::handle value); diff --git a/src/sora_sdk_ext.cpp b/src/sora_sdk_ext.cpp index df2c00b..572abd8 100644 --- a/src/sora_sdk_ext.cpp +++ b/src/sora_sdk_ext.cpp @@ -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(), @@ -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, "