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

data_channels 項目に header 項目を追加 #104

Merged
merged 13 commits into from
Jan 6, 2025

Conversation

torikizi
Copy link
Contributor

@torikizi torikizi commented Oct 29, 2024

data_channels 項目に header 項目を追加しました。
dc.header は string から json にパースして設定しています。


This pull request introduces a new Header property to the DataChannel class and updates related files to support this addition. The most important changes include updates to the Sora.Config, DataChannel class, and associated methods in both C# and C++ code, as well as the protocol buffer definition.

Enhancements to DataChannel:

  • Sora/Sora.cs: Added Header property to the DataChannel class.
  • Sora/Sora.cs: Updated Connect method to set the Header property if it is not null.

Protocol buffer updates:

C++ code updates:

  • src/sora.cpp: Updated DoConnect method to parse and set the Header property from JSON.

Documentation updates:

  • CHANGES.md: Documented the addition of the Header property to DataChannels.

@torikizi torikizi requested review from melpon and miosakuma October 29, 2024 01:46
Copy link
Contributor

@miosakuma miosakuma left a comment

Choose a reason for hiding this comment

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

対応ありがとうございます。

@@ -419,6 +419,13 @@ void Sora::DoConnect(const sora_conf::internal::ConnectConfig& cc,
if (dc.has_compress()) {
d.compress = dc.compress;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

他は項目を追加に関しての設定なので、一番確認していただきたいのはこの下の追加部分になります。

src/sora.cpp Outdated
@@ -419,6 +419,13 @@ void Sora::DoConnect(const sora_conf::internal::ConnectConfig& cc,
if (dc.has_compress()) {
d.compress = dc.compress;
}
if (dc.has_header()) {
boost::json::value parsed_value = boost::json::parse(dc.header);
if (parsed_value.is_array()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

配列しか許可しないなら、最初から header を配列として定義して下さい。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

配列として定義し直しました。

Sora/Sora.cs Outdated
@@ -62,6 +62,7 @@ public class DataChannel
public int? MaxRetransmits;
public string? Protocol;
public bool? Compress;
public string? Header;
Copy link
Contributor

Choose a reason for hiding this comment

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

こっちも配列になってないですね

Sora/Sora.cs Outdated
@@ -453,6 +454,10 @@ public void Connect(Config config)
{
c.SetCompress(m.Compress.Value);
}
if (m.Header != null)
{
c.SetHeader(m.Header);
Copy link
Contributor

Choose a reason for hiding this comment

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

これコンパイル通ります…?

src/sora.cpp Outdated
if (dc.has_header()) {
const auto& header_content = dc.header.content;
d.header->insert(d.header->end(), header_content.begin(),
header_content.end());
Copy link
Contributor

Choose a reason for hiding this comment

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

proto の各要素の型は JSON 文字列にシリアライズされた string 型で、SoraSignalingConfig::DataChannel::header の各要素の型は boost::json::value なんだから、絶対に JSON 文字列をデシリアライズする処理が必要なはずです。

Sora/Sora.cs Outdated
public class Header
{
public List<string> content { get; set; } = 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.

C# は proto と違って string 配列が nullable なので、Header クラスを作る必要は無いです。DataChannel クラスで直接 List<string>? Header すれば良いです。
proto 側で Header クラスを作ってるのは nullable な string 配列(optional repeated string header)が定義できないからです。

@@ -2,6 +2,10 @@ syntax = "proto3";

package sora_conf.internal;

message Header {
repeated string content = 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

DataChannel の下に作らないなら Header という名前は汎用的すぎるので DataChannelHeader にした方が良いです

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 の Rules と同じように DataChannel の下に作るよう修正します。

src/sora.cpp Outdated
const auto& header_content = dc.header.content;
d.header->reserve(header_content.size());
for (const auto& json_str : header_content) {
auto parsed = boost::json::parse(json_str);
Copy link
Contributor

Choose a reason for hiding this comment

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

これだとパースエラー時に例外投げちゃうので、他の parse と合わせて error_code を渡すようにして下さい。

src/sora.cpp Outdated
@@ -419,6 +419,19 @@ void Sora::DoConnect(const sora_conf::internal::ConnectConfig& cc,
if (dc.has_compress()) {
d.compress = dc.compress;
}
if (dc.has_header()) {
d.header = std::vector<boost::json::value>();
d.header->reserve(dc.header.content.size());
Copy link
Contributor

Choose a reason for hiding this comment

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

reserve するような最適化はいらないので削除して下さい

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ご指摘のとおり削除します。

src/sora.cpp Outdated
boost::system::error_code ec;
auto parsed = boost::json::parse(json_str, ec);
if (ec) {
RTC_LOG(LS_WARNING) << "Invalid JSON in header: " << json_str;
Copy link
Contributor

Choose a reason for hiding this comment

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

他のやつと書き方のフォーマットが違いますね。

Suggested change
RTC_LOG(LS_WARNING) << "Invalid JSON in header: " << json_str;
RTC_LOG(LS_WARNING) << "Invalid JSON: header=" << json_str;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

失礼しました。メッセージを修正します。

Sora/Sora.cs Outdated
Comment on lines 459 to 460
var header = new SoraConf.Internal.DataChannel.Header();
header.content.AddRange(m.Header);
Copy link
Contributor

Choose a reason for hiding this comment

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

初期化と同時に代入の方がいい感じになりそう。

Suggested change
var header = new SoraConf.Internal.DataChannel.Header();
header.content.AddRange(m.Header);
var header = new SoraConf.Internal.DataChannel.Header() {
content = m.Header,
};

Copy link
Contributor Author

@torikizi torikizi Dec 30, 2024

Choose a reason for hiding this comment

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

初期化と同時に代入するように修正します。
c9087e4 で対応しました。

Sora/Sora.cs Outdated
@@ -454,6 +454,10 @@ public void Connect(Config config)
{
c.SetCompress(m.Compress.Value);
}
if (m.Header != null)
{
c.SetHeader(new SoraConf.Internal.DataChannel.Header { content = new List<string>(m.Header) });
Copy link
Contributor

Choose a reason for hiding this comment

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

これ content = m.Header とは書けないですか?

Copy link
Contributor Author

@torikizi torikizi Dec 30, 2024

Choose a reason for hiding this comment

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

ここでまた List 作らなくても良いですね。修正します。

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.

良さそう

@torikizi
Copy link
Contributor Author

torikizi commented Jan 6, 2025

レビューありがとうございました。こちらマージします。

@torikizi torikizi merged commit 1778cbe into develop Jan 6, 2025
7 checks passed
@torikizi torikizi deleted the feature/add-datachannels-header branch January 6, 2025 01:58
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.

3 participants