-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: develop
Are you sure you want to change the base?
Conversation
public RuleList[] forwardingFilter; | ||
public bool enableForwardingFilterVersion = false; | ||
public string forwardingFilterVersion = ""; | ||
public bool enableForwardingFilterMetadata = false; | ||
public string forwardingFilterMetadataMessage = ""; | ||
|
||
|
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
通常の転送フィルターでは enable を使って未設定にし、sora へ送信しないようにしていたが、マルチ転送フィルターは転送フィルターの項目が階層で一つおりたので設定しようとしない限りは送らない想定
public bool enableForwardingFilterName = false; | ||
public string forwardingFilterName; | ||
public bool enableForwardingFilterPriority = false; | ||
public int forwardingFilterPriority; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
全体的に ForwardingFilters の設定と共通化して下さい
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ForwardingFilter の設定と共通化しました。8521ea0
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ユーザーがインスペクタで要素数を指定して作っている以上、ここは空文字列が来ても設定して Sora に送るほうが素直で良いので、ここら辺の条件はいらないです
共通のヘルパー関数を作ってスリムに作り直しました |
public static class ForwardingFilterHelper | ||
{ | ||
[Serializable] | ||
private class ForwardingFilterMetadata |
There was a problem hiding this comment.
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 にした方が良いです。
There was a problem hiding this comment.
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 にしておかないとうまくいかないようです
There was a problem hiding this comment.
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 にした方が良いよねって話です
There was a problem hiding this comment.
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();
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここでしか ConvertMetadataToJson 関数を使ってないので、この関数に処理を分ける必要は無いです
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create 関数で入力が null は前提条件として破綻してると思うので、この関数を呼び出す側がチェックした方が良いです。
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これ1箇所でしか使ってないので関数にしなくても良さそう。
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 と書いてはダメです。
There was a problem hiding this comment.
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個生やすだけでいいと思います。
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 にする必要があります。
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 フラグを用意するかどうか考える必要がありそう。
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ruleSet の Set は集合だと勘違いしやすいので、別の名前を付けたほうが良いです
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ruleSet
や ruleSet.data
が null になることってあります?インスペクタで設定している以上無さそうな気がしてます。
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
settings という名前が現状と合ってなさそう
There was a problem hiding this comment.
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 を追加 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここ [ADD] のところと同じ内容だから削って良さそう
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
インスペクタで設定される値だから forwardingFilter.rules が null になることは無いはず
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 とかにすると良さそう。
There was a problem hiding this comment.
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 を使用してください。")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これはもう1行下で設定するのが正しそう?もしかしたら両方の変数に必要かも
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var ccrs = new List<Sora.ForwardingFilter.Rule>(); | ||
foreach (var r in rs.data) | ||
var newFilter = ConvertForwardingFilter(filter); | ||
if (newFilter != null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここが null になることは無いはず
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ruleList が空の時にも filter.Rules に空の値を設定するのが正しいので、この条件は要らないです。
There was a problem hiding this comment.
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) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToJson 1個で済むようになったので、他の if 文と同じ書き方にしておいて下さい
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RuleList の配列だから ruleLists の方が名前的に良さそう。rules だと Rule の配列だと思ってしまいそうなので。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ruleLists に名前を変えます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
よさそう
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:
name
andpriority
. (CHANGES.md
, SoraUnitySdkSamples/Assets/SoraSample.csR126-R194)Code Updates:
ForwardingFilter
class with attributes and aConvertForwardingFilter
method to handle the conversion of these filters. (SoraUnitySdkSamples/Assets/SoraSample.cs
, SoraUnitySdkSamples/Assets/SoraSample.csR126-R194)SoraUnitySdkSamples/Assets/SoraSample.cs
, [1] [2]ForwardingFilterMetadata
class and its usage from theOnClickStart
method. (SoraUnitySdkSamples/Assets/SoraSample.cs
, [1] [2]