Skip to content

Commit

Permalink
シンプルな構成に見直し
Browse files Browse the repository at this point in the history
  • Loading branch information
torikizi committed Dec 19, 2024
1 parent 5cf82fe commit 16a605c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 87 deletions.
87 changes: 4 additions & 83 deletions Sora/Sora.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,79 +86,9 @@ public class Rule
public string? Version;
public string? Metadata;
}
public class ForwardingFiltersRule
{
public string field = "";
public string op = "";
public string[] values = new string[0];
}

public class ForwardingFiltersRuleSet
{
public ForwardingFiltersRule[] rules = new ForwardingFiltersRule[0];
}

[Serializable]
public class ForwardingFiltersConfig
{
[Header("Filter Settings")]
public bool enableAction = false;
[Tooltip("Action to take (block/allow)")]
public string action = "";

public bool enableName = false;
[Tooltip("Filter name")]
public string name = "";

public bool enablePriority = false;
[Tooltip("Filter priority")]
public int? priority;

[Header("Rules")]
public ForwardingFiltersRuleSet[] ruleSets = new ForwardingFiltersRuleSet[0];

public bool enableVersion = false;
[Tooltip("Filter version")]
public string version = "";

public bool enableMetadata = false;
[Tooltip("Filter metadata")]
public string metadata = "";
}
public class ForwardingFilters
{
// 内部のfiltersリスト
public List<ForwardingFilter> filters { get; set; }

// 読み取り専用のFiltersプロパティ
public IReadOnlyList<ForwardingFilter> Filters => filters;

public ForwardingFilters()
{
filters = new List<ForwardingFilter>();
}

public void Add(ForwardingFilter filter)
{
if (filters == null)
{
filters = new List<ForwardingFilter>();
}
filters.Add(filter);
}

// ForwardingFiltersインスタンスを追加するメソッド
public void Add(ForwardingFilters otherFilters)
{
if (otherFilters?.filters != null)
{
if (filters == null)
{
filters = new List<ForwardingFilter>();
}
filters.AddRange(otherFilters.filters);
}
}
public List<ForwardingFilter> Filters = new List<ForwardingFilter>();
}
/// <summary>
/// カメラの設定
Expand Down Expand Up @@ -576,12 +506,10 @@ public void Connect(Config config)
}
if (config.ForwardingFilters != null && config.ForwardingFilters.Filters.Count > 0)
{
var forwardingFilters = new SoraConf.Internal.ForwardingFilters();

var ffs = new SoraConf.Internal.ForwardingFilters();
foreach (var filter in config.ForwardingFilters.Filters)
{
var ff = new SoraConf.Internal.ForwardingFilter();

if (filter.Action != null)
{
ff.SetAction(filter.Action);
Expand All @@ -594,11 +522,9 @@ public void Connect(Config config)
{
ff.SetPriority(filter.Priority.Value);
}

foreach (var rs in filter.Rules)
{
var ccrs = new SoraConf.Internal.ForwardingFilter.Rules();

foreach (var r in rs)
{
var ccr = new SoraConf.Internal.ForwardingFilter.Rule();
Expand All @@ -612,7 +538,6 @@ public void Connect(Config config)
}
ff.rules.Add(ccrs);
}

if (filter.Version != null)
{
ff.SetVersion(filter.Version);
Expand All @@ -621,13 +546,9 @@ public void Connect(Config config)
{
ff.SetMetadata(filter.Metadata);
}

// ForwardingFilters に追加
forwardingFilters.Add(ff);
ffs.filters.Add(ff);
}

// forwarding_filters に設定
cc.forwarding_filters = forwardingFilters;
cc.SetForwardingFilters(ffs);
}
if (config.UseHardwareEncoder.HasValue)
{
Expand Down
6 changes: 2 additions & 4 deletions src/sora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,7 @@ void Sora::DoConnect(const sora_conf::internal::ConnectConfig& cc,
}
if (cc.has_forwarding_filters()) {
std::vector<sora::SoraSignalingConfig::ForwardingFilter> filters;
const auto& ff = cc.forwarding_filters;
// filters プロパティから直接フィルターを取得するように修正
for (const auto& filter : ff.filters) {
for (const auto& filter : cc.forwarding_filters.filters) {
sora::SoraSignalingConfig::ForwardingFilter ff;
if (filter.has_action()) {
ff.action = filter.action;
Expand Down Expand Up @@ -516,7 +514,7 @@ void Sora::DoConnect(const sora_conf::internal::ConnectConfig& cc,
boost::system::error_code ec;
auto ffmd = boost::json::parse(filter.metadata, ec);
if (ec) {
RTC_LOG(LS_WARNING) << "Invalid JSON: forwarding_filters metadata="
RTC_LOG(LS_WARNING) << "Invalid JSON: forwarding_filter metadata="
<< filter.metadata;
} else {
ff.metadata = ffmd;
Expand Down

0 comments on commit 16a605c

Please sign in to comment.