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

Merged
merged 18 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

## develop

- [ADD] forwardingfilters を設定可能にする
- マルチ転送フィルターを設定できるように項目を追加
- @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.

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

- @torikizi

## sora-unity-sdk-2024.4.0

- [UPDATE] Sora Unity SDK 2024.4.0 にあげる
Expand Down
116 changes: 115 additions & 1 deletion SoraUnitySdkSamples/Assets/SoraSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,51 @@ public class RuleList
[Header("ForwardingFilter の設定")]
public bool enableForwardingFilterAction = false;
public string forwardingFilterAction;
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.

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

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.

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

[System.Serializable]
public class ForwardingFiltersRule
{
public string field;
public string op;
public string[] values;
}
[System.Serializable]
public class ForwardingFiltersRuleList
{
public ForwardingFiltersRule[] data;
}

[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 で良さそう

{
public string action;
public string name;
public int priority;
public ForwardingFiltersRuleList[] rules;
public string version;
public string metadata;
}

[System.Serializable]
public class ForwardingFiltersList
{
public ForwardingFiltersItem[] filters;
}

[Header("ForwardingFilters の設定")]

public ForwardingFiltersList forwardingFilters;

[Header("DataChannel シグナリングの設定")]
public bool dataChannelSignaling = false;
public int dataChannelSignalingTimeout = 30;
Expand Down Expand Up @@ -777,10 +816,12 @@ public void OnClickStart()
}
fixedDataChannelLabels = config.DataChannels.Select(x => x.Label).ToArray();
}
if (forwardingFilter.Length != 0)
if (forwardingFilter != null && forwardingFilter.Length != 0)
{
config.ForwardingFilter = new Sora.ForwardingFilter();
if (enableForwardingFilterAction) config.ForwardingFilter.Action = forwardingFilterAction;
if (enableForwardingFilterName) config.ForwardingFilter.Name = forwardingFilterName;
if (enableForwardingFilterPriority) config.ForwardingFilter.Priority = forwardingFilterPriority;
foreach (var rs in forwardingFilter)
{
var ccrs = new List<Sora.ForwardingFilter.Rule>();
Expand All @@ -789,6 +830,7 @@ public void OnClickStart()
var ccr = new Sora.ForwardingFilter.Rule();
ccr.Field = r.field;
ccr.Operator = r.op;
ccr.Values = new List<string>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Sora.ForwardingFilter.Rule の初期化時に自動で作ってるのでこれは不要です

foreach (var v in r.values)
{
ccr.Values.Add(v);
Expand All @@ -800,7 +842,79 @@ public void OnClickStart()
if (enableForwardingFilterVersion) config.ForwardingFilter.Version = forwardingFilterVersion;
if (enableForwardingFilterMetadata) config.ForwardingFilter.Metadata = forwardingFilterMetadataJson;
}
if (forwardingFilters != null &&
forwardingFilters.filters != null &&
forwardingFilters.filters.Length > 0)
{
config.ForwardingFilters = new List<Sora.ForwardingFilter>();

foreach (var filter in forwardingFilters.filters)
{
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 に対する処理と共通化できるはず


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 へ送信しないようにしていたが、マルチ転送フィルターは転送フィルターの項目が階層で一つおりたので設定しようとしない限りは送らない想定

{
newFilter.Action = filter.action;
}
if (!string.IsNullOrEmpty(filter.name))
{
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 のチェックする意味は無いです

{
newFilter.Priority = filter.priority;
}

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 という名前は紛らわしいので別の名前にした方が良さそう

{
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;
}
...

{
var ruleList = new List<Sora.ForwardingFilter.Rule>();
foreach (var rule in ruleSet.data)
{
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 に送るほうが素直で良いので、ここら辺の条件はいらないです

{
var newRule = new Sora.ForwardingFilter.Rule
{
Field = rule.field,
Operator = rule.op
};
newRule.Values.AddRange(rule.values);
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.

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

{
newFilter.Rules.Add(ruleList);
}
}
}
}

if (!string.IsNullOrEmpty(filter.version))
{
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 への変換は他の項目は別の場所で行なっていますが、複数の転送フィルターを設定することを考えてこちらで実行するようにしました

{
newFilter.Metadata = filter.metadata;
}

if (newFilter.Action != null ||
newFilter.Name != null ||
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 は使えるはずなので、この分岐はダメそう

{
config.ForwardingFilters.Add(newFilter);
}
}
}
sora.Connect(config);
SetState(State.Started);
Debug.LogFormat("Sora is Created: signalingUrl={0}, channelId={1}", signalingUrl, channelId);
Expand Down