Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

マルチ転送フィルターを設定可能にする #62

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from

Conversation

torikizi
Copy link
Contributor

@torikizi torikizi commented Dec 19, 2024

  • ForwardingFilter に name と priority を追加
  • forwardingfilters を設定できるよう追加

This pull request introduces new functionality for configuring forwarding filters, including adding names and priorities, and deprecates the old forwarding filter method. Additionally, it updates the SoraSample.cs file to reflect these changes.

New Features:

Code Updates:

  • Introduced a new ForwardingFilter class with attributes and a ConvertForwardingFilter method to handle the conversion of these filters. (SoraUnitySdkSamples/Assets/SoraSample.cs, SoraUnitySdkSamples/Assets/SoraSample.csR126-R194)
  • Deprecated the old forwarding filter configuration in favor of the new multiple forwarding filters configuration. (SoraUnitySdkSamples/Assets/SoraSample.cs, [1] [2]
  • Removed the old ForwardingFilterMetadata class and its usage from the OnClickStart method. (SoraUnitySdkSamples/Assets/SoraSample.cs, [1] [2]

@torikizi torikizi changed the title [WIP] マルチ転送フィルターを設定可能にする マルチ転送フィルターを設定可能にする Dec 19, 2024
public RuleList[] forwardingFilter;
public bool enableForwardingFilterVersion = false;
public string forwardingFilterVersion = "";
public bool enableForwardingFilterMetadata = false;
public string forwardingFilterMetadataMessage = "";


Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

マルチ転送フィルター用に新しく項目を追加しました


if (!string.IsNullOrEmpty(filter.action))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

通常の転送フィルターでは enable を使って未設定にし、sora へ送信しないようにしていたが、マルチ転送フィルターは転送フィルターの項目が階層で一つおりたので設定しようとしない限りは送らない想定

@torikizi torikizi requested review from miosakuma and melpon December 19, 2024 07:58
public bool enableForwardingFilterName = false;
public string forwardingFilterName;
public bool enableForwardingFilterPriority = false;
public int forwardingFilterPriority;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全体的に ForwardingFilters の設定と共通化して下さい

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ForwardingFilter の設定と共通化しました。8521ea0

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このあたりの設定も共通のクラスにできるはずです

}

newFilter.Version = filter.version;
if (!string.IsNullOrEmpty(filter.metadata))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json への変換は他の項目は別の場所で行なっていますが、複数の転送フィルターを設定することを考えてこちらで実行するようにしました

public bool enableForwardingFilterName = false;
public string forwardingFilterName;
public bool enableForwardingFilterPriority = false;
public int forwardingFilterPriority;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このあたりの設定も共通のクラスにできるはずです

public RuleList[] forwardingFilter;
public bool enableForwardingFilterVersion = false;
public string forwardingFilterVersion = "";
public bool enableForwardingFilterMetadata = false;
public string forwardingFilterMetadataMessage = "";

[System.Serializable]
public class ForwardingFiltersItem
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule クラスの命名ルールからすると単に ForwardingFilter で良さそう


foreach (var filter in forwardingFilters)
{
var newFilter = new Sora.ForwardingFilter();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

共通のクラスにすればこのあたりの処理は forwardingFilter に対する処理と共通化できるはず

newFilter.Version = filter.version;
if (!string.IsNullOrEmpty(filter.metadata))
{
var ffm = new ForwardingFilterMetadata()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この ForwardingFilterMetadata がなんのために存在してるクラスなのか分からないので削除して良さそう

newFilter.Priority.HasValue ||
newFilter.Rules.Count > 0 ||
newFilter.Version != null ||
newFilter.Metadata != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

仕様上、Action や Name、Priority に値が設定されてない場合でも ForwardingFilters は使えるはずなので、この分岐はダメそう

{
newFilter.Name = filter.name;
}
if (filter.priority >= 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unity に設定される int のデフォルト値が 0 で、priority に渡す値として 0 が有効な値である以上、ここで priority >= 0 のチェックする意味は無いです


if (filter.rules != null)
{
foreach (var ruleSet in filter.rules)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filter.rules は RuleList 型であって ruleSet という名前は紛らわしいので別の名前にした方が良さそう

{
foreach (var ruleSet in filter.rules)
{
if (ruleSet.data != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

インデントが深くなるのでガード条件にした方が良さそう

if (ruleSet.data == null)
{
    continue;
}
...

ruleList.Add(newRule);
}
}
if (ruleList.Count > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

空で送るテストすることを考えると、この条件は無くても良いです

{
if (!string.IsNullOrEmpty(rule.field) &&
!string.IsNullOrEmpty(rule.op) &&
rule.values != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ユーザーがインスペクタで要素数を指定して作っている以上、ここは空文字列が来ても設定して Sora に送るほうが素直で良いので、ここら辺の条件はいらないです

@torikizi
Copy link
Contributor Author

共通のヘルパー関数を作ってスリムに作り直しました

public static class ForwardingFilterHelper
{
[Serializable]
private class ForwardingFilterMetadata
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

そもそもこれって ForwardingFilter に渡すメタデータ用のクラスなので、string metadata の代わりに ForwardingFilterMetadata metadata にした方が良いです。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        private class ForwardingFilterMetadata
        {
            public ForwardingFilterMetadata metadata;
        }

というようにした方が良いというご指摘だと理解したのですが、ここは JSON 用のプロパティのため、string にしておかないとうまくいかないようです

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

いや、ForwardingFilter クラスに定義してある string metadata を、string じゃなく ForwardingFilterMetadata にした方が良いよねって話です

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

失礼しました。勘違いしておりました。
以下のように修正します。

public ForwardingFilterMetadata metadata = new ForwardingFilterMetadata();

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

インスペクタで設定してもらう値だから初期値はいらないはず

if (settings.enableVersion) filter.Version = settings.version;
if (settings.enableMetadata)
{
filter.Metadata = ForwardingFilterMetadataHelper.ConvertMetadataToJson(settings.metadata);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここでしか ConvertMetadataToJson 関数を使ってないので、この関数に処理を分ける必要は無いです

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (forwardingFilter.enableMetadata) の中にまとめます

}
public static Sora.ForwardingFilter CreateFilter(ForwardingFilterSettings settings)
{
if (settings == null) return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create 関数で入力が null は前提条件として破綻してると思うので、この関数を呼び出す側がチェックした方が良いです。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forwardingfilter と forwardingfilters に enable フラグを追加してチェックするように修正します。

if (settings == null) return null;

var filter = new Sora.ForwardingFilter();
ConfigureFilter(filter, settings);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ1箇所でしか使ってないので関数にしなくても良さそう。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConfigureFilter を削除して ConvertForwardingFilter にまとめます。

return JsonUtility.ToJson(ffMetadata);
}
}
public static Sora.ForwardingFilter CreateFilter(ForwardingFilter settings)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create より Convert の方が機能として近そうなのと、この機能は Forwarding Filter なので略して Filter と書いてはダメです。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

結果的に ForwardingFilterHelper はこの関数1個しか使わないので、ForwardingFilterHelper というクラスにまとめなくても、単に SoraSample に static 関数1個生やすだけでいいと思います。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘のとおりです。ForwardingFilterHelper にまとめるのをやめます。

@@ -777,30 +838,23 @@ public void OnClickStart()
}
fixedDataChannelLabels = config.DataChannels.Select(x => x.Label).ToArray();
}
if (forwardingFilter.Length != 0)
if (forwardingFilter != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

インスペクタで設定している以上、通常 forwardingFilter は null にはならないので、bool enableForwardingFilter を用意するか、以前と同じ条件にするなら forwardingFilter.rules.Length != 0 にする必要があります。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enableForwardingFilter を用意します。

foreach (var rs in forwardingFilter)
config.ForwardingFilter = ForwardingFilterHelper.CreateFilter(forwardingFilter);
}
if (forwardingFilters != null && forwardingFilters.Length > 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

インスペクタで設定している以上、通常 forwardingFilters は null にはならないはずです。
あと、サンプルの仕様として長さ0の ForwardingFilters を作ることを許容するかどうか次第ですけど、こちらも bool enableForwardingFilters フラグを用意するかどうか考える必要がありそう。

Copy link
Contributor Author

@torikizi torikizi Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

何も条件がないと forwardingfilters の項目を設定してしまうのでフラグを用意します。


if (settings.rules != null)
{
foreach (var ruleSet in settings.rules)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruleSet の Set は集合だと勘違いしやすいので、別の名前を付けたほうが良いです

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruleListData にします

{
foreach (var ruleSet in settings.rules)
{
if (ruleSet?.data == null) continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruleSetruleSet.data が null になることってあります?インスペクタで設定している以上無さそうな気がしてます。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null になることはない想定です。こちらも修正します

{
public string metadata;
}
private static void ConfigureFilter(Sora.ForwardingFilter filter, ForwardingFilter settings)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settings という名前が現状と合ってなさそう

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forwardingFilter に修正します

CHANGES.md Outdated
- マルチ転送フィルターを設定できるように項目を追加
- @torikizi
- [ADD] forwardingfilter に name と priority を追加
- 既存の forwardingfilter に name と priority を追加
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここ [ADD] のところと同じ内容だから削って良さそう

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かに同じことが書いてあるだけでした。消します。

if (forwardingFilter.enableName) filter.Name = forwardingFilter.name;
if (forwardingFilter.enablePriority) filter.Priority = forwardingFilter.priority;

if (forwardingFilter.rules != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

インスペクタで設定される値だから forwardingFilter.rules が null になることは無いはず

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘のとおりです。こちらもチェックを外します。

{
public string metadata;
}
public static Sora.ForwardingFilter ConvertForwardingFilter(ForwardingFilter forwardingFilter)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sora-unity-sdk でやったのと同じように ConvertTo の方が分かりやすいかも。あと SoraSample の ForwardingFilter と Sora.ForwardingFilter が同じ名前なので、違いを出すために ConvertToSoraForwardingFilter とかにすると良さそう。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConvertToSoraForwardingFilter にします。

public string forwardingFilterVersion = "";
public bool enableForwardingFilterMetadata = false;
public string forwardingFilterMetadataMessage = "";
[System.Obsolete("forwardingFilter は非推奨です。代わりに forwardingFilters を使用してください。")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これはもう1行下で設定するのが正しそう?もしかしたら両方の変数に必要かも

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

対象としては両方あった方が良さそうですね。両方設定します。
Image from Gyazo

var ccrs = new List<Sora.ForwardingFilter.Rule>();
foreach (var r in rs.data)
var newFilter = ConvertForwardingFilter(filter);
if (newFilter != null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここが null になることは無いはず

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘のとおりです。チェックを外します。

ruleList.Add(newRule);
}

if (ruleList.Any())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruleList が空の時にも filter.Rules に空の値を設定するのが正しいので、この条件は要らないです。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

条件を削除します。


if (forwardingFilter.enableVersion) filter.Version = forwardingFilter.version;
if (forwardingFilter.enableMetadata)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToJson 1個で済むようになったので、他の if 文と同じ書き方にしておいて下さい

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ご指摘のとおりです。他とあわせて一行になるようにします。

public string name;
public bool enablePriority = false;
public int priority;
public RuleList[] rules;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuleList の配列だから ruleLists の方が名前的に良さそう。rules だと Rule の配列だと思ってしまいそうなので。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruleLists に名前を変えます。

Copy link
Contributor

@melpon melpon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よさそう

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants